Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:11:19

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