ATLAS Offline Software
Loading...
Searching...
No Matches
GNN_DataStorage.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8#include "GNN_DataStorage.h"
9
10#include<iostream>
11#include<cmath>
12#include<cstring>
13#include<algorithm>
14
16 m_vn.clear();
17 m_params.clear();
18 m_vn.reserve(1000);
19 m_vFirstEdge.reserve(1000);
20 m_vNumEdges.reserve(1000);
21}
22
27
29
30 std::vector<std::pair<float, const TrigFTF_GNN_Node*> > phiBuckets[32];
31
32 int nBuckets = 31;
33
34 for(const auto& n : m_vn) {
35 int bIdx = (int)(0.5*nBuckets*(n->phi()/(float)M_PI + 1.0f));
36 phiBuckets[bIdx].push_back(std::make_pair(n->phi(), n));
37 }
38
39 for(auto& b : phiBuckets) {
40 std::sort(b.begin(), b.end());
41 }
42
43 int idx = 0;
44 for(const auto& b : phiBuckets) {
45 for(const auto& p : b) {
46 m_vn[idx++] = p.second;
47 }
48 }
49
50}
51
52
54
55 if(m_vn.empty()) return;
56
57 m_params.resize(m_vn.size());
58 m_vFirstEdge.resize(m_vn.size(), 0);
59 m_vNumEdges.resize(m_vn.size(), 0);
60 m_vIsConnected.resize(m_vn.size(), 0);
61
62 std::transform(m_vn.begin(), m_vn.end(), m_params.begin(),
63 [](const TrigFTF_GNN_Node* pN) { std::array<float,5> a = {-100.0, 100.0, pN->phi(), pN->r(), pN->z()}; return a;});
64
65 auto [min_iter, max_iter] = std::minmax_element(m_vn.begin(), m_vn.end(),
66 [](const TrigFTF_GNN_Node* s, const TrigFTF_GNN_Node* s1) { return (s->r() < s1->r()); });
67 m_maxRadius = (*max_iter)->r();
68 m_minRadius = (*min_iter)->r();
69}
70
72
73 for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
74
75 float phi = m_params[nIdx][2];
76 if(phi <= M_PI-dphi) continue;
77 m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi - 2*M_PI, nIdx));
78
79 }
80
81 for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
82 float phi = m_params[nIdx][2];
83 m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi, nIdx));
84 }
85
86 for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
87
88 float phi = m_params[nIdx][2];
89 if(phi >= -M_PI + dphi) break;
90 m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi + 2*M_PI, nIdx));
91 }
92
93}
94
95TrigFTF_GNN_DataStorage::TrigFTF_GNN_DataStorage(const TrigFTF_GNN_Geometry& g, const std::vector<std::array<float, 5> >& lut) : m_geo(g), m_mlLUT(lut) {
96 m_etaBins.resize(g.num_bins());
97}
98
99
103
104int TrigFTF_GNN_DataStorage::loadPixelGraphNodes(short layerIndex, const std::vector<TrigFTF_GNN_Node>& coll, bool useML) {
105
106 int nLoaded = 0;
107
108 const TrigFTF_GNN_Layer* pL = m_geo.getTrigFTF_GNN_LayerByIndex(layerIndex);
109
110 if(pL == nullptr) {
111 return -1;
112 }
113
114 bool isBarrel = (pL->m_layer.m_type == 0);
115
116 for(const auto& node : coll) {
117
118 int binIndex = pL->getEtaBin(node.z(), node.r());
119
120 if(binIndex == -1) {
121 continue;
122 }
123
124 if(isBarrel) {
125 m_etaBins.at(binIndex).m_vn.push_back(&node);
126 }
127 else {
128 if (useML) {
129 float cluster_width = node.pixelClusterWidth();
130 if(cluster_width > 0.35) continue;
131 }
132 m_etaBins.at(binIndex).m_vn.push_back(&node);
133 }
134
135 nLoaded++;
136
137 }
138
139 return nLoaded;
140}
141
142int TrigFTF_GNN_DataStorage::loadStripGraphNodes(short layerIndex, const std::vector<TrigFTF_GNN_Node>& coll) {
143
144 int nLoaded = 0;
145
146 const TrigFTF_GNN_Layer* pL = m_geo.getTrigFTF_GNN_LayerByIndex(layerIndex);
147
148 if(pL == nullptr) {
149 return -1;
150 }
151
152 for(const auto& node : coll) {
153
154 int binIndex = pL->getEtaBin(node.z(), node.r());
155
156 if(binIndex == -1) {
157 continue;
158 }
159
160 m_etaBins.at(binIndex).m_vn.push_back(&node);
161 nLoaded++;
162 }
163
164 return nLoaded;
165}
166
168
169 unsigned int n=0;
170
171 for(const auto& b : m_etaBins) {
172 n += b.m_vn.size();
173 }
174 return n;
175}
176
178
179 for(auto& b : m_etaBins) b.sortByPhi();
180}
181
183
184 for(auto& b : m_etaBins) {
185 b.initializeNodes();
186 if(!b.m_vn.empty()) {
187 b.m_layerKey = m_geo.getTrigFTF_GNN_LayerKeyByIndex((*b.m_vn.begin())->m_layer);
188 }
189 }
190
191 if(!useML) return;
192
193 unsigned int nL = m_geo.num_layers();
194
195 for(unsigned int layerIdx=0;layerIdx<nL;layerIdx++) {
196
197 const TrigFTF_GNN_Layer* pL = m_geo.getTrigFTF_GNN_LayerByIndex(layerIdx);
198
199 if(pL->m_layer.m_subdet < 20000) {//skip strips volumes: layers in range [1200X-1400X]
200 continue;
201 }
202
203 bool isBarrel = (pL->m_layer.m_type == 0);//TO-DO: implement a separate id for inclined barrel layers
204
205 if(!isBarrel) continue;
206
207 // adjusting cuts on |cot(theta)| using pre-trained LUT loaded from a file
208
209 int lutSize = m_mlLUT.size();
210
211 int nBins = pL->m_bins.size();
212
213 for(int b=0;b<nBins;b++) {//loop over eta-bins in Layer
214
215 TrigFTF_GNN_EtaBin& B = m_etaBins.at(pL->m_bins.at(b));
216
217 if(B.empty()) continue;
218
219 for(unsigned int nIdx=0;nIdx<B.m_vn.size();nIdx++) {
220
221 float cluster_width = B.m_vn[nIdx]->pixelClusterWidth();
222
223 float locPosY = B.m_vn[nIdx]->localPositionY();
224
225 int lutBinIdx = std::floor(20*cluster_width) - 1;//lut bin width is 0.05 mm
226
227 if (lutBinIdx >= lutSize) continue;
228
229 const std::array<float, 5> lutBin = m_mlLUT[lutBinIdx];
230
231 float dist2border = 10.0 - std::abs(locPosY);
232
233 float min_tau = -100.0;
234 float max_tau = 100.0;
235
236 if (dist2border > 0.3f) {//far enough from the edge
237 min_tau = lutBin[1];
238 max_tau = lutBin[2];
239 } else {//possible cluster shortening at a module edge
240 min_tau = lutBin[3];
241 max_tau = lutBin[4];
242 }
243
244 if (max_tau < 0) {//insufficient training data
245 max_tau = 100.0;//use "no-cut" default
246 }
247
248 B.m_params[nIdx][0] = min_tau;
249 B.m_params[nIdx][1] = max_tau;
250
251 }
252 }
253 }
254}
255
257 for(auto& b : m_etaBins) b.generatePhiIndexing(dphi);
258}
259
#define M_PI
Scalar phi() const
phi method
static Double_t a
std::vector< TrigFTF_GNN_EtaBin > m_etaBins
unsigned int numberOfNodes() const
const TrigFTF_GNN_Geometry & m_geo
const std::vector< std::array< float, 5 > > & m_mlLUT
TrigFTF_GNN_DataStorage(const TrigFTF_GNN_Geometry &, const std::vector< std::array< float, 5 > > &)
int loadStripGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &)
int loadPixelGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &, bool)
std::vector< const TrigFTF_GNN_Node * > m_vn
std::vector< unsigned short > m_vIsConnected
std::vector< unsigned int > m_vFirstEdge
void generatePhiIndexing(float)
std::vector< std::pair< float, unsigned int > > m_vPhiNodes
std::vector< std::array< float, 5 > > m_params
std::vector< unsigned short > m_vNumEdges
const TrigInDetSiLayer & m_layer
int getEtaBin(float, float) const
std::vector< int > m_bins
Definition node.h:24
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.