ATLAS Offline Software
Loading...
Searching...
No Matches
Gbts2ActsSeedingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
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
34StatusCode Gbts2ActsSeedingTool::createSeeds(const EventContext& ctx, const Acts::SpacePointContainer<ActsTrk::SpacePointCollector, Acts::detail::RefHolder>& spContainer, const Acts::Vector3&, const Acts::Vector3&, ActsTrk::SeedContainer& seedContainer) const {
35
36 seedContainer.spacePoints().reserve(spContainer.size());
37 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*m_geo, m_mlLUT);
38
40
41 const Amg::Vector3D &vertex = beamSpotHandle->beamPos();
42
43 float shift_x = vertex.x() - beamSpotHandle->beamTilt(0)*vertex.z();
44 float shift_y = vertex.y() - beamSpotHandle->beamTilt(1)*vertex.z();
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 for(size_t idx=0; idx<spContainer.size(); idx++){
55 const auto & sp = spContainer.at(idx);
56 const auto & extSP = sp.externalSpacePoint();
57 seedContainer.spacePoints().push_back(&extSP);
58 const std::vector<xAOD::DetectorIDHashType>& elementlist = extSP.elementIdList() ;
59
60 bool isPixel(elementlist.size() == 1);
61
62 short layer = (isPixel ? m_pix_h2l : m_sct_h2l)->at(static_cast<int>(elementlist[0]));
63
64 //convert incoming xaod spacepoints into GNN nodes
65
66 GNN_Node& node = node_storage[layer].emplace_back(layer);
67
68 const auto& pos = extSP.globalPosition();
69
70 node.m_x = pos.x() - shift_x;
71 node.m_y = pos.y() - shift_y;
72 node.m_z = pos.z();
73 node.m_r = std::sqrt(std::pow(node.m_x, 2) + std::pow(node.m_y, 2));
74 node.m_phi = std::atan2(node.m_y, node.m_x);
75 node.m_idx = idx;
76
77 if(isPixel && m_useML){
78 //Check type in debug build otherwise assume it is correct
79 assert(dynamic_cast<const xAOD::PixelCluster*>(extSP.measurements().front())!=nullptr);
80 const xAOD::PixelCluster* pCL = static_cast<const xAOD::PixelCluster*>(extSP.measurements().front());
81 node.m_pcw = pCL->widthInEta();
82 node.m_locPosY = pCL->localPosition<2>().y();
83 }
84 }
85
86 for(size_t l = 0; l < node_storage.size(); l++) {
87
88 const std::vector<GNN_Node>& nodes = node_storage[l];
89
90 if(nodes.size() == 0) continue;
91
92 if(m_are_pixels[l])
93 nPixelLoaded += storage->loadPixelGraphNodes(l, nodes, m_useML);
94 else
95 nStripLoaded += storage->loadStripGraphNodes(l, nodes);
96 }
97
98 ATH_MSG_DEBUG("Loaded "<<nPixelLoaded<<" pixel spacepoints and "<<nStripLoaded<<" strip spacepoints");
99
100 storage->sortByPhi();
101
102 storage->initializeNodes(m_useML);
103
104 storage->generatePhiIndexing(1.5f*m_phiSliceWidth);
105
106 std::vector<GNN_Edge> edgeStorage;
107
108 const TrigRoiDescriptor fakeRoi = TrigRoiDescriptor(0, -4.5, 4.5, 0, -M_PI, M_PI, 0, -150.0, 150.0);
109
110 std::pair<int, int> graphStats = buildTheGraph(fakeRoi, storage, edgeStorage);
111
112 ATH_MSG_DEBUG("Created graph with "<<graphStats.first<<" edges and "<<graphStats.second<< " edge links");
113
114 if (graphStats.first == 0 || graphStats.second == 0) return StatusCode::SUCCESS;
115
116 int maxLevel = runCCA(graphStats.first, edgeStorage);
117
118 ATH_MSG_DEBUG("Reached Level "<<maxLevel<<" after GNN iterations");
119
120 std::vector<std::tuple<float, int, std::vector<unsigned int> > > vSeedCandidates;
121
122 extractSeedsFromTheGraph(maxLevel, graphStats.first, spContainer.size(), edgeStorage, vSeedCandidates);
123
124 if (vSeedCandidates.empty()) return StatusCode::SUCCESS;
125
126 seedContainer.reserve(vSeedCandidates.size(), 7.0f); // 7 SP/seed to optimise allocations (average is 6.1 SP/seed)
127
128 for (const auto& seed : vSeedCandidates) {
129
130 if (std::get<1>(seed) != 0) continue;//identified as a clone of a better candidate
131
132 //add seed to output
133
134 auto newseed = seedContainer.push_back(std::get<2>(seed));
135 newseed.quality() = std::get<0>(seed);
136
137 }
138
139 ATH_MSG_DEBUG("GBTS created "<<seedContainer.size()<<" seeds");
140
141 return StatusCode::SUCCESS;
142}
143
#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
const std::vector< short > * m_pix_h2l
virtual StatusCode finalize() override
Gbts2ActsSeedingTool(const std::string &, const std::string &, const IInterface *)
virtual StatusCode createSeeds(const EventContext &ctx, const Acts::SpacePointContainer< ActsTrk::SpacePointCollector, Acts::detail::RefHolder > &spContainer, const Acts::Vector3 &beamSpotPos, const Acts::Vector3 &bField, ActsTrk::SeedContainer &seedContainer) const override
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
const std::vector< short > * m_sct_h2l
virtual StatusCode initialize() override
std::vector< bool > m_are_pixels
int runCCA(int, std::vector< GNN_Edge > &) const
ToolHandle< ITrigL2LayerNumberTool > m_layerNumberTool
std::vector< std::array< float, 5 > > m_mlLUT
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)
void extractSeedsFromTheGraph(int, int, int, std::vector< GNN_Edge > &, std::vector< std::tuple< float, int, std::vector< unsigned int > > > &) const
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.
Eigen::Matrix< double, 3, 1 > Vector3D
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
Acts::MutableSeedProxy2 push_back(Acts::SpacePointIndexSubset2 sp)
const SpacePointContainer & spacePoints() const noexcept