ATLAS Offline Software
GNN_DataStorage.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
10 #include "GNN_Geometry.h"
11 #include "GNN_DataStorage.h"
12 
13 #include<cmath>
14 #include<cstring>
15 #include<algorithm>
16 
17 TrigFTF_GNN_EtaBin::TrigFTF_GNN_EtaBin() : m_minRadius(0), m_maxRadius(0) {
18 
19  m_in.clear();
20  m_vn.clear();
21  m_params.clear();
22  m_vn.reserve(1000);
23 }
24 
26  m_in.clear();
27  m_vn.clear();
28  m_params.clear();
29 }
30 
32 
33  std::vector<std::pair<float, const TrigFTF_GNN_Node*> > phiBuckets[32];
34 
35  int nBuckets = 31;
36 
37  for(const auto& n : m_vn) {
38 
39  int bIdx = (int)(0.5*nBuckets*(n->phi()/(float)M_PI + 1.0f));
40  phiBuckets[bIdx].push_back(std::make_pair(n->phi(), n));
41  }
42 
43  for(auto& b : phiBuckets) {
44  std::sort(b.begin(), b.end());
45  }
46 
47  int idx = 0;
48  for(const auto& b : phiBuckets) {
49  for(const auto& p : b) {
50  m_vn[idx++] = p.second;
51  }
52  }
53 
54 }
55 
57 
58  if(m_vn.empty()) return;
59 
60  m_params.resize(m_vn.size());
61 
62  m_in.resize(m_vn.size());
63 
64  for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
65  m_in[nIdx].reserve(50);//reasonably high number of incoming edges per node
66  m_params[nIdx][0] = -100.0;//default cut on cot(theta)
67  m_params[nIdx][1] = 100.0; //default cut on cot(theta)
68  const TrigFTF_GNN_Node* pN = m_vn.at(nIdx);
69  m_params[nIdx][2] = pN->phi();
70  m_params[nIdx][3] = pN->r();
71  m_params[nIdx][4] = pN->z();
72  }
73 
74  auto [min_iter, max_iter] = std::minmax_element(m_vn.begin(), m_vn.end(),
75  [](const TrigFTF_GNN_Node* s, const TrigFTF_GNN_Node* s1) { return (s->r() < s1->r()); });
76  m_maxRadius = (*max_iter)->r();
77  m_minRadius = (*min_iter)->r();
78 }
79 
81 
82  for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
83 
84  float phi = m_params[nIdx][2];
85  if(phi <= M_PI-dphi) continue;
86  m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi - 2*M_PI, nIdx));
87 
88  }
89 
90  for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
91  float phi = m_params[nIdx][2];
92  m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi, nIdx));
93  }
94 
95  for(unsigned int nIdx=0;nIdx<m_vn.size();nIdx++) {
96 
97  float phi = m_params[nIdx][2];
98  if(phi >= -M_PI + dphi) break;
99  m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi + 2*M_PI, nIdx));
100  }
101 
102 }
103 
105  m_etaBins.resize(g.num_bins());
106 }
107 
109 
110 }
111 
112 int TrigFTF_GNN_DataStorage::loadPixelGraphNodes(short layerIndex, const std::vector<TrigFTF_GNN_Node>& coll, bool useML) {
113 
114  int nLoaded = 0;
115 
116  const TrigFTF_GNN_Layer* pL = m_geo.getTrigFTF_GNN_LayerByIndex(layerIndex);
117 
118  if(pL == nullptr) {
119  return -1;
120  }
121 
122  bool isBarrel = (pL->m_layer.m_type == 0);
123 
124  for(const auto& node : coll) {
125 
126  int binIndex = pL->getEtaBin(node.z(), node.r());
127 
128  if(binIndex == -1) {
129  continue;
130  }
131 
132  if(isBarrel) {
133  m_etaBins.at(binIndex).m_vn.push_back(&node);
134  }
135  else {
136  if (useML) {
137  const InDet::PixelCluster* pCL = dynamic_cast<const InDet::PixelCluster*>(node.sp()->clusterList().first);
138  float cluster_width = pCL->width().widthPhiRZ().y();
139  if(cluster_width > 0.2) continue;
140  }
141  m_etaBins.at(binIndex).m_vn.push_back(&node);
142  }
143 
144  nLoaded++;
145 
146  }
147 
148  return nLoaded;
149 }
150 
151 int TrigFTF_GNN_DataStorage::loadStripGraphNodes(short layerIndex, const std::vector<TrigFTF_GNN_Node>& coll) {
152 
153  int nLoaded = 0;
154 
155  const TrigFTF_GNN_Layer* pL = m_geo.getTrigFTF_GNN_LayerByIndex(layerIndex);
156 
157  if(pL == nullptr) {
158  return -1;
159  }
160 
161  for(const auto& node : coll) {
162 
163  int binIndex = pL->getEtaBin(node.z(), node.r());
164 
165  if(binIndex == -1) {
166  continue;
167  }
168 
169  m_etaBins.at(binIndex).m_vn.push_back(&node);
170  nLoaded++;
171  }
172 
173  return nLoaded;
174 }
175 
176 
178 
179  unsigned int n=0;
180 
181  for(const auto& b : m_etaBins) {
182  n += b.m_vn.size();
183  }
184  return n;
185 }
186 
188 
189  for(auto& b : m_etaBins) b.sortByPhi();
190 }
191 
193 
194  for(auto& b : m_etaBins) {
195  b.initializeNodes();
196  }
197 
198  if(!useML) return;
199 
200  unsigned int nL = m_geo.num_layers();
201 
202  for(unsigned int layerIdx=0;layerIdx<nL;layerIdx++) {
203 
205 
206  if(pL->m_layer.m_subdet < 20000) {//skip strips volumes: layers in range [1200X-1400X]
207  continue;
208  }
209 
210  bool isBarrel = (pL->m_layer.m_type == 0);
211 
212  if(!isBarrel) continue;
213 
214  int nBins = pL->m_bins.size();
215 
216  for(int b=0;b<nBins;b++) {//loop over eta-bins in Layer
217 
218  TrigFTF_GNN_EtaBin& B = m_etaBins.at(pL->m_bins.at(b));
219 
220  if(B.empty()) continue;
221 
222  for(unsigned int nIdx=0;nIdx<B.m_vn.size();nIdx++) {
223 
224  const Trk::SpacePoint* osp = B.m_vn[nIdx]->sp();
225  const InDet::PixelCluster* pCL = dynamic_cast<const InDet::PixelCluster*>(osp->clusterList().first);
226 
227  float cluster_width = pCL->width().widthPhiRZ().y();
228  //adjusting cuts using fitted boundaries of |cot(theta)| vs. cluster z-width distribution
229  float min_tau = 6.7*(cluster_width - 0.2);//linear fit
230  float max_tau = 1.6 + 0.15/(cluster_width + 0.2) + 6.1*(cluster_width - 0.2);//linear fit + correction for short clusters
231 
232  B.m_params[nIdx][0] = min_tau;
233  B.m_params[nIdx][1] = max_tau;
234 
235  }
236  }
237  }
238 }
239 
241  for(auto& b : m_etaBins) b.generatePhiIndexing(dphi);
242 }
243 
244 
245 
TrigFTF_GNN_EtaBin
Definition: GNN_DataStorage.h:42
Trk::SpacePoint::clusterList
const std::pair< const PrepRawData *, const PrepRawData * > & clusterList() const
return the pair of cluster pointers by reference
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:127
Trk::SpacePoint
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:35
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
TrigFTF_GNN_EtaBin::m_in
std::vector< std::vector< unsigned int > > m_in
Definition: GNN_DataStorage.h:74
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PixelCluster.h
TrigFTF_GNN_Geometry::num_layers
unsigned int num_layers() const
Definition: GNN_Geometry.h:59
TrigFTF_GNN_DataStorage::sortByPhi
void sortByPhi()
Definition: GNN_DataStorage.cxx:187
InDet::SiWidth::widthPhiRZ
const Amg::Vector2D & widthPhiRZ() const
Definition: SiWidth.h:121
TrigFTF_GNN_Node::phi
float phi() const
Definition: GNN_DataStorage.h:28
TrigFTF_GNN_EtaBin::TrigFTF_GNN_EtaBin
TrigFTF_GNN_EtaBin()
Definition: GNN_DataStorage.cxx:17
M_PI
#define M_PI
Definition: ActiveFraction.h:11
TrigFTF_GNN_Layer::m_bins
std::vector< int > m_bins
Definition: GNN_Geometry.h:31
TrigFTF_GNN_EtaBin::~TrigFTF_GNN_EtaBin
~TrigFTF_GNN_EtaBin()
Definition: GNN_DataStorage.cxx:25
TrigFTF_GNN_EtaBin::m_minRadius
float m_minRadius
Definition: GNN_DataStorage.h:77
TrigFTF_GNN_Node
Definition: GNN_DataStorage.h:21
TrigInDetSiLayer.h
SpacePointCollection.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
TrigFTF_GNN_DataStorage::m_etaBins
std::vector< TrigFTF_GNN_EtaBin > m_etaBins
Definition: GNN_DataStorage.h:104
TrigFTF_GNN_DataStorage::TrigFTF_GNN_DataStorage
TrigFTF_GNN_DataStorage(const TrigFTF_GNN_Geometry &)
Definition: GNN_DataStorage.cxx:104
TrigFTF_GNN_DataStorage::generatePhiIndexing
void generatePhiIndexing(float)
Definition: GNN_DataStorage.cxx:240
TrigFTF_GNN_EtaBin::m_vPhiNodes
std::vector< std::pair< float, unsigned int > > m_vPhiNodes
Definition: GNN_DataStorage.h:73
TrigFTF_GNN_EtaBin::initializeNodes
void initializeNodes()
Definition: GNN_DataStorage.cxx:56
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
SpacePoint.h
TrigFTF_GNN_Layer::m_layer
const TrigInDetSiLayer & m_layer
Definition: GNN_Geometry.h:30
TrigFTF_GNN_EtaBin::m_maxRadius
float m_maxRadius
Definition: GNN_DataStorage.h:77
TrigFTF_GNN_DataStorage::numberOfNodes
unsigned int numberOfNodes() const
Definition: GNN_DataStorage.cxx:177
IDPVM::binIndex
unsigned int binIndex(const T &val, const std::vector< T > &partitions)
general utility function to return bin index given a value and the upper endpoints of each bin
Definition: InDetPhysValMonitoringUtilities.h:43
TrigFTF_GNN_DataStorage::loadPixelGraphNodes
int loadPixelGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &, bool)
Definition: GNN_DataStorage.cxx:112
TrigInDetSiLayer::m_type
int m_type
Definition: TrigInDetSiLayer.h:11
TrigFTF_GNN_Geometry::getTrigFTF_GNN_LayerByIndex
const TrigFTF_GNN_Layer * getTrigFTF_GNN_LayerByIndex(int) const
Definition: GNN_Geometry.cxx:301
TrigFTF_GNN_DataStorage::initializeNodes
void initializeNodes(bool)
Definition: GNN_DataStorage.cxx:192
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
TrigFTF_GNN_Layer
Definition: GNN_Geometry.h:16
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
TrigFTF_GNN_EtaBin::generatePhiIndexing
void generatePhiIndexing(float)
Definition: GNN_DataStorage.cxx:80
dqt_zlumi_alleff_HIST.B
B
Definition: dqt_zlumi_alleff_HIST.py:110
TrigFTF_GNN_Geometry
Definition: GNN_Geometry.h:50
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
InDet::SiCluster::width
const InDet::SiWidth & width() const
return width class reference
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
TrigFTF_GNN_DataStorage::loadStripGraphNodes
int loadStripGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &)
Definition: GNN_DataStorage.cxx:151
TrigFTF_GNN_DataStorage::m_geo
const TrigFTF_GNN_Geometry & m_geo
Definition: GNN_DataStorage.h:102
TrigFTF_GNN_EtaBin::sortByPhi
void sortByPhi()
Definition: GNN_DataStorage.cxx:31
TrigFTF_GNN_Node::z
float z() const
Definition: GNN_DataStorage.h:29
GNN_DataStorage.h
TrigFTF_GNN_EtaBin::m_vn
std::vector< const TrigFTF_GNN_Node * > m_vn
Definition: GNN_DataStorage.h:72
TrigFTF_GNN_Layer::getEtaBin
int getEtaBin(float, float) const
Definition: GNN_Geometry.cxx:184
TrigFTF_GNN_DataStorage::~TrigFTF_GNN_DataStorage
~TrigFTF_GNN_DataStorage()
Definition: GNN_DataStorage.cxx:108
TrigFTF_GNN_Node::r
float r() const
Definition: GNN_DataStorage.h:30
node
Definition: memory_hooks-stdcmalloc.h:74
TrigInDetSiLayer::m_subdet
int m_subdet
Definition: TrigInDetSiLayer.h:10
TrigFTF_GNN_EtaBin::m_params
std::vector< std::array< float, 5 > > m_params
Definition: GNN_DataStorage.h:75
GNN_Geometry.h