Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:18:25

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/Units.hpp"
0012 #include "Acts/EventData/SpacePointContainer.hpp"
0013 #include "Acts/Utilities/KDTree.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 
0016 #include <vector>
0017 
0018 namespace Acts::Experimental {
0019 
0020 /// A cylindrical space point KD-tree used for seeding in a cylindrical detector
0021 /// geometry.
0022 /// The tree is defined in cylindrical coordinates (phi, r, z) and allows for
0023 /// efficient access to space points based on their azimuthal angle,
0024 /// radial distance, and z-coordinate.
0025 class CylindricalSpacePointKDTree {
0026  public:
0027   /// Space point index type used in the grid.
0028   using SpacePointIndex = std::uint32_t;
0029 
0030   /// @brief Set the number of dimensions in which to embed points. This is just
0031   /// 3 for now (phi, r, and z), but we might want to increase or decrease this
0032   /// number in the future.
0033   static constexpr std::size_t NDims = 3;
0034 
0035   /// @brief Enumeration of the different dimensions in which we can apply cuts.
0036   enum Dim { DimPhi = 0, DimR = 1, DimZ = 2 };
0037 
0038   /// @brief The k-d tree type used by this seeder internally, which is
0039   /// three-dimensional, contains internal space point pointers, uses the Acts
0040   /// scalar type for coordinates, stores its coordinates in std::arrays, and
0041   /// has leaf size 4.
0042   using Tree = KDTree<NDims, SpacePointIndex, float, std::array, 4>;
0043 
0044   /// Configuration options for cylindrical space point selection.
0045   struct Options {
0046     /// maximum extension of sensitive detector layer relevant for seeding as
0047     /// distance from x=y=0 (i.e. in r)
0048     float rMax = 600 * UnitConstants::mm;
0049     /// minimum extension of sensitive detector layer relevant for seeding in
0050     /// negative direction in z
0051     float zMin = -2800 * UnitConstants::mm;
0052     /// maximum extension of sensitive detector layer relevant for seeding in
0053     /// positive direction in z
0054     float zMax = 2800 * UnitConstants::mm;
0055     /// minimum phi value for phiAxis construction
0056     float phiMin = -std::numbers::pi_v<float>;
0057     /// maximum phi value for phiAxis construction
0058     float phiMax = std::numbers::pi_v<float>;
0059 
0060     /// Minimum radial distance between two doublet components
0061     float deltaRMin = 5 * UnitConstants::mm;
0062     /// Maximum radial distance between two doublet components
0063     float deltaRMax = 270 * UnitConstants::mm;
0064 
0065     /// Minimal z distance between two doublet components
0066     float deltaZMin = -std::numeric_limits<float>::infinity();
0067     /// Maximum z distance between two doublet components
0068     float deltaZMax = std::numeric_limits<float>::infinity();
0069 
0070     /// Limiting location of collision region in z-axis used to check if doublet
0071     /// origin is within reasonable bounds
0072     float collisionRegionMin = -150 * UnitConstants::mm;
0073     /// Maximum location of collision region in z-axis
0074     float collisionRegionMax = +150 * UnitConstants::mm;
0075 
0076     /// Maximum allowed cotTheta between two space-points in doublet, used to
0077     /// check if forward angle is within bounds
0078     float cotThetaMax = 10.01788;  // equivalent to eta = 3 (pseudorapidity)
0079 
0080     /// Shrink the phi range of middle space-point (analogous to phi bin size in
0081     /// grid from default seeding + number of phi bins used in search)
0082     float deltaPhiMax = 0.085;
0083   };
0084 
0085   /// Candidate space point indices grouped by z ordering.
0086   struct Candidates {
0087     /// denotes the candidates bottom seed points, assuming that the track has
0088     /// monotonically _increasing_ z position
0089     std::vector<SpacePointIndex> bottom_lh_v;
0090     /// denotes the candidate bottom points assuming that the track has
0091     /// monotonically _decreasing_ z position
0092     std::vector<SpacePointIndex> bottom_hl_v;
0093     /// are the candidate top points for an increasing z track
0094     std::vector<SpacePointIndex> top_lh_v;
0095     /// are the candidate top points for a decreasing z track
0096     std::vector<SpacePointIndex> top_hl_v;
0097 
0098     /// Reserve space for candidates
0099     /// @param n Number of candidates to reserve space for
0100     void reserve(std::size_t n) {
0101       bottom_lh_v.reserve(n);
0102       bottom_hl_v.reserve(n);
0103       top_lh_v.reserve(n);
0104       top_hl_v.reserve(n);
0105     }
0106 
0107     /// @brief Clear all candidate vectors
0108     void clear() {
0109       bottom_lh_v.clear();
0110       bottom_hl_v.clear();
0111       top_lh_v.clear();
0112       top_hl_v.clear();
0113     }
0114   };
0115 
0116   /// Construct a cylindrical space point grid with the given configuration and
0117   /// an optional logger.
0118   /// @param tree KD tree
0119   /// @param logger Optional logger
0120   explicit CylindricalSpacePointKDTree(
0121       Tree tree, std::unique_ptr<const Logger> logger = getDefaultLogger(
0122                      "CylindricalSpacePointKDTree", Logging::Level::INFO));
0123 
0124   /// @brief Return the number of space points in the tree
0125   /// @return Number of space points
0126   std::size_t size() const { return m_tree.size(); }
0127 
0128   /// @brief Return iterator to the beginning of the tree
0129   /// @return Begin iterator
0130   auto begin() const { return m_tree.begin(); }
0131   /// @brief Return iterator to the end of the tree
0132   /// @return End iterator
0133   auto end() const { return m_tree.end(); }
0134 
0135   /// @brief Get valid orthogonal range for low-high pairs
0136   /// @param options Search options
0137   /// @param low Low space point
0138   /// @return Valid range
0139   Tree::range_t validTupleOrthoRangeLH(const Options& options,
0140                                        const ConstSpacePointProxy& low) const;
0141   /// @brief Get valid orthogonal range for high-low pairs
0142   /// @param options Search options
0143   /// @param high High space point
0144   /// @return Valid range
0145   Tree::range_t validTupleOrthoRangeHL(const Options& options,
0146                                        const ConstSpacePointProxy& high) const;
0147 
0148   /// @brief Find valid seed tuples
0149   /// @param lhOptions Low-high search options
0150   /// @param hlOptions High-low search options
0151   /// @param spM Middle space point
0152   /// @param nTopSeedConf Number of top seed configurations
0153   /// @param candidates Output candidates container
0154   void validTuples(const Options& lhOptions, const Options& hlOptions,
0155                    const ConstSpacePointProxy& spM, std::size_t nTopSeedConf,
0156                    Candidates& candidates) const;
0157 
0158  private:
0159   Tree m_tree;
0160 
0161   std::unique_ptr<const Logger> m_logger;
0162 
0163   const Logger& logger() const { return *m_logger; }
0164 };
0165 
0166 /// Builder for cylindrical space point KD-trees.
0167 class CylindricalSpacePointKDTreeBuilder {
0168  public:
0169   /// space point index type used in the grid.
0170   using SpacePointIndex = CylindricalSpacePointKDTree::SpacePointIndex;
0171 
0172   /// @brief Set the number of dimensions in which to embed points. This is just
0173   /// 3 for now (phi, r, and z), but we might want to increase or decrease
0174   /// this number in the future.
0175   static constexpr std::size_t NDims = CylindricalSpacePointKDTree::NDims;
0176 
0177   /// @brief Enumeration of the different dimensions in which we can apply cuts.
0178   using Dim = CylindricalSpacePointKDTree::Dim;
0179 
0180   /// @brief The k-d tree type used by this seeder internally, which is
0181   /// three-dimensional, contains internal space point pointers, uses the Acts
0182   /// scalar type for coordinates, stores its coordinates in std::arrays, and
0183   /// has leaf size 4.
0184   using Tree = CylindricalSpacePointKDTree::Tree;
0185 
0186   /// Construct a cylindrical space point grid with the given configuration
0187   /// and an optional logger.
0188   /// @param logger Optional logger instance
0189   explicit CylindricalSpacePointKDTreeBuilder(
0190       std::unique_ptr<const Logger> logger = getDefaultLogger(
0191           "CylindricalSpacePointKDTree", Logging::Level::INFO));
0192 
0193   /// Get the number of space points in the grid.
0194   /// @return The number of space points in the grid
0195   std::size_t size() const { return m_points.size(); }
0196 
0197   /// Reserve space for space points
0198   /// @param n Number of space points to reserve space for
0199   void reserve(std::size_t n) { m_points.reserve(n); }
0200 
0201   /// Clear the grid and drop all state. The object will behave like a newly
0202   /// constructed one.
0203   void clear() { m_points.clear(); }
0204 
0205   /// Insert a space point into the grid.
0206   /// @param index The index of the space point to insert
0207   /// @param phi The azimuthal angle of the space point in radians
0208   /// @param r The radial distance of the space point from the origin
0209   /// @param z The z-coordinate of the space point
0210   void insert(SpacePointIndex index, float phi, float r, float z);
0211 
0212   /// Insert a space point into the grid.
0213   /// @param sp The space point to insert
0214   void insert(const ConstSpacePointProxy& sp) {
0215     return insert(sp.index(), sp.phi(), sp.r(), sp.z());
0216   }
0217 
0218   /// Fill the grid with space points from the container.
0219   /// @param spacePoints The space point container to fill the grid with
0220   void extend(const SpacePointContainer::ConstRange& spacePoints);
0221 
0222   /// Build the KD-tree from accumulated space points
0223   /// @return The constructed cylindrical space point KD-tree
0224   CylindricalSpacePointKDTree build();
0225 
0226  private:
0227   std::unique_ptr<const Logger> m_logger;
0228 
0229   std::vector<Tree::pair_t> m_points;
0230 
0231   const Logger& logger() const { return *m_logger; }
0232 };
0233 
0234 }  // namespace Acts::Experimental