Back to home page

EIC code displayed by LXR

 
 

    


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

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/Seeding/BinnedGroup.hpp"
0014 #include "Acts/Utilities/Grid.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "Acts/Utilities/RangeXD.hpp"
0017 
0018 #include <numbers>
0019 #include <vector>
0020 
0021 namespace Acts::Experimental {
0022 
0023 /// A spherical space point grid for seeding, binned in (phi, eta, r).
0024 ///
0025 /// A space point's eta bin is found from cot(theta) = z / r (a single
0026 /// division), matched against bin edges that are stored as sinh(eta). Since
0027 /// cot(theta) = sinh(eta), comparing z / r against those edges
0028 /// places the point into exactly its eta bin, with no atan2 / tan / log /
0029 /// asinh.
0030 class SphericalSpacePointGrid {
0031  public:
0032   /// Space point index type used in the grid.
0033   using SpacePointIndex = std::uint32_t;
0034   /// Type alias for bin container holding space point indices
0035   using BinType = std::vector<SpacePointIndex>;
0036   /// Type alias for phi axis with equidistant binning and closed boundaries
0037   using PhiAxisType = Axis<AxisType::Equidistant, AxisBoundaryType::Closed>;
0038   /// Type alias for the middle (cot(theta)) axis with variable binning and open
0039   /// boundaries. Edges are stored as sinh(eta) = cot(theta), so the binning is
0040   /// configured in eta while space points are placed by z / r (see class doc).
0041   using CotThetaAxisType = Axis<AxisType::Variable, AxisBoundaryType::Open>;
0042   /// Type alias for r axis with variable binning and open boundaries
0043   using RAxisType = Axis<AxisType::Variable, AxisBoundaryType::Open>;
0044   /// Spherical space point grid type (phi, eta, r)
0045   using GridType = Grid<BinType, PhiAxisType, CotThetaAxisType, RAxisType>;
0046   /// Type alias for binned group over the spherical grid
0047   using BinnedGroupType = BinnedGroup<GridType>;
0048 
0049   /// Configuration parameters for the spherical space point grid.
0050   struct Config {
0051     /// minimum pT
0052     float minPt = 0 * UnitConstants::MeV;
0053     /// minimum extension of sensitive detector layer relevant for seeding as
0054     /// distance from x=y=0 (i.e. in r)
0055     /// WARNING: if rMin is smaller than impactMax, the bin size will be 2*pi,
0056     /// which will make seeding very slow!
0057     float rMin = 0 * UnitConstants::mm;
0058     /// maximum extension of sensitive detector layer relevant for seeding as
0059     /// distance from x=y=0 (i.e. in r)
0060     float rMax = 600 * UnitConstants::mm;
0061     /// minimum pseudorapidity relevant for seeding
0062     float etaMin = -4;
0063     /// maximum pseudorapidity relevant for seeding
0064     float etaMax = 4;
0065     /// maximum distance in r from middle space point to bottom or top
0066     /// space point
0067     float deltaRMax = 270 * UnitConstants::mm;
0068     /// maximum impact parameter in mm
0069     float impactMax = 0 * UnitConstants::mm;
0070     /// minimum phi value for phiAxis construction
0071     float phiMin = -std::numbers::pi_v<float>;
0072     /// maximum phi value for phiAxis construction
0073     float phiMax = std::numbers::pi_v<float>;
0074     /// Multiplicator for the number of phi-bins. The minimum number of phi-bins
0075     /// depends on min_pt, magnetic field: 2*pi/(minPT particle phi-deflection).
0076     /// phiBinDeflectionCoverage is a multiplier for this number. If
0077     /// numPhiNeighbors (in the configuration of the BinFinders) is configured
0078     /// to return 1 neighbor on either side of the current phi-bin (and you want
0079     /// to cover the full phi-range of minPT), leave this at 1.
0080     int phiBinDeflectionCoverage = 1;
0081     /// maximum number of phi bins
0082     int maxPhiBins = 10000;
0083     /// width of the equidistant eta bins used when `etaBinEdges` is empty
0084     float deltaEtaMax = 0.8;
0085     /// enable non equidistant binning in eta (edges given in pseudorapidity;
0086     /// mapped to cot(theta) = sinh(eta) internally)
0087     std::vector<float> etaBinEdges{};
0088     /// enable non equidistant binning in r
0089     std::vector<float> rBinEdges{};
0090 
0091     /// magnetic field
0092     float bFieldInZ = 0 * UnitConstants::T;
0093 
0094     /// bin finder for bottom space points
0095     std::optional<GridBinFinder<3ul>> bottomBinFinder;
0096     /// bin finder for top space points
0097     std::optional<GridBinFinder<3ul>> topBinFinder;
0098     /// navigation structure for the grid
0099     std::array<std::vector<std::size_t>, 3ul> navigation;
0100   };
0101 
0102   /// Construct a spherical space point grid with the given configuration and
0103   /// an optional logger.
0104   /// @param config Configuration for the spherical grid
0105   /// @param logger Optional logger instance for debugging output
0106   explicit SphericalSpacePointGrid(
0107       const Config& config,
0108       std::unique_ptr<const Logger> logger =
0109           getDefaultLogger("SphericalSpacePointGrid", Logging::Level::INFO));
0110 
0111   /// Clear the grid and drop all state. The object will behave like a newly
0112   /// constructed one.
0113   void clear();
0114 
0115   /// Get the bin index for a space point given its azimuthal angle,
0116   /// cot(theta) = z / r, and radial distance.
0117   /// @param position The position of the space point in (phi, cotTheta, r)
0118   /// coordinates
0119   /// @return The index of the bin in which the space point is located, or
0120   ///         `std::nullopt` if the space point is outside the grid bounds.
0121   std::optional<std::size_t> binIndex(const Vector3& position) const {
0122     if (!grid().isInside(position)) {
0123       return std::nullopt;
0124     }
0125     return grid().globalBinFromPosition(position);
0126   }
0127   /// Get the bin index for a space point.
0128   /// @param phi The azimuthal angle of the space point in radians
0129   /// @param cotTheta cot(theta) = z / r, used to place the point in its eta bin
0130   /// via cot(theta) = z / r = sinh(eta)
0131   /// @param r The radial distance of the space point from the origin
0132   /// @return The index of the bin in which the space point is located, or
0133   ///         `std::nullopt` if the space point is outside the grid bounds.
0134   std::optional<std::size_t> binIndex(float phi, float cotTheta,
0135                                       float r) const {
0136     return binIndex(Vector3(phi, cotTheta, r));
0137   }
0138 
0139   /// Insert a space point into the grid.
0140   /// @param index The index of the space point to insert
0141   /// @param phi The azimuthal angle of the space point in radians
0142   /// @param cotTheta cot(theta) = z / r, used to place the point in its eta bin
0143   /// via cot(theta) = z / r = sinh(eta)
0144   /// @param r The radial distance of the space point from the origin
0145   /// @return The index of the bin in which the space point was inserted, or
0146   ///         `std::nullopt` if the space point is outside the grid bounds.
0147   std::optional<std::size_t> insert(SpacePointIndex index, float phi,
0148                                     float cotTheta, float r);
0149   /// Insert a space point into the grid, binning it by cot(theta) = z / r
0150   /// (a single division; assumes r > 0); see the class documentation.
0151   /// @param sp The space point to insert
0152   /// @return The index of the bin in which the space point was inserted, or
0153   ///         `std::nullopt` if the space point is outside the grid bounds.
0154   std::optional<std::size_t> insert(const ConstSpacePointProxy& sp) {
0155     return insert(sp.index(), sp.phi(), sp.z() / sp.r(), sp.r());
0156   }
0157 
0158   /// Fill the grid with space points from the container.
0159   /// @param spacePoints The space point container to fill the grid with
0160   void extend(const SpacePointContainer::ConstRange& spacePoints);
0161 
0162   /// Sort the bins in the grid by the space point radius, which is required by
0163   /// some algorithms that operate on the grid.
0164   /// @param spacePoints The space point container to sort the bins by radius
0165   void sortBinsByR(const SpacePointContainer& spacePoints);
0166 
0167   /// Compute the range of radii in the grid. This requires the grid to be
0168   /// filled with space points and sorted by radius. The sorting can be done
0169   /// with the `sortBinsByR` method.
0170   /// @param spacePoints The space point container to compute the radius range
0171   /// @return The range of radii in the grid
0172   Range1D<float> computeRadiusRange(
0173       const SpacePointContainer& spacePoints) const;
0174 
0175   /// Mutable bin access by index.
0176   /// @param index The index of the bin to access
0177   /// @return Mutable reference to the bin at the specified index
0178   BinType& at(std::size_t index) { return grid().at(index); }
0179   /// Const bin access by index.
0180   /// @param index The index of the bin to access
0181   /// @return Const reference to the bin at the specified index
0182   const BinType& at(std::size_t index) const { return grid().at(index); }
0183 
0184   /// Mutable grid access.
0185   /// @return Mutable reference to the grid
0186   GridType& grid() { return *m_grid; }
0187   /// Const grid access.
0188   /// @return Const reference to the grid
0189   const GridType& grid() const { return *m_grid; }
0190 
0191   /// Access to the binned group.
0192   /// @return Reference to the binned group
0193   const BinnedGroupType& binnedGroup() const { return *m_binnedGroup; }
0194 
0195   /// Get the number of space points in the grid.
0196   /// @return The number of space points in the grid
0197   std::size_t numberOfSpacePoints() const { return m_counter; }
0198 
0199   /// Get the number of bins in the grid.
0200   /// @return The number of bins in the grid
0201   std::size_t numberOfBins() const { return grid().size(); }
0202 
0203  private:
0204   Config m_cfg;
0205 
0206   std::unique_ptr<const Logger> m_logger;
0207 
0208   GridType* m_grid{};
0209   std::optional<BinnedGroupType> m_binnedGroup;
0210 
0211   std::size_t m_counter{};
0212 
0213   const Logger& logger() const { return *m_logger; }
0214 };
0215 
0216 }  // namespace Acts::Experimental