ATLAS Offline Software
Loading...
Searching...
No Matches
GbtsFtfActsSeedingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10
11#include <optional>
12
14 const std::string& n,
15 const IInterface* p ) : SeedingToolBase(t,n,p)
16{
17}
18
21 ATH_CHECK(m_beamSpotKey.initialize());
22 m_sct_h2l = m_layerNumberTool->sctLayers();
23 m_pix_h2l = m_layerNumberTool->pixelLayers();
24 m_are_pixels.resize(m_layerNumberTool->maxNumberOfUniqueLayers(), true);
25 for(const auto& l : *m_sct_h2l) m_are_pixels[l] = false;
26
27 return StatusCode::SUCCESS;
28}
29
33
35 const EventContext& ctx,
36 const std::vector<const xAOD::SpacePointContainer*>&
37 spacePointCollections,
38 const Eigen::Vector3f& beamSpotPos, float bFieldInZ,
39 ActsTrk::SeedContainer& seedContainer) const {
40
41 (void)ctx;
42 (void)bFieldInZ;
43
44 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*m_geo, m_mlLUT);
45
46 std::vector<std::vector<GNN_Node> > node_storage;//layer-based collections
47 node_storage.resize(m_are_pixels.size());
48
49 for(auto& v : node_storage) v.reserve(100000);
50
51 unsigned int nPixelLoaded = 0;
52 unsigned int nStripLoaded = 0;
53
54 std::size_t totalSpacePoints = 0;
55 for (const xAOD::SpacePointContainer* spacePoints : spacePointCollections) {
56 totalSpacePoints += spacePoints->size();
57 }
58
59 std::vector<const xAOD::SpacePoint*> selectedXAODSpacePoints;
60 selectedXAODSpacePoints.reserve(totalSpacePoints);
61
62 for (const xAOD::SpacePointContainer* spacePoints : spacePointCollections) {
63 for (const xAOD::SpacePoint* sp : *spacePoints) {
64 const auto& pos = sp->globalPosition();
65 const std::vector<xAOD::DetectorIDHashType>& elementlist = sp->elementIdList();
66 const bool isPixel = (elementlist.size() == 1);
67 const short layer = (isPixel ? m_pix_h2l : m_sct_h2l)->at(static_cast<int>(elementlist[0]));
68
69 //convert incoming xaod spacepoints into GNN nodes
70
71 GNN_Node& node = node_storage[layer].emplace_back(layer);
72
73 node.m_x = pos.x() - beamSpotPos[0];
74 node.m_y = pos.y() - beamSpotPos[1];
75 node.m_z = pos.z();
76 node.m_r = std::sqrt(std::pow(node.m_x, 2) + std::pow(node.m_y, 2));
77 node.m_phi = std::atan2(node.m_y, node.m_x);
78 node.m_idx = selectedXAODSpacePoints.size();
79
80 if (isPixel && m_useML){
81 //Check type in debug build otherwise assume it is correct
82 assert(dynamic_cast<const xAOD::PixelCluster*>(sp->measurements().front())!=nullptr);
83 const xAOD::PixelCluster* pCL = static_cast<const xAOD::PixelCluster*>(sp->measurements().front());
84 node.m_pcw = pCL->widthInEta();
85 node.m_locPosY = pCL->localPosition<2>().y();
86 }
87
88 selectedXAODSpacePoints.push_back(sp);
89 }
90 }
91
92 for(size_t l = 0; l < node_storage.size(); l++) {
93
94 const std::vector<GNN_Node>& nodes = node_storage[l];
95
96 if(nodes.size() == 0) continue;
97
98 if(m_are_pixels[l])
99 nPixelLoaded += storage->loadPixelGraphNodes(l, nodes, m_useML);
100 else
101 nStripLoaded += storage->loadStripGraphNodes(l, nodes);
102 }
103
104 ATH_MSG_DEBUG("Loaded "<<nPixelLoaded<<" pixel spacepoints and "<<nStripLoaded<<" strip spacepoints");
105
106 storage->sortByPhi();
107
108 storage->initializeNodes(m_useML);
109
110 storage->generatePhiIndexing(1.5f*m_phiSliceWidth);
111
112 std::vector<GNN_Edge> edgeStorage;
113
114 const TrigRoiDescriptor fakeRoi = TrigRoiDescriptor(0, -4.5, 4.5, 0, -M_PI, M_PI, 0, -150.0, 150.0);
115
116 std::pair<int, int> graphStats = buildTheGraph(fakeRoi, storage, edgeStorage);
117
118 ATH_MSG_DEBUG("Created graph with "<<graphStats.first<<" edges and "<<graphStats.second<< " edge links");
119
120 if (graphStats.first == 0 || graphStats.second == 0) return StatusCode::SUCCESS;
121
122 int maxLevel = runCCA(graphStats.first, edgeStorage);
123
124 ATH_MSG_DEBUG("Reached Level "<<maxLevel<<" after GNN iterations");
125
126 std::vector<std::pair<float, std::vector<unsigned int> > > vOutputSeeds;
127
128 extractSeedsFromTheGraph(maxLevel, graphStats.first, totalSpacePoints, edgeStorage, vOutputSeeds);
129
130 if (vOutputSeeds.empty()) return StatusCode::SUCCESS;
131
132 seedContainer.reserve(vOutputSeeds.size(), 7.0f); // 7 SP/seed to optimise allocations (average is 6.1 SP/seed)
133
134 for (const auto& seed : vOutputSeeds) {
135 // convert space points and add seed to output
136 const float quality = seed.first;
137 const float vertexZ = 0.0f; // not used in GBTS seeding, set to 0
138 seedContainer.push_back(
139 seed.second,
140 [&](const unsigned int spIndex) {
141 return selectedXAODSpacePoints[spIndex];
142 },
143 quality, vertexZ);
144 }
145
146 ATH_MSG_DEBUG("GBTS created "<<seedContainer.size()<<" seeds");
147
148 return StatusCode::SUCCESS;
149}
150
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
static Double_t sp
Athena::TPCnvVers::Current TrigRoiDescriptor
#define y
virtual StatusCode finalize() override
virtual StatusCode initialize() override
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
GbtsFtfActsSeedingTool(const std::string &, const std::string &, const IInterface *)
std::vector< bool > m_are_pixels
const std::vector< short > * m_sct_h2l
const std::vector< short > * m_pix_h2l
virtual StatusCode createSeeds(const EventContext &ctx, const std::vector< const xAOD::SpacePointContainer * > &spacePointCollections, const Eigen::Vector3f &beamSpotPos, float bFieldInZ, ActsTrk::SeedContainer &seedContainer) const override
int runCCA(int, std::vector< GNN_Edge > &) const
ToolHandle< ITrigL2LayerNumberTool > m_layerNumberTool
std::vector< std::array< float, 5 > > m_mlLUT
void extractSeedsFromTheGraph(int, int, int, std::vector< GNN_Edge > &, std::vector< std::pair< float, std::vector< unsigned int > > > &) const
std::pair< int, int > buildTheGraph(const IRoiDescriptor &, const std::unique_ptr< GNN_DataStorage > &, std::vector< GNN_Edge > &) const
SeedingToolBase(const std::string &t, const std::string &n, const IInterface *p)
std::unique_ptr< const TrigFTF_GNN_Geometry > m_geo
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
Definition node.h:24
float widthInEta() const
Returns the width of the cluster in phi (x) and eta (y) directions, respectively.
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
SpacePointContainer_v1 SpacePointContainer
Define the version of the space point container.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
Seed push_back(SpacePointRange spacePoints, float quality, float vertexZ)
void reserve(std::size_t size, float averageSpacePoints=3) noexcept
std::size_t size() const noexcept