Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-17 07:59:44

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