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