Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-30 08:18:22

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