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/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 {
0022 
0023 /// A cylindrical space point grid used for seeding in a cylindrical detector
0024 /// geometry.
0025 /// The grid is defined in cylindrical coordinates (phi, z, r) and allows for
0026 /// efficient access to space points based on their azimuthal angle,
0027 /// z-coordinate, and radial distance.
0028 class CylindricalSpacePointGrid {
0029  public:
0030   /// Space point index type used in the grid.
0031   using SpacePointIndex = std::uint32_t;
0032   /// Type alias for bin container holding space point indices
0033   using BinType = std::vector<SpacePointIndex>;
0034   /// Type alias for phi axis with equidistant binning and closed boundaries
0035   using PhiAxisType = Axis<AxisType::Equidistant, AxisBoundaryType::Closed>;
0036   /// Type alias for z axis with variable binning and open boundaries
0037   using ZAxisType = Axis<AxisType::Variable, AxisBoundaryType::Open>;
0038   /// Type alias for r axis with variable binning and open boundaries
0039   using RAxisType = Axis<AxisType::Variable, AxisBoundaryType::Open>;
0040   /// Cylindrical space point grid type, which is a grid over `BinType` with
0041   /// axes defined by `PhiAxisType`, `ZAxisType`, and `RAxisType`.
0042   /// The grid is a 3D grid with the axes representing azimuthal angle (phi),
0043   /// z-coordinate, and radial distance (r).
0044   using GridType = Grid<BinType, PhiAxisType, ZAxisType, RAxisType>;
0045   /// Type alias for binned group over the cylindrical grid
0046   using BinnedGroupType = BinnedGroup<GridType>;
0047 
0048   /// Configuration parameters for the cylindrical space point grid.
0049   struct Config {
0050     /// minimum pT
0051     float minPt = 0 * UnitConstants::MeV;
0052     /// minimum extension of sensitive detector layer relevant for seeding as
0053     /// distance from x=y=0 (i.e. in r)
0054     /// WARNING: if rMin is smaller than impactMax, the bin size will be 2*pi,
0055     /// which will make seeding very slow!
0056     float rMin = 0 * UnitConstants::mm;
0057     /// maximum extension of sensitive detector layer relevant for seeding as
0058     /// distance from x=y=0 (i.e. in r)
0059     float rMax = 600 * UnitConstants::mm;
0060     /// minimum extension of sensitive detector layer relevant for seeding in
0061     /// negative direction in z
0062     float zMin = -2800 * UnitConstants::mm;
0063     /// maximum extension of sensitive detector layer relevant for seeding in
0064     /// positive direction in z
0065     float zMax = 2800 * UnitConstants::mm;
0066     /// maximum distance in r from middle space point to bottom or top
0067     /// space point
0068     float deltaRMax = 270 * UnitConstants::mm;
0069     /// maximum forward direction expressed as cot(theta)
0070     float cotThetaMax = 10.01788;  // equivalent to eta = 3 (pseudorapidity)
0071     /// maximum impact parameter in mm
0072     float impactMax = 0 * UnitConstants::mm;
0073     /// minimum phi value for phiAxis construction
0074     float phiMin = -std::numbers::pi_v<float>;
0075     /// maximum phi value for phiAxis construction
0076     float phiMax = std::numbers::pi_v<float>;
0077     /// Multiplicator for the number of phi-bins. The minimum number of phi-bins
0078     /// depends on min_pt, magnetic field: 2*pi/(minPT particle phi-deflection).
0079     /// phiBinDeflectionCoverage is a multiplier for this number. If
0080     /// numPhiNeighbors (in the configuration of the BinFinders) is configured
0081     /// to return 1 neighbor on either side of the current phi-bin (and you want
0082     /// to cover the full phi-range of minPT), leave this at 1.
0083     int phiBinDeflectionCoverage = 1;
0084     /// maximum number of phi bins
0085     int maxPhiBins = 10000;
0086     /// enable non equidistant binning in z
0087     std::vector<float> zBinEdges{};
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 cylindrical space point grid with the given configuration and
0103   /// an optional logger.
0104   /// @param config Configuration for the cylindrical grid
0105   /// @param logger Optional logger instance for debugging output
0106   explicit CylindricalSpacePointGrid(
0107       const Config& config,
0108       std::unique_ptr<const Logger> logger =
0109           getDefaultLogger("CylindricalSpacePointGrid", 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, radial
0116   /// distance, and z-coordinate.
0117   /// @param position The position of the space point in (phi, z, r) coordinates
0118   /// @return The index of the bin in which the space point is located, or
0119   ///         `std::nullopt` if the space point is outside the grid bounds.
0120   std::optional<std::size_t> binIndex(const Vector3& position) const {
0121     if (!grid().isInside(position)) {
0122       return std::nullopt;
0123     }
0124     return grid().globalBinFromPosition(position);
0125   }
0126   /// Get the bin index for a space point given its azimuthal angle, radial
0127   /// distance, and z-coordinate.
0128   /// @param phi The azimuthal angle of the space point in radians
0129   /// @param z The z-coordinate of the space point
0130   /// @param r The radial distance of the space point from the origin
0131   /// @return The index of the bin in which the space point is located, or
0132   ///         `std::nullopt` if the space point is outside the grid bounds.
0133   std::optional<std::size_t> binIndex(float phi, float z, float r) const {
0134     return binIndex(Vector3(phi, z, r));
0135   }
0136 
0137   /// Insert a space point into the grid.
0138   /// @param index The index of the space point to insert
0139   /// @param phi The azimuthal angle of the space point in radians
0140   /// @param z The z-coordinate of the space point
0141   /// @param r The radial distance of the space point from the origin
0142   /// @return The index of the bin in which the space point was inserted, or
0143   ///         `std::nullopt` if the space point is outside the grid bounds.
0144   std::optional<std::size_t> insert(SpacePointIndex index, float phi, float z,
0145                                     float r);
0146   /// Insert a space point into the grid.
0147   /// @param sp The space point to insert
0148   /// @return The index of the bin in which the space point was inserted, or
0149   ///         `std::nullopt` if the space point is outside the grid bounds.
0150   std::optional<std::size_t> insert(const ConstSpacePointProxy& sp) {
0151     return insert(sp.index(), sp.phi(), sp.z(), sp.r());
0152   }
0153 
0154   /// Fill the grid with space points from the container.
0155   /// @param spacePoints The space point container to fill the grid with
0156   void extend(const SpacePointContainer::ConstRange& spacePoints);
0157 
0158   /// Sort the bins in the grid by the space point radius, which is required by
0159   /// some algorithms that operate on the grid.
0160   /// @param spacePoints The space point container to sort the bins by radius
0161   void sortBinsByR(const SpacePointContainer& spacePoints);
0162 
0163   /// Compute the range of radii in the grid. This requires the grid to be
0164   /// filled with space points and sorted by radius. The sorting can be done
0165   /// with the `sortBinsByR` method.
0166   /// @param spacePoints The space point container to compute the radius range
0167   /// @return The range of radii in the grid
0168   Range1D<float> computeRadiusRange(
0169       const SpacePointContainer& spacePoints) const;
0170 
0171   /// Mutable bin access by index.
0172   /// @param index The index of the bin to access
0173   /// @return Mutable reference to the bin at the specified index
0174   BinType& at(std::size_t index) { return grid().at(index); }
0175   /// Const bin access by index.
0176   /// @param index The index of the bin to access
0177   /// @return Const reference to the bin at the specified index
0178   const BinType& at(std::size_t index) const { return grid().at(index); }
0179 
0180   /// Mutable grid access.
0181   /// @return Mutable reference to the grid
0182   GridType& grid() { return *m_grid; }
0183   /// Const grid access.
0184   /// @return Const reference to the grid
0185   const GridType& grid() const { return *m_grid; }
0186 
0187   /// Access to the binned group.
0188   /// @return Reference to the binned group
0189   const BinnedGroupType& binnedGroup() const { return *m_binnedGroup; }
0190 
0191   /// Get the number of space points in the grid.
0192   /// @return The number of space points in the grid
0193   std::size_t numberOfSpacePoints() const { return m_counter; }
0194 
0195   /// Get the number of bins in the grid.
0196   /// @return The number of bins in the grid
0197   std::size_t numberOfBins() const { return grid().size(); }
0198 
0199  private:
0200   Config m_cfg;
0201 
0202   std::unique_ptr<const Logger> m_logger;
0203 
0204   GridType* m_grid{};
0205   std::optional<BinnedGroupType> m_binnedGroup;
0206 
0207   std::size_t m_counter{};
0208 
0209   const Logger& logger() const { return *m_logger; }
0210 };
0211 
0212 }  // namespace Acts