Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:24:24

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 #pragma once
0009 
0010 #include "Acts/Definitions/Algebra.hpp"
0011 #include "Acts/Utilities/BinningData.hpp"
0012 #include "Acts/Utilities/ProtoAxis.hpp"
0013 
0014 #include <span>
0015 #include <string>
0016 #include <vector>
0017 
0018 namespace Acts::ProtoAxisHelpers {
0019 
0020 /// @brief Get the number of bins from a ProtoAxis
0021 /// @param axis DirectedProtoAxis object
0022 /// @return Number of bins in the axis
0023 inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) {
0024   return axis.getAxis().getNBins();
0025 }
0026 
0027 /// @brief Get the total number of bins from multiple ProtoAxes
0028 /// @param axes Span of DirectedProtoAxis objects
0029 /// @return Total number of bins across all axes
0030 inline std::size_t totalBinsFromProtoAxes(
0031     std::span<const Acts::DirectedProtoAxis> axes) {
0032   if (axes.empty() || axes.size() > 3) {
0033     throw std::runtime_error(
0034         "Unsupported number of axes, must be 1-3, instead got " +
0035         std::to_string(axes.size()) + ")");
0036   }
0037   return axes[0].getAxis().getNBins() *
0038          (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) *
0039          (axes.size() > 2 ? axes[2].getAxis().getNBins() : 1);
0040 }
0041 
0042 /// @brief Get the number of bins from a specific ProtoAxis in a collection
0043 /// @param axes DirectedProtoAxis span
0044 /// @param ba Bin axis index
0045 /// @return Number of bins in the specified axis
0046 inline std::size_t binsFromProtoAxes(
0047     std::span<const Acts::DirectedProtoAxis> axes, std::size_t ba) {
0048   if (axes.empty() || axes.size() > 3) {
0049     throw std::runtime_error(
0050         "Unsupported number of axes, must be 1-3, instead got " +
0051         std::to_string(axes.size()) + ")");
0052   }
0053   Acts::BinningData bd(axes[ba]);
0054   return bd.bins();
0055 }
0056 
0057 /// @brief Get the bin index from a ProtoAxis using local coordinates
0058 /// @param axis DirectedProtoAxis object
0059 /// @param lp Local position vector
0060 /// @return Bin index corresponding to the local position
0061 inline std::size_t binFromProtoAxis(const Acts::DirectedProtoAxis& axis,
0062                                     const Acts::Vector2& lp) {
0063   Acts::BinningData bd(axis);
0064   return bd.searchLocal(lp);
0065 }
0066 
0067 /// @brief Get the bin index from a ProtoAxis using global coordinates
0068 /// @param axis DirectedProtoAxis object
0069 /// @param gp Global position vector
0070 /// @return Bin index corresponding to the global position
0071 inline std::size_t binFromProtoAxis(const Acts::DirectedProtoAxis& axis,
0072                                     const Acts::Vector3& gp) {
0073   Acts::BinningData bd(axis);
0074   return bd.searchGlobal(gp);
0075 }
0076 
0077 /// @brief Get the bin triple from multiple ProtoAxes using global coordinates
0078 /// @param axes Span of DirectedProtoAxis objects
0079 /// @param gp Global position vector
0080 /// @return Array of bin indices corresponding to the global position for each axis
0081 inline std::array<std::size_t, 3> binTripleFromProtoAxes(
0082     std::span<const Acts::DirectedProtoAxis> axes, const Acts::Vector3& gp) {
0083   const Acts::Vector3& bPosition = gp;
0084   std::array<std::size_t, 3> bTriple = {0, 0, 0};
0085   if (axes.empty() || axes.size() > 3) {
0086     throw std::runtime_error(
0087         "Unsupported number of axes, must be 1-3, instead got " +
0088         std::to_string(axes.size()) + ")");
0089   }
0090   if (axes.size() == 1) {
0091     Acts::BinningData bd0(axes[0]);
0092     bTriple[0] = bd0.searchGlobal(bPosition);
0093   }
0094   if (axes.size() == 2) {
0095     Acts::BinningData bd1(axes[1]);
0096     bTriple[1] = bd1.searchGlobal(bPosition);
0097   }
0098   if (axes.size() == 3) {
0099     Acts::BinningData bd2(axes[2]);
0100     bTriple[2] = bd2.searchGlobal(bPosition);
0101   }
0102   return bTriple;
0103 }
0104 
0105 /// @brief Get the maximum bin index from a specific ProtoAxis in a collection
0106 /// @param axes DirectedProtoAxis span
0107 /// @param ba Bin axis index
0108 /// @return Maximum bin index in the specified axis
0109 inline std::size_t maxBin(std::span<const Acts::DirectedProtoAxis> axes,
0110                           std::size_t ba = 0) {
0111   if (axes.empty() || axes.size() > 3) {
0112     throw std::runtime_error(
0113         "Unsupported number of axes, must be 1-3, instead got " +
0114         std::to_string(axes.size()) + ")");
0115   }
0116   std::vector<Acts::BinningData> binningDataVec;
0117   binningDataVec.reserve(axes.size());
0118   for (const auto& axis : axes) {
0119     binningDataVec.emplace_back(axis);
0120   }
0121   if (ba >= binningDataVec.size()) {
0122     return 0;
0123   }
0124   return (binningDataVec.at(ba).bins() - 1);
0125 }
0126 
0127 }  // namespace Acts::ProtoAxisHelpers