Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:46:28

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 <array>
0012 #include <cstdint>
0013 #include <limits>
0014 #include <memory>
0015 #include <span>
0016 #include <vector>
0017 
0018 namespace Acts::Experimental {
0019 
0020 /// Number of segment connections
0021 constexpr std::uint32_t gbtsNumSegConns = 6;
0022 
0023 class GbtsGeometry;
0024 
0025 /// Machine learning lookup table for Gbts seeding
0026 using GbtsMlLookupTable = std::vector<std::array<float, 5>>;
0027 
0028 /// GBTS graph node storing space point properties.
0029 struct GbtsNode final {
0030  public:
0031   /// Constructor with layer index
0032   /// @param layer_ Layer index
0033   explicit GbtsNode(std::uint16_t layer_) : layer(layer_) {};
0034 
0035   /// Global x coordinate of the node
0036   float x{};
0037   /// Global y coordinate of the node
0038   float y{};
0039   /// Global z coordinate of the node
0040   float z{};
0041   /// Transverse distance from the beamline
0042   float r{};
0043   /// Azimuthal angle in the xy plane
0044   float phi{};
0045   /// Layer index
0046   std::uint16_t layer{};
0047   /// Index of the node in the original collection
0048   std::uint32_t idx{std::numeric_limits<std::uint32_t>::max()};
0049   /// Pixel cluster width
0050   float pcw{};
0051   /// Local y cluster position
0052   float locPosY{};
0053 };
0054 
0055 /// Eta-bin container for GBTS nodes and edge data.
0056 struct GbtsEtaBin final {
0057   GbtsEtaBin();
0058 
0059   /// Sort nodes by phi
0060   void sortByPhi();
0061   /// Initialize node attributes
0062   void initializeNodes();
0063   /// Check if bin is empty
0064   /// @return True if bin has no nodes
0065   bool empty() const { return vn.empty(); }
0066 
0067   /// Generate phi indexing
0068   /// @param dphi Phi bin width
0069   void generatePhiIndexing(float dphi);
0070 
0071   /// nodes of the graph
0072   std::vector<const GbtsNode*> vn;
0073   /// Phi-indexed nodes
0074   std::vector<std::pair<float, std::uint32_t>> vPhiNodes;
0075   /// node attributes: minCutOnTau, maxCutOnTau, phi, r, z;
0076   std::vector<std::array<float, 5>> params;
0077   /// the index of the first incoming graph edge attached to the node
0078   std::vector<std::uint32_t> vFirstEdge;
0079   /// the total number of incoming graph edges attached to this node
0080   std::vector<std::uint16_t> vNumEdges;
0081   /// flag to indicate the node's outer neighbourhood isolation from previously
0082   /// built graph
0083   std::vector<std::uint16_t> vIsConnected;
0084 
0085   /// Minimum radius in bin
0086   float minRadius{};
0087   /// Maximum radius in bin
0088   float maxRadius{};
0089 
0090   /// Layer ID for this bin
0091   std::uint32_t layerId{0};
0092 };
0093 
0094 /// Storage container for GBTS nodes
0095 class GbtsNodeStorage final {
0096  public:
0097   /// @param geometry Shared pointer to GBTS geometry
0098   /// @param mlLut Machine learning lookup table
0099   explicit GbtsNodeStorage(std::shared_ptr<const GbtsGeometry> geometry,
0100                            GbtsMlLookupTable mlLut);
0101 
0102   /// Load pixel graph nodes
0103   /// @param layerIndex Layer index for the nodes
0104   /// @param coll Collection of nodes to load
0105   /// @param useMl Use machine learning features
0106   /// @param maxEndcapClusterWidth Maximum cluster width for endcap nodes
0107   /// @return Number of nodes loaded
0108   std::uint32_t loadPixelGraphNodes(std::uint16_t layerIndex,
0109                                     const std::span<const GbtsNode> coll,
0110                                     bool useMl, float maxEndcapClusterWidth);
0111   /// Load strip graph nodes
0112   /// @param layerIndex Layer index for the nodes
0113   /// @param coll Collection of nodes to load
0114   /// @return Number of nodes loaded
0115   std::uint32_t loadStripGraphNodes(std::uint16_t layerIndex,
0116                                     const std::span<const GbtsNode> coll);
0117 
0118   /// Get the total number of nodes
0119   /// @return Total number of nodes
0120   std::uint32_t numberOfNodes() const;
0121   /// Sort nodes by phi
0122   void sortByPhi();
0123   /// Initialize node attributes
0124   /// @param useMl Use machine learning features
0125   void initializeNodes(bool useMl);
0126   /// Generate phi indexing
0127   /// @param dphi Phi bin width
0128   void generatePhiIndexing(float dphi);
0129 
0130   /// Get eta bin by index
0131   /// @param idx Eta bin index
0132   /// @return Reference to the eta bin
0133   GbtsEtaBin& getEtaBin(std::uint32_t idx) {
0134     if (idx >= m_etaBins.size()) {
0135       idx = idx - 1;
0136     }
0137     return m_etaBins.at(idx);
0138   }
0139 
0140  private:
0141   /// GBTS geometry
0142   std::shared_ptr<const GbtsGeometry> m_geometry;
0143 
0144   /// Machine learning lookup table
0145   GbtsMlLookupTable m_mlLut;
0146 
0147   /// Eta bins for node storage
0148   std::vector<GbtsEtaBin> m_etaBins;
0149 };
0150 
0151 /// Edge between two GBTS nodes with fit parameters.
0152 struct GbtsEdge final {
0153   GbtsEdge() = default;
0154 
0155   /// Constructor
0156   /// @param n1_ First node
0157   /// @param n2_ Second node
0158   /// @param p1_ First fit parameter
0159   /// @param p2_ Second fit parameter
0160   /// @param p3_ Third fit parameter
0161   GbtsEdge(const GbtsNode* n1_, const GbtsNode* n2_, float p1_, float p2_,
0162            float p3_)
0163       : n1{n1_}, n2{n2_}, level{1}, next{1}, p{p1_, p2_, p3_} {}
0164 
0165   /// First node of the edge
0166   const GbtsNode* n1{nullptr};
0167   /// Second node of the edge
0168   const GbtsNode* n2{nullptr};
0169 
0170   /// Level in the graph hierarchy
0171   std::int8_t level{-1};
0172   /// Index of next edge
0173   std::int8_t next{-1};
0174 
0175   /// Number of neighbor edges
0176   std::uint8_t nNei{0};
0177   /// Fit parameters
0178   std::array<float, 3> p{};
0179 
0180   /// Global indices of the connected edges
0181   std::array<std::uint32_t, gbtsNumSegConns> vNei{};
0182 };
0183 
0184 }  // namespace Acts::Experimental