Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-18 09:56:23

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/detail/SpacePointGridBase.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 Acts::detail::SpacePointGridBase<
0032           SphericalSpacePointGrid,
0033           Grid<std::vector<std::uint32_t>,
0034                Axis<AxisType::Equidistant, AxisBoundaryType::Closed>,
0035                Axis<AxisType::Variable, AxisBoundaryType::Open>,
0036                Axis<AxisType::Variable, AxisBoundaryType::Open>>> {
0037  public:
0038   /// Type alias for the CRTP base class
0039   using GridBase =
0040       Acts::detail::SpacePointGridBase<SphericalSpacePointGrid, GridType>;
0041   /// Type alias for the phi axis (equidistant binning, closed boundaries)
0042   using PhiAxisType = GridBase::AxisTypeAt<0>;
0043   /// Type alias for the middle (cot(theta)) axis with variable binning and
0044   /// open boundaries. Edges are stored as sinh(eta) = cot(theta), so the
0045   /// binning is configured in eta while space points are placed by z / r (see
0046   /// class doc).
0047   using CotThetaAxisType = GridBase::AxisTypeAt<1>;
0048   /// Type alias for the r axis (variable binning, open boundaries)
0049   using RAxisType = GridBase::AxisTypeAt<2>;
0050 
0051   /// Configuration parameters for the spherical space point grid.
0052   struct Config {
0053     /// minimum pT
0054     float minPt = 0 * UnitConstants::MeV;
0055     /// minimum extension of sensitive detector layer relevant for seeding as
0056     /// distance from x=y=0 (i.e. in r)
0057     /// WARNING: if rMin is smaller than impactMax, the bin size will be 2*pi,
0058     /// which will make seeding very slow!
0059     float rMin = 0 * UnitConstants::mm;
0060     /// maximum extension of sensitive detector layer relevant for seeding as
0061     /// distance from x=y=0 (i.e. in r)
0062     float rMax = 600 * UnitConstants::mm;
0063     /// minimum pseudorapidity relevant for seeding
0064     float etaMin = -4;
0065     /// maximum pseudorapidity relevant for seeding
0066     float etaMax = 4;
0067     /// maximum distance in r from middle space point to bottom or top
0068     /// space point
0069     float deltaRMax = 270 * UnitConstants::mm;
0070     /// maximum impact parameter in mm
0071     float impactMax = 0 * UnitConstants::mm;
0072     /// minimum phi value for phiAxis construction
0073     float phiMin = -std::numbers::pi_v<float>;
0074     /// maximum phi value for phiAxis construction
0075     float phiMax = std::numbers::pi_v<float>;
0076     /// Multiplicator for the number of phi-bins. The minimum number of phi-bins
0077     /// depends on min_pt, magnetic field: 2*pi/(minPT particle phi-deflection).
0078     /// phiBinDeflectionCoverage is a multiplier for this number. If
0079     /// numPhiNeighbors (in the configuration of the BinFinders) is configured
0080     /// to return 1 neighbor on either side of the current phi-bin (and you want
0081     /// to cover the full phi-range of minPT), leave this at 1.
0082     int phiBinDeflectionCoverage = 1;
0083     /// maximum number of phi bins
0084     int maxPhiBins = 10000;
0085     /// width of the equidistant eta bins used when `etaBinEdges` is empty
0086     float deltaEtaMax = 0.8;
0087     /// enable non equidistant binning in eta (edges given in pseudorapidity;
0088     /// mapped to cot(theta) = sinh(eta) internally)
0089     std::vector<float> etaBinEdges{};
0090     /// enable non equidistant binning in r
0091     std::vector<float> rBinEdges{};
0092 
0093     /// magnetic field
0094     float bFieldInZ = 0 * UnitConstants::T;
0095 
0096     /// bin finder for bottom space points
0097     std::optional<GridBinFinder<3ul>> bottomBinFinder;
0098     /// bin finder for top space points
0099     std::optional<GridBinFinder<3ul>> topBinFinder;
0100     /// navigation structure for the grid
0101     std::array<std::vector<std::size_t>, 3ul> navigation;
0102   };
0103 
0104   /// Construct a spherical space point grid with the given configuration and
0105   /// an optional logger.
0106   /// @param config Configuration for the spherical grid
0107   /// @param logger Optional logger instance for debugging output
0108   explicit SphericalSpacePointGrid(
0109       const Config& config,
0110       std::unique_ptr<const Logger> logger =
0111           getDefaultLogger("SphericalSpacePointGrid", Logging::Level::INFO));
0112 
0113   using GridBase::binIndex;
0114   /// Get the bin index for a space point.
0115   /// @param phi The azimuthal angle of the space point in radians
0116   /// @param cotTheta cot(theta) = z / r, used to place the point in its eta bin
0117   /// via cot(theta) = z / r = sinh(eta)
0118   /// @param r The radial distance of the space point from the origin
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(float phi, float cotTheta,
0122                                       float r) const {
0123     return binIndex(Vector3(phi, cotTheta, r));
0124   }
0125 
0126   using GridBase::insert;
0127   /// Insert a space point into the grid.
0128   /// @param index The index of the space point to insert
0129   /// @param phi The azimuthal angle of the space point in radians
0130   /// @param cotTheta cot(theta) = z / r, used to place the point in its eta bin
0131   /// via cot(theta) = z / r = sinh(eta)
0132   /// @param r The radial distance of the space point from the origin
0133   /// @return The index of the bin in which the space point was inserted, or
0134   ///         `std::nullopt` if the space point is outside the grid bounds.
0135   std::optional<std::size_t> insert(SpacePointIndex index, float phi,
0136                                     float cotTheta, float r) {
0137     return insert(index, Vector3(phi, cotTheta, r));
0138   }
0139   /// Insert a space point into the grid, binning it by cot(theta) = z / r
0140   /// (a single division; assumes r > 0); see the class documentation.
0141   /// @param sp The space point to insert
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(const ConstSpacePointProxy& sp) {
0145     return insert(sp.index(), sp.phi(), sp.z() / sp.r(), sp.r());
0146   }
0147 
0148   /// Sort the bins in the grid by the space point radius, which is required by
0149   /// some algorithms that operate on the grid.
0150   /// @param spacePoints The space point container to sort the bins by radius
0151   void sortBinsByR(const SpacePointContainer& spacePoints);
0152 
0153   /// Compute the range of radii in the grid. This requires the grid to be
0154   /// filled with space points and sorted by radius. The sorting can be done
0155   /// with the `sortBinsByR` method.
0156   /// @param spacePoints The space point container to compute the radius range
0157   /// @return The range of radii in the grid
0158   Range1D<float> computeRadiusRange(
0159       const SpacePointContainer& spacePoints) const;
0160 
0161  private:
0162   Config m_cfg;
0163 };
0164 
0165 }  // namespace Acts::Experimental