Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-07 07:58:52

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/Common.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/EventData/SpacePointContainer2.hpp"
0015 #include "Acts/Seeding/BinnedGroup.hpp"
0016 #include "Acts/Utilities/Grid.hpp"
0017 #include "Acts/Utilities/Logger.hpp"
0018 #include "Acts/Utilities/RangeXD.hpp"
0019 
0020 #include <numbers>
0021 #include <vector>
0022 
0023 namespace Acts {
0024 
0025 /// A cartesian space point grid used for seeding in a cartesian detector
0026 /// geometry.
0027 /// The grid is defined in cartesian coordinates (x,y,z).
0028 class CartesianSpacePointGrid {
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 x axis with equidistant binning and open boundaries
0035   using XAxisType = Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0036   /// Type alias for y axis with equidistant binning and open boundaries
0037   using YAxisType = Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0038   /// Type alias for z axis with equidistant binning and open boundaries
0039   using ZAxisType = Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0040   /// cartesian space point grid type, which is a grid over `BinType` with
0041   /// axes defined by `XAxisType`, `YAxisType`, and `ZAxisType`.
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, XAxisType, YAxisType, ZAxisType>;
0045   /// Type alias for binned group over the cartesian grid
0046   using BinnedGroupType = BinnedGroup<GridType>;
0047 
0048   /// Configuration parameters for the cartesian space point grid.
0049   struct Config {
0050     /// minimum pT
0051 
0052     /// number of bins in the x-coordinate
0053     int nXbins = 10;
0054     /// minimum x-coordinate of space points used in the seeding
0055     float xMin = -600 * UnitConstants::mm;
0056     /// maximum x-coordinate of space points used in the seeding
0057     float xMax = 600 * UnitConstants::mm;
0058     /// number of bins in the y-coordinate
0059     int nYbins = 6;
0060     /// minimum y-coordinate of space points used in the seeding
0061     float yMin = -600 * UnitConstants::mm;
0062     /// maximum y-coordinate of space points used in the seeding
0063     float yMax = 600 * UnitConstants::mm;
0064     /// number of bins in the z-coordinate
0065     int nZbins = 10;
0066     /// minimum z coordinate ofspace points used in the seeding
0067     float zMin = -2700 * UnitConstants::mm;
0068     /// maximum z coordinate ofspace points used in the seeding
0069     float zMax = 2700 * UnitConstants::mm;
0070 
0071     /// bin finder for bottom space points
0072     std::optional<GridBinFinder<3ul>> bottomBinFinder;
0073     /// bin finder for top space points
0074     std::optional<GridBinFinder<3ul>> topBinFinder;
0075     /// navigation structure for the grid
0076     std::array<std::vector<std::size_t>, 3ul> navigation;
0077 
0078     /// coordinate to sort the space points by
0079     Acts::CoordinateIndices sortingCoord = Acts::CoordinateIndices::eY;
0080 
0081     /// direction to sort the space points in
0082     Acts::Direction sortingDirection = Acts::Direction::Negative();
0083   };
0084 
0085   /// Construct a cartesian space point grid with the given configuration and
0086   /// an optional logger.
0087   /// @param config Configuration for the cartesian grid
0088   /// @param logger Optional logger instance for debugging output
0089   explicit CartesianSpacePointGrid(
0090       const Config& config,
0091       std::unique_ptr<const Logger> logger =
0092           getDefaultLogger("CartesianSpacePointGrid", Logging::Level::INFO));
0093 
0094   /// Clear the grid and drop all state. The object will behave like a newly
0095   /// constructed one.
0096   void clear();
0097 
0098   /// Get the bin index for a space point given its x-, y-, and z-coordinate.
0099   /// @param position The position of the space point in (x,y,z) coordinates
0100   /// @return The index of the bin in which the space point is located, or
0101   ///         `std::nullopt` if the space point is outside the grid bounds.
0102   std::optional<std::size_t> binIndex(const Vector3& position) const {
0103     if (!grid().isInside(position)) {
0104       return std::nullopt;
0105     }
0106     return grid().globalBinFromPosition(position);
0107   }
0108   /// Get the bin index for a space point given its azimuthal angle, radial
0109   /// distance, and z-coordinate.
0110   /// @param x The x-coordinate of the space point
0111   /// @param y The y-coordinate of the space point
0112   /// @param z The z-coordinate of the space point
0113   /// @return The index of the bin in which the space point is located, or
0114   ///         `std::nullopt` if the space point is outside the grid bounds.
0115   std::optional<std::size_t> binIndex(float x, float y, float z) const {
0116     return binIndex(Vector3(x, y, z));
0117   }
0118 
0119   /// Insert a space point into the grid.
0120   /// @param index The index of the space point to insert
0121   /// @param x The x-coordinate the space point
0122   /// @param y The y-coordinate the space point
0123   /// @param z The z-coordinate the space point
0124   /// @return The index of the bin in which the space point was inserted, or
0125   ///         `std::nullopt` if the space point is outside the grid bounds.
0126   std::optional<std::size_t> insert(SpacePointIndex index, float x, float y,
0127                                     float z);
0128   /// Insert a space point into the grid.
0129   /// @param sp The space point to insert
0130   /// @return The index of the bin in which the space point was inserted, or
0131   ///         `std::nullopt` if the space point is outside the grid bounds.
0132   std::optional<std::size_t> insert(const ConstSpacePointProxy2& sp) {
0133     return insert(sp.index(), sp.x(), sp.y(), sp.z());
0134   }
0135 
0136   /// Fill the grid with space points from the container.
0137   /// @param spacePoints The space point container to fill the grid with
0138   void extend(const SpacePointContainer2::ConstRange& spacePoints);
0139 
0140   /// Sort the bins in the grid by the space point sorting-coordinate, which is
0141   /// required by some algorithms that operate on the grid.
0142   /// @param spacePoints The space point container to sort the bins by the configured coordinate
0143   void sortBinsByCoord(const SpacePointContainer2& spacePoints);
0144 
0145   /// Compute the range of the sorting coordinates in the grid. This requires
0146   /// the grid to be filled with space points and sorted by coordinate. The
0147   /// sorting can be done with the `sortBinsByY` method.
0148   /// @param spacePoints The space point container to compute the y-range
0149   /// @return The range of y-values in the grid
0150   Range1D<float> computeCoordRange(
0151       const SpacePointContainer2& spacePoints) const;
0152 
0153   /// Mutable bin access by index.
0154   /// @param index The index of the bin to access
0155   /// @return Mutable reference to the bin at the specified index
0156   BinType& at(std::size_t index) { return grid().at(index); }
0157 
0158   /// Const bin access by index.
0159   /// @param index The index of the bin to access
0160   /// @return Const reference to the bin at the specified index
0161   const BinType& at(std::size_t index) const { return grid().at(index); }
0162 
0163   /// Mutable grid access.
0164   /// @return Mutable reference to the grid
0165   GridType& grid() { return *m_grid; }
0166   /// Const grid access.
0167   /// @return Const reference to the grid
0168   const GridType& grid() const { return *m_grid; }
0169 
0170   /// Access to the binned group.
0171   /// @return Reference to the binned group
0172   const BinnedGroupType& binnedGroup() const { return *m_binnedGroup; }
0173 
0174   /// Get the number of space points in the grid.
0175   /// @return The number of space points in the grid
0176   std::size_t numberOfSpacePoints() const { return m_counter; }
0177 
0178   /// Get the number of bins in the grid.
0179   /// @return The number of bins in the grid
0180   std::size_t numberOfBins() const { return grid().size(); }
0181 
0182  private:
0183   Config m_cfg;
0184 
0185   std::unique_ptr<const Logger> m_logger;
0186 
0187   GridType* m_grid{};
0188   std::optional<BinnedGroupType> m_binnedGroup;
0189 
0190   std::size_t m_counter{};
0191 
0192   std::function<float(const ConstSpacePointProxy2&)> m_sortCoordGetter;
0193 
0194   const Logger& logger() const { return *m_logger; }
0195 };
0196 
0197 }  // namespace Acts