Back to home page

EIC code displayed by LXR

 
 

    


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

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/EventData/StripSpacePointCalibrationDetails.hpp"
0012 #include "Acts/EventData/Types.hpp"
0013 #include "Acts/Seeding/GbtsLayerDescription.hpp"
0014 
0015 #include <array>
0016 #include <cstdint>
0017 #include <limits>
0018 #include <span>
0019 #include <utility>
0020 #include <vector>
0021 
0022 namespace Acts::Experimental::detail {
0023 
0024 /// Accepted |cot(theta)| range for one cluster width bin. A cluster near the
0025 /// module edge may be shortened, hence the second pair.
0026 struct GbtsTauBounds final {
0027   /// Minimum accepted |cot(theta)|.
0028   float minTau{};
0029   /// Maximum accepted |cot(theta)|. Negative means undertrained: do not cut.
0030   float maxTau{};
0031   /// Minimum accepted |cot(theta)| near the module edge.
0032   float minTauNearEdge{};
0033   /// Maximum accepted |cot(theta)| near the module edge. Negative as above.
0034   float maxTauNearEdge{};
0035 };
0036 
0037 /// Tau bounds per cluster width, one entry per 0.05 mm, indexed not searched.
0038 using GbtsTauLookupTable = std::vector<GbtsTauBounds>;
0039 
0040 /// Maximum number of neighbouring edges recorded per graph edge
0041 static constexpr std::uint32_t kGbtsMaxEdgeNeighbours = 6;
0042 
0043 /// Bins of the per-node z0 histogram, which is kept as a bit mask in
0044 /// GbtsNodeEdgeInfo::isConnected and so may not exceed its width.
0045 static constexpr std::int32_t kGbtsZ0HistogramBins = 16;
0046 static_assert(kGbtsZ0HistogramBins <=
0047               std::numeric_limits<std::uint16_t>::digits);
0048 
0049 //! [gbts node params]
0050 /// Per-node parameters used while building the graph.
0051 ///
0052 /// All five values are read together in the innermost doublet loop, so they sit
0053 /// in one record rather than in separate arrays.
0054 struct GbtsNodeParams final {
0055   /// Minimum accepted |cot(theta)|. The infinite defaults mean "do not cut on
0056   /// tau"; only the tau lookup table narrows them.
0057   float minTau{-std::numeric_limits<float>::infinity()};
0058   /// Maximum accepted |cot(theta)|. See @ref minTau.
0059   float maxTau{std::numeric_limits<float>::infinity()};
0060   /// Azimuthal angle in the xy plane.
0061   float phi{};
0062   /// Transverse distance from the beamline.
0063   float r{};
0064   /// Global z coordinate.
0065   float z{};
0066 };
0067 //! [gbts node params]
0068 
0069 //! [gbts node edge info]
0070 /// Per-node graph bookkeeping, written while the graph is built.
0071 ///
0072 /// The three fields are read together in the innermost doublet loop, so they
0073 /// sit in one record rather than in separate arrays.
0074 struct GbtsNodeEdgeInfo final {
0075   /// Index of the first incoming graph edge attached to the node.
0076   std::uint32_t firstEdge{};
0077   /// Total number of incoming graph edges attached to the node.
0078   std::uint16_t numEdges{};
0079   /// z0 histogram bitmask. Non-zero marks the node's outer neighbourhood as
0080   /// connected to the previously built graph.
0081   std::uint16_t isConnected{};
0082 };
0083 //! [gbts node edge info]
0084 
0085 //! [gbts eta bin info]
0086 /// Constant per-eta-bin data.
0087 struct GbtsEtaBinInfo final {
0088   /// Range of node indices belonging to this bin.
0089   SpacePointIndexRange nodes{0, 0};
0090 
0091   /// (phi, node index) pairs covering this bin, with duplicated entries shifted
0092   /// by +-2pi at the wrap-around so the phi sliding window never has to wrap.
0093   std::vector<std::pair<float, SpacePointIndex>> phiNodes;
0094 
0095   float minRadius{};
0096   float maxRadius{};
0097   std::uint32_t layerId{0};
0098 
0099   /// Type of the layer this bin belongs to.
0100   GbtsLayerType type{};
0101   /// Technology of the layer this bin belongs to.
0102   GbtsLayerTechnology technology{};
0103 
0104   /// Check if bin is empty
0105   /// @return True if bin has no nodes
0106   bool empty() const { return nodes.first == nodes.second; }
0107 };
0108 //! [gbts eta bin info]
0109 
0110 class GbtsNodeProxy;
0111 
0112 /// What a node's entry in `GbtsNodeView::stripIndex` holds when it carries no
0113 /// stereo pair, i.e. when it is a pixel node.
0114 constexpr std::uint32_t kNoStrip = std::numeric_limits<std::uint32_t>::max();
0115 
0116 /// Read-only view of the node attributes needed outside the graph builder.
0117 ///
0118 /// Positions are packed as (x, y, z, r) because every consumer reads them
0119 /// together. Index it to get a GbtsNodeProxy with named accessors.
0120 struct GbtsNodeView final {
0121   /// Packed (x, y, z, r) per node.
0122   std::span<const std::array<float, 4>> positions;
0123   /// Dense layer index per node.
0124   std::span<const std::uint16_t> layers;
0125   /// Stereo pairs of the strip nodes, reached through `stripIndex`.
0126   std::span<const OuterStripSpacePointCalibrationDetailsDerived> strips;
0127   /// Index into `strips` per node, `kNoStrip` where a node carries none.
0128   /// Empty when nothing does.
0129   std::span<const std::uint32_t> stripIndex;
0130 
0131   /// Handle on a single node.
0132   /// @param index Index of the node
0133   /// @return Proxy for the node
0134   GbtsNodeProxy operator[](SpacePointIndex index) const;
0135 
0136   /// The stereo pair a node was formed from.
0137   /// @param index Index of the node
0138   /// @return The pair, or null for a pixel node
0139   const OuterStripSpacePointCalibrationDetailsDerived* strip(
0140       SpacePointIndex index) const {
0141     if (stripIndex.empty() || stripIndex[index] == kNoStrip) {
0142       return nullptr;
0143     }
0144     return &strips[stripIndex[index]];
0145   }
0146 };
0147 
0148 /// Read-only handle on a single graph node.
0149 ///
0150 /// Cheap to copy and meant to be created at the point of use. The view it
0151 /// refers to has to outlive it.
0152 class GbtsNodeProxy final {
0153  public:
0154   /// @param view View of the node positions and layers
0155   /// @param index Index of the node
0156   GbtsNodeProxy(const GbtsNodeView& view, SpacePointIndex index)
0157       : m_view(&view), m_index(index) {}
0158 
0159   /// @return Index of the node
0160   SpacePointIndex index() const { return m_index; }
0161   /// @return Global x coordinate
0162   float x() const { return position()[0]; }
0163   /// @return Global y coordinate
0164   float y() const { return position()[1]; }
0165   /// @return Global z coordinate
0166   float z() const { return position()[2]; }
0167   /// @return Transverse distance from the beamline
0168   float r() const { return position()[3]; }
0169   /// @return Dense layer index
0170   std::uint16_t layer() const { return m_view->layers[m_index]; }
0171 
0172  private:
0173   const std::array<float, 4>& position() const {
0174     return m_view->positions[m_index];
0175   }
0176 
0177   const GbtsNodeView* m_view{};
0178   SpacePointIndex m_index{kSpacePointIndexInvalid};
0179 };
0180 
0181 inline GbtsNodeProxy GbtsNodeView::operator[](SpacePointIndex index) const {
0182   return GbtsNodeProxy(*this, index);
0183 }
0184 
0185 //! [gbts edge]
0186 /// Edge between two GBTS nodes with fit parameters.
0187 struct GbtsEdge final {
0188   GbtsEdge() = default;
0189 
0190   /// Constructor
0191   /// @param n1_ Inner node index
0192   /// @param n2_ Outer node index
0193   /// @param n2LayerId_ GBTS layer ID of the outer node
0194   /// @param n2PixelBarrel_ Whether the outer node is on a pixel barrel layer
0195   /// @param p1_ First fit parameter
0196   /// @param p2_ Second fit parameter
0197   /// @param p3_ Third fit parameter
0198   GbtsEdge(SpacePointIndex n1_, SpacePointIndex n2_, std::uint32_t n2LayerId_,
0199            bool n2PixelBarrel_, float p1_, float p2_, float p3_)
0200       : n1{n1_},
0201         n2{n2_},
0202         level{1},
0203         next{1},
0204         n2PixelBarrel{n2PixelBarrel_},
0205         p{p1_, p2_, p3_},
0206         n2LayerId{n2LayerId_} {}
0207 
0208   /// Inner node of the edge
0209   SpacePointIndex n1{kSpacePointIndexInvalid};
0210   /// Outer node of the edge
0211   SpacePointIndex n2{kSpacePointIndexInvalid};
0212 
0213   std::int8_t level{-1};
0214   std::int8_t next{-1};
0215 
0216   std::uint8_t nNei{0};
0217 
0218   /// Whether the outer node is on a pixel barrel layer, the only thing the
0219   /// innermost neighbour loop asks about it. Cached so that loop does not have
0220   /// to chase the node's bin, and in what was padding so the edge does not
0221   /// grow.
0222   bool n2PixelBarrel{};
0223 
0224   std::array<float, 3> p{};
0225 
0226   /// GBTS layer ID of the outer node. Cached next to the fit parameters so the
0227   /// innermost neighbour loop does not have to chase the node.
0228   std::uint32_t n2LayerId{0};
0229 
0230   std::array<std::uint32_t, kGbtsMaxEdgeNeighbours> vNei{};
0231 };
0232 //! [gbts edge]
0233 
0234 }  // namespace Acts::Experimental::detail