ATLAS Offline Software
Loading...
Searching...
No Matches
TrigL2LayerNumberToolITk.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10
13
14#include <fstream>
15#include <stdexcept>
16
18 const std::string& n,
19 const IInterface* p ) :
20 AthAlgTool(t,n,p) {
21
22 declareInterface< ITrigL2LayerNumberTool >( this );
23}
24
26
27 ATH_CHECK( detStore()->retrieve(m_pixelId, "PixelID") );
28 ATH_CHECK( detStore()->retrieve(m_sctId, "SCT_ID") );
29 ATH_CHECK( detStore()->retrieve(m_pixelManager, "ITkPixel") );
30 ATH_CHECK( detStore()->retrieve(m_sctManager, "ITkStrip") );
31
32 //calculate the numbers
33
34 if(!m_useNewScheme) {
35
36 const InDetDD::SiNumerology& pixSiNum = m_pixelManager->numerology();
37 const InDetDD::SiNumerology& sctSiNum = m_sctManager->numerology();
38
39 m_MaxSiliconLayerNum = pixSiNum.numLayers()+pixSiNum.numDisks()+sctSiNum.numLayers()+sctSiNum.numDisks();
40 m_OffsetBarrelSCT = pixSiNum.numLayers();
41 m_OffsetEndcapPixels = pixSiNum.numLayers()+sctSiNum.numLayers();
43 m_OffsetEndcapSCT = pixSiNum.numLayers()+sctSiNum.numLayers()+pixSiNum.numDisks();
44 }
45 else {
47
48 ATH_MSG_INFO("Total number of unique silicon layers = "<<m_hashMap.size());
49
50 m_MaxSiliconLayerNum = static_cast<int>(m_hashMap.size());
52 }
53
54 report();
55
56 return StatusCode::SUCCESS;
57}
58
60
61 ATH_MSG_INFO("TrigL2 Layer numbering scheme:");
62 ATH_MSG_INFO("Total number of layers = "<<maxSiliconLayerNum());
63 ATH_MSG_INFO("OffsetEndcapPixels = "<<offsetEndcapPixels());
64 ATH_MSG_INFO("OffsetBarrelSCT = "<<offsetBarrelSCT());
65 ATH_MSG_INFO("OffsetEndcapSCT = "<<offsetEndcapSCT());
66}
67
68
69void TrigL2LayerNumberToolITk::createModuleHashMap(std::map<std::tuple<int, int, short, short>,std::vector<PhiEtaHashITk> >& hashMap) {
70
71
72 //helper function
73
74
75 short subdetid = 1;
76
77 for(int hash = 0; hash<static_cast<int>(m_pixelId->wafer_hash_max()); hash++) {
78
79 Identifier offlineId = m_pixelId->wafer_id(hash);
80
81 if(offlineId==0) continue;
82
83 short barrel_ec = m_pixelId->barrel_ec(offlineId);
84 if(std::abs(barrel_ec)>2) continue;//no DBM needed
85
86 short phi_index = m_pixelId->phi_module(offlineId);
87 short eta_index = m_pixelId->eta_module(offlineId);
88 int lay_id = m_pixelId->layer_disk(offlineId);
89 int eta_mod = m_pixelId->eta_module(offlineId);
90
91 int vol_id = -1;
92 if(barrel_ec== 0) vol_id = 8;
93 if(barrel_ec==-2) vol_id = 7;
94 if(barrel_ec== 2) vol_id = 9;
95
96 int new_vol=0, new_lay=0;
97
98 if(vol_id == 7 || vol_id == 9) {
99 new_vol = 10*vol_id + lay_id;
100 new_lay = eta_mod;
101 }
102 else if(vol_id == 8) {
103 new_lay = 0;
104 new_vol = 10*vol_id + lay_id;
105 }
106
107 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, new_vol, new_lay);
108
109 std::map<std::tuple<int, int, short, short>,std::vector<PhiEtaHashITk> >::iterator it = hashMap.find(t);
110 if(it==hashMap.end())
111 hashMap.insert(std::pair<std::tuple<int, int, short, short>,std::vector<PhiEtaHashITk> >(t,std::vector<PhiEtaHashITk>(1, PhiEtaHashITk(phi_index, eta_index, hash) )));
112 else (*it).second.push_back(PhiEtaHashITk(phi_index, eta_index, hash));
113 }
114
115 subdetid = 2;
116
117 for(int hash = 0; hash<static_cast<int>(m_sctId->wafer_hash_max()); hash++) {
118
119 Identifier offlineId = m_sctId->wafer_id(hash);
120
121 if(offlineId==0) continue;
122
123 short barrel_ec = m_sctId->barrel_ec(offlineId);
124 short phi_index = m_sctId->phi_module(offlineId);
125 short eta_index = m_sctId->eta_module(offlineId);
126
127 int vol_id = 13;
128
129 if(barrel_ec) vol_id = 12;
130 if(barrel_ec>0) vol_id = 14;
131
132 int lay_id = m_sctId->layer_disk(offlineId);
133
134 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, vol_id, lay_id);
135
136 std::map<std::tuple<int, int, short, short>,std::vector<PhiEtaHashITk> >::iterator it = hashMap.find(t);
137 if(it==hashMap.end())
138 hashMap.insert(std::pair<std::tuple<int, int, short, short>,std::vector<PhiEtaHashITk> >(t,std::vector<PhiEtaHashITk>(1, PhiEtaHashITk(phi_index, eta_index, hash))));
139 else (*it).second.push_back(PhiEtaHashITk(phi_index, eta_index, hash));
140 }
141
142 m_pixelLayers.clear();
143 m_sctLayers.clear();
144
145 m_pixelLayers.resize(m_pixelId->wafer_hash_max(), -100);
146 m_sctLayers.resize(m_sctId->wafer_hash_max(), -100);
147 m_layerGeometry.resize(hashMap.size());
148
149 int layerId=0;
150
152
153 std::ofstream geometryStream;
154 if(m_dumpGeometry){
155 geometryStream.open(m_geometryDumpDir);
156 }
157
158 for(std::map<std::tuple<int, int, short, short>,std::vector<PhiEtaHashITk> >::iterator it = hashMap.begin();it!=hashMap.end();++it, layerId++) {
159
160 short vol_id = std::get<2>((*it).first);
161 short lay_id = std::get<3>((*it).first);
162 int combinedId = static_cast<int>(vol_id)*1000 + lay_id;
163
164 short subdetId = std::get<1>((*it).first);
165 short barrel_ec = std::get<0>((*it).first);
166
167 if(barrel_ec == -100) barrel_ec = 0;
168
169 if(barrel_ec == 0) m_LastBarrelLayer++;
170
171 m_layerGeometry[layerId].m_type = barrel_ec;
172
173 m_layerGeometry[layerId].m_subdet = combinedId;
174
175 //m_layerGeometry[layerId].m_subdet = subdetId;
176
177 float rc=0.0;
178 int nModules = 0;
179 double minZ = 100000.0;
180 double maxZ = -100000.0;
181 double minR = 100000.0;
182 double maxR = -100000.0;
183
184 for(std::vector<PhiEtaHashITk>::iterator hIt = (*it).second.begin();hIt != (*it).second.end();++hIt) {
185
186 const InDetDD::SiDetectorElement *p = nullptr;
187
188 if(subdetId == 1) {//pixel
189 m_pixelLayers[(*hIt).m_hash] = layerId;
190 p = m_pixelManager->getDetectorElement((*hIt).m_hash);
191 }
192 if(subdetId == 2) {//SCT
193 m_sctLayers[(*hIt).m_hash] = layerId;
194 p = m_sctManager->getDetectorElement((*hIt).m_hash);
195 }
196 if (!p)[[unlikely]]{
197 ATH_MSG_WARNING("SiDetectorElement pointer is null.");
198 continue;
199 }
200 const Amg::Vector3D& C = p->center();
201
202 // find min and max r and z values of the layers
203 minZ = std::min(minZ, p->zMin());
204 maxZ = std::max(maxZ, p->zMax());
205 minR = std::min(minR, p->rMin());
206 maxR = std::max(maxR, p->rMax());
207
208 // find average average position of layer in coordinnate that is constant
209 if(barrel_ec == 0) {
210 rc += sqrt(C(0)*C(0)+C(1)*C(1));
211
212 }
213 else {
214 rc += C(2);
215
216 }
217 nModules++;
218 }
219 if (nModules == 0)[[unlikely]]{
220 throw std::runtime_error("TrigL2LayerNumberToolITk::createModuleHashMap: nModules is zero.");
221 }
222 m_layerGeometry[layerId].m_refCoord = rc/nModules;
223 // r or z max/man are added depending on if layer is
224 // barrel or endcap
225 if(barrel_ec == 0){
226 m_layerGeometry[layerId].m_minBound = minZ;
227 m_layerGeometry[layerId].m_maxBound = maxZ;
228 }
229 else{
230 m_layerGeometry[layerId].m_minBound = minR;
231 m_layerGeometry[layerId].m_maxBound = maxR;
232 }
233
234 // dump detailed layer information if requested
235 if(m_dumpGeometry){
236
237 // outputs like, minR, maxR, minZ, maxZ, gbts Id
238 geometryStream << minR << " "
239 << maxR << " "
240 << minZ << " "
241 << maxZ << " "
242 << combinedId << "\n";
243 }
244 }
245
246 ATH_MSG_DEBUG("List of unique layers in Pixel and SCT :");
247 for(int l=0;l<layerId;l++) {
248 ATH_MSG_DEBUG("Layer "<<l<<" ("<<m_layerGeometry[l].m_subdet<<") : reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<" "<<m_layerGeometry[l].m_maxBound<<" type="<<m_layerGeometry[l].m_type);
249 }
250}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
static Double_t rc
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
Class to hold geometrical description of a silicon detector element.
Class to extract numerology for Pixel and SCT.
int numLayers() const
Number of layers.
int numDisks() const
Number of disks.
const InDetDD::PixelDetectorManager * m_pixelManager
Gaudi::Property< bool > m_useNewScheme
TrigL2LayerNumberToolITk(const std::string &, const std::string &, const IInterface *)
Gaudi::Property< bool > m_dumpGeometry
Gaudi::Property< std::string > m_geometryDumpDir
virtual int offsetEndcapSCT() const override
void createModuleHashMap(std::map< std::tuple< int, int, short, short >, std::vector< PhiEtaHashITk > > &)
virtual StatusCode initialize() override
const InDetDD::SCT_DetectorManager * m_sctManager
virtual int offsetBarrelSCT() const override
std::vector< TrigInDetSiLayer > m_layerGeometry
virtual void report() const override
virtual int offsetEndcapPixels() const override
virtual int maxSiliconLayerNum() const override
std::map< std::tuple< int, int, short, short >, std::vector< PhiEtaHashITk > > m_hashMap
struct color C
Eigen::Matrix< double, 3, 1 > Vector3D
#define unlikely(x)