ATLAS Offline Software
Loading...
Searching...
No Matches
GNNR3_Geometry.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
6#include "GNNR3_Geometry.h"
7
8#include<cmath>
9#include<cstring>
10#include<algorithm>
11#include <iostream>
12
14
15 if(m_layer.m_type == 0) {//barrel
16 m_r1 = m_layer.m_refCoord;
17 m_r2 = m_layer.m_refCoord;
18 m_z1 = m_layer.m_minBound;
19 m_z2 = m_layer.m_maxBound;
20 }
21 else {//endcap
22 m_r1 = m_layer.m_minBound;
23 m_r2 = m_layer.m_maxBound;
24 m_z1 = m_layer.m_refCoord;
25 m_z2 = m_layer.m_refCoord;
26 }
27
28 float t1 = m_z1/m_r1;
29 float eta1 = -std::log(std::sqrt(1+t1*t1)-t1);
30
31
32 float t2 = m_z2/m_r2;
33 float eta2 = -std::log(std::sqrt(1+t2*t2)-t2);
34
35 m_minEta = eta1;
36 m_maxEta = eta2;
37
38 if(m_maxEta < m_minEta) {
39 m_minEta = eta2;
40 m_maxEta = eta1;
41 }
42
43 m_maxEta += 1e-6;//increasing them slightly to avoid range_check exceptions
44 m_minEta -= 1e-6;
45
46 float deltaEta = m_maxEta - m_minEta;
47
48 int binCounter = bin0;
49
50 if(deltaEta < m_etaBinWidth) {
51 m_nBins = 1;
52 m_bins.push_back(binCounter++);
53 m_etaBin = deltaEta;
54 if(m_layer.m_type == 0) {//barrel
55 m_minRadius.push_back(m_layer.m_refCoord - 2.0);
56 m_maxRadius.push_back(m_layer.m_refCoord + 2.0);
57 m_minBinCoord.push_back(m_layer.m_minBound);
58 m_maxBinCoord.push_back(m_layer.m_maxBound);
59 }
60 else {//endcap
61 m_minRadius.push_back(m_layer.m_minBound - 2.0);
62 m_maxRadius.push_back(m_layer.m_maxBound + 2.0);
63 m_minBinCoord.push_back(m_layer.m_minBound);
64 m_maxBinCoord.push_back(m_layer.m_maxBound);
65 }
66 }
67 else {
68 float nB = static_cast<int>(deltaEta/m_etaBinWidth);
69 m_nBins = nB;
70 if(deltaEta - m_etaBinWidth*nB > 0.5*m_etaBinWidth) m_nBins++;
71
72 m_etaBin = deltaEta/m_nBins;
73
74 if(m_nBins == 1) {
75 m_bins.push_back(binCounter++);
76 if(m_layer.m_type == 0) {//barrel
77 m_minRadius.push_back(m_layer.m_refCoord - 2.0);
78 m_maxRadius.push_back(m_layer.m_refCoord + 2.0);
79 m_minBinCoord.push_back(m_layer.m_minBound);
80 m_maxBinCoord.push_back(m_layer.m_maxBound);
81 }
82 else {//endcap
83 m_minRadius.push_back(m_layer.m_minBound - 2.0);
84 m_maxRadius.push_back(m_layer.m_maxBound + 2.0);
85 m_minBinCoord.push_back(m_layer.m_minBound);
86 m_maxBinCoord.push_back(m_layer.m_maxBound);
87 }
88 }
89 else {
90
91 float eta = m_minEta+0.5*m_etaBin;
92
93 for(int i=1;i<=m_nBins;i++) {
94
95 m_bins.push_back(binCounter++);
96
97 float e1 = eta - 0.5*m_etaBin;
98 float e2 = eta + 0.5*m_etaBin;
99
100 if(m_layer.m_type == 0) {//barrel
101 m_minRadius.push_back(m_layer.m_refCoord - 2.0);
102 m_maxRadius.push_back(m_layer.m_refCoord + 2.0);
103 float z1 = m_layer.m_refCoord*std::sinh(e1);
104 m_minBinCoord.push_back(z1);
105 float z2 = m_layer.m_refCoord*std::sinh(e2);
106 m_maxBinCoord.push_back(z2);
107 }
108 else {//endcap
109 float r = m_layer.m_refCoord/std::sinh(e1);
110 m_minBinCoord.push_back(r);
111 m_minRadius.push_back(r - 2.0);
112 r = m_layer.m_refCoord/std::sinh(e2);
113 m_maxBinCoord.push_back(r);
114 m_maxRadius.push_back(r + 2.0);
115
116 }
117
118 eta += m_etaBin;
119 }
120 }
121 }
122}
123
124bool TrigFTF_GNNR3_Layer::verifyBin(const TrigFTF_GNNR3_Layer* pL, int b1, int b2, float min_z0, float max_z0) const {
125
126 float z1min = m_minBinCoord.at(b1);
127 float z1max = m_maxBinCoord.at(b1);
128 float r1 = m_layer.m_refCoord;
129
130 if(m_layer.m_type == 0 && pL->m_layer.m_type == 0) {//barrel -> barrel
131
132 const float tol = 5.0;
133
134 float min_b2 = pL->m_minBinCoord.at(b2);
135 float max_b2 = pL->m_maxBinCoord.at(b2);
136
137 float r2 = pL->m_layer.m_refCoord;
138
139 float A = r2/(r2-r1);
140 float B = r1/(r2-r1);
141
142 float z0_min = z1min*A - max_b2*B;
143 float z0_max = z1max*A - min_b2*B;
144
145 if(z0_max < min_z0-tol || z0_min > max_z0+tol) return false;
146
147 return true;
148 }
149
150 if(m_layer.m_type == 0 && pL->m_layer.m_type != 0) {//barrel -> endcap
151
152 const float tol = 10.0;
153
154 float z2 = pL->m_layer.m_refCoord;
155 float r2max = pL->m_maxBinCoord.at(b2);
156 float r2min = pL->m_minBinCoord.at(b2);
157
158 if(r2max <= r1) return false;
159
160 if(r2min <= r1) {
161 r2min = r1 + 1e-3;
162 }
163
164 float z0_max = 0.0;
165 float z0_min = 0.0;
166
167 if(z2 > 0) {
168 z0_max = (z1max*r2max - z2*r1)/(r2max-r1);
169 z0_min = (z1min*r2min - z2*r1)/(r2min-r1);
170 }
171 else {
172 z0_max = (z1max*r2min - z2*r1)/(r2min-r1);
173 z0_min = (z1min*r2max - z2*r1)/(r2max-r1);
174 }
175
176 if(z0_max < min_z0-tol || z0_min > max_z0+tol) return false;
177 return true;
178 }
179
180 return true;
181}
182
183
184int TrigFTF_GNNR3_Layer::getEtaBin(float zh, float rh) const {
185
186 if(m_bins.size() == 1) return m_bins.at(0);
187
188 float t1 = zh/rh;
189 float eta = -std::log(std::sqrt(1+t1*t1)-t1);
190
191
192 int idx = static_cast<int>((eta-m_minEta)/m_etaBin);
193
194
195 if(idx < 0) idx = 0;
196 if(idx >= static_cast<int>(m_bins.size())) idx = static_cast<int>(m_bins.size())-1;
197
198 return m_bins.at(idx);//index in the global storage
199}
200
202 if(idx >= static_cast<int>(m_minRadius.size())) idx = idx-1;
203 if(idx < 0) idx = 0;
204
205 return m_minRadius.at(idx);
206}
207
209 if(idx >= static_cast<int>(m_maxRadius.size())) idx = idx-1;
210 if(idx < 0) idx = 0;
211
212 return m_maxRadius.at(idx);
213}
214
218
219TrigFTF_GNNR3_Geometry::TrigFTF_GNNR3_Geometry(const std::vector<TrigInDetSiLayer>& layers, const std::unique_ptr<GNNR3_FasTrackConnector>& conn) : m_nEtaBins(0) {
220
221 const float min_z0 = -168.0;
222 const float max_z0 = 168.0;
223
224 m_etaBinWidth = conn->m_etaBin;
225
226 for(const auto& layer : layers) {
227 const TrigFTF_GNNR3_Layer* pL = addNewLayer(layer, m_nEtaBins);
228 m_nEtaBins += pL->num_bins();
229 }
230
231 //calculating bin tables in the connector...
232 //calculate bin pairs for graph edge building
233
234 int lastBin1 = -1;
235
236 for(std::map<int, std::vector<GNNR3_FASTRACK_CONNECTION*> >::const_iterator it = conn->m_connMap.begin();it!=conn->m_connMap.end();++it) {
237
238 const std::vector<GNNR3_FASTRACK_CONNECTION*>& vConn = (*it).second;
239
240 for(std::vector<GNNR3_FASTRACK_CONNECTION*>::const_iterator cIt=vConn.begin();cIt!=vConn.end();++cIt) {
241
242 unsigned int src = (*cIt)->m_src;//n2 : the new connectors
243 unsigned int dst = (*cIt)->m_dst;//n1
244
245 const TrigFTF_GNNR3_Layer* pL1 = getTrigFTF_GNNR3_LayerByKey(dst);
246 const TrigFTF_GNNR3_Layer* pL2 = getTrigFTF_GNNR3_LayerByKey(src);
247
248 if (pL1==nullptr) {
249 std::cout << " skipping invalid dst layer " << dst << std::endl;
250 continue;
251 }
252 if (pL2==nullptr) {
253 std::cout << " skipping invalid src layer " << src << std::endl;
254 continue;
255 }
256 int nSrcBins = pL2->m_bins.size();
257 int nDstBins = pL1->m_bins.size();
258
259 (*cIt)->m_binTable.resize(nSrcBins*nDstBins, 0);
260
261 for(int b1=0;b1<nDstBins;b1++) {//loop over bins in Layer 1
262 for(int b2=0;b2<nSrcBins;b2++) {//loop over bins in Layer 2
263 if(!pL1->verifyBin(pL2, b1, b2, min_z0, max_z0)) continue;
264 int address = b1 + b2*nDstBins;
265 (*cIt)->m_binTable.at(address) = 1;
266
267 int bin1_idx = pL1->m_bins.at(b1);
268 int bin2_idx = pL2->m_bins.at(b2);
269
270 if(bin1_idx != lastBin1) {//adding a new group
271
272 std::vector<int> v2(1, bin2_idx);
273 m_binGroups.push_back(std::make_pair(bin1_idx, v2));
274 lastBin1 = bin1_idx;
275
276 }
277 else {//extend the last group
278 (*m_binGroups.rbegin()).second.push_back(bin2_idx);
279 }
280 }
281 }
282 }
283 }
284}
285
286
288 for(std::vector<TrigFTF_GNNR3_Layer*>::iterator it = m_layArray.begin();it!=m_layArray.end();++it) {
289 delete (*it);
290 }
291 m_layMap.clear();m_layArray.clear();
292}
293
295 std::map<unsigned int, TrigFTF_GNNR3_Layer*>::const_iterator it = m_layMap.find(key);
296 if(it == m_layMap.end()) {
297 return nullptr;
298 }
299 return (*it).second;
300}
301
305
306
307
309
310 unsigned int layerKey = l.m_subdet;
311
312 float ew = m_etaBinWidth;
313
314 TrigFTF_GNNR3_Layer* pHL = new TrigFTF_GNNR3_Layer(l, ew, bin0);
315
316 m_layMap.insert(std::pair<unsigned int, TrigFTF_GNNR3_Layer*>(layerKey, pHL));
317 m_layArray.push_back(pHL);
318 return pHL;
319}
Scalar eta() const
pseudorapidity method
TrigFTF_GNNR3_Geometry(const std::vector< TrigInDetSiLayer > &, const std::unique_ptr< GNNR3_FasTrackConnector > &)
const TrigFTF_GNNR3_Layer * getTrigFTF_GNNR3_LayerByIndex(int) const
const TrigFTF_GNNR3_Layer * addNewLayer(const TrigInDetSiLayer &, int)
std::map< unsigned int, TrigFTF_GNNR3_Layer * > m_layMap
std::vector< TrigFTF_GNNR3_Layer * > m_layArray
const TrigFTF_GNNR3_Layer * getTrigFTF_GNNR3_LayerByKey(unsigned int) const
bool verifyBin(const TrigFTF_GNNR3_Layer *, int, int, float, float) const
const TrigInDetSiLayer & m_layer
std::vector< float > m_maxRadius
TrigFTF_GNNR3_Layer(const TrigInDetSiLayer &, float, int)
std::vector< int > m_bins
std::vector< float > m_maxBinCoord
std::vector< float > m_minRadius
float getMaxBinRadius(int) const
float getMinBinRadius(int) const
int getEtaBin(float, float) const
std::vector< float > m_minBinCoord
int r
Definition globals.cxx:22
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
hold the test vectors and ease the comparison