Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-02 08:53:01

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/Utilities/Concepts.hpp"
0012 #include "Acts/Utilities/Grid.hpp"
0013 #include "Acts/Utilities/detail/grid_helper.hpp"
0014 
0015 #include <variant>
0016 #include <vector>
0017 
0018 #include <boost/container/small_vector.hpp>
0019 
0020 namespace Acts {
0021 
0022 /// @tparam DIM Dimension of the Grid on which the GridBinFinder will be used
0023 ///
0024 /// The GridBinFinder is used by the ISPGroupSelector. It can be used to find
0025 /// both bins that could be bottom bins as well as bins that could be top bins,
0026 /// which are assumed to be the same bins. Does not take interaction region into
0027 /// account to limit z-bins.
0028 template <std::size_t DIM>
0029 class GridBinFinder {
0030  public:
0031   /// Number of neighbor bins in 3^DIM grid configuration
0032   static constexpr std::size_t dimCubed = detail::ipow(3, DIM);
0033 
0034   /// Type alias for variant storing different bin finding configurations
0035   using stored_values_t =
0036       std::variant<int, std::pair<int, int>, std::vector<std::pair<int, int>>>;
0037 
0038   /// @brief Constructor that takes the individual values for each axis
0039   /// @tparam args ... Input parameters provided by the user
0040   ///
0041   /// @param [in] vals The input parameters that define how many neighbours we need to find
0042   ///
0043   /// @pre The provided paramers must be of type 'int', 'std::pair<int, int>' or 'std::vector<std::pair<int, int>>'
0044   /// no other type is allowed. The order of these parameters must correspond to
0045   /// the same ordering of the axes in the grid
0046   template <typename... args>
0047   explicit GridBinFinder(args&&... vals)
0048     requires(
0049         sizeof...(args) == DIM &&
0050         (Concepts::same_as_any_of<std::decay_t<args>, int, std::pair<int, int>,
0051                                   std::vector<std::pair<int, int>>> &&
0052          ...))
0053   {
0054     storeValue(std::forward<args>(vals)...);
0055   }
0056 
0057   /// @brief Constructor that takes an array of axes values
0058   ///
0059   /// @param [in] values The array of stored values that define how many neighbours we need to find
0060   explicit GridBinFinder(std::array<stored_values_t, DIM> values)
0061       : m_values(std::move(values)) {}
0062 
0063   /// Get the stored bin edge values for all dimensions
0064   /// @return Array of bin edge values for each dimension
0065   const std::array<stored_values_t, DIM>& values() const { return m_values; }
0066 
0067   /// @brief Retrieve the neighbouring bins given a local position in the grid
0068   ///
0069   /// Return all bins that could contain space points that can be used with the
0070   /// space points in the bin with the provided indices to create seeds.
0071   ///
0072   /// @tparam stored_t The type of elements stored in the Grid
0073   /// @tparam Axes ... The type of the axes of the grid
0074   ///
0075   /// @param [in] locPosition The N-dimentional local position in the grid
0076   /// @param [in] grid The grid
0077   /// @return The list of neighbouring bins
0078   ///
0079   /// @pre The provided local position must be a valid local bins configuration in the grid
0080   template <typename stored_t, class... Axes>
0081   boost::container::small_vector<std::size_t, dimCubed> findBins(
0082       const std::array<std::size_t, DIM>& locPosition,
0083       const Grid<stored_t, Axes...>& grid) const;
0084 
0085  private:
0086   /// @brief Store the values provided by the user for each axis in the grid
0087   /// @tparam first_value_t Type of the first value
0088   /// @tparam vals ... values of the remaining values
0089   ///
0090   /// @param [in] fv The first value in the list
0091   /// @param [in] others The remaining values in the list
0092   ///
0093   /// @pre both first_value_t and vals ... can be only int or std::vector<std::pair<int, int>>
0094   /// In the second case, the number of entries of the vector of pairs MUST be
0095   /// equal to the number of bins in that specific axis. Empty vectors are also
0096   /// allowed but in this case the value will be replaced with a 1 (integer),
0097   /// thus instructing the code to look for neighbours in the range {-1 ,1}
0098   template <typename first_value_t, typename... vals>
0099   void storeValue(first_value_t&& fv, vals&&... others);
0100 
0101   /// @brief Get the instructions for retrieving the neighbouring bins given a local position
0102   ///
0103   /// @param [in] locPosition The requested local position
0104   /// @return the instructions for retrieving the neighbouring bins for this local position
0105   ///
0106   /// @pre The local position must be a valid local bins configuration for the grid
0107   std::array<std::pair<int, int>, DIM> getSizePerAxis(
0108       const std::array<std::size_t, DIM>& locPosition) const;
0109 
0110   /// @brief Check the GridBinFinder configuration is compatible with the grid
0111   /// by checking the values of m_values against the axes of the grid
0112   /// This function is called only in debug mode
0113   ///
0114   /// @tparam stored_t The type of elements stored in the Grid
0115   /// @tparam Axes ... The type of the axes of the grid
0116   ///
0117   /// @param [in] grid The Grid
0118   /// @return If the GridBinFinder is compatible with the grid
0119   template <typename stored_t, class... Axes>
0120   bool isGridCompatible(const Grid<stored_t, Axes...>& grid) const;
0121 
0122  private:
0123   /// @brief the instructions for retrieving the nieghbouring bins for each given axis in the grid
0124   /// These values are provided by the user and can be ints, a pair of ints or a
0125   /// vector of pair of ints. In the first case, the neighbours will be +/- bins
0126   /// from the given local bin In the second case, the user defines how many
0127   /// bins in both directions should be provided
0128   ///
0129   /// @pre The list of entries of the vector of pairs MUST be equal to the number of bins in that specific
0130   /// axis. Empty vectors are also allowed  but in this case the value will be
0131   /// replaced with a 1 (integer), thus instructing the code to look for
0132   /// neighbours in the range {-1 ,1}
0133   std::array<stored_values_t, DIM> m_values{};
0134 };
0135 
0136 }  // namespace Acts
0137 
0138 #include "Acts/Utilities/GridBinFinder.ipp"