ATLAS Offline Software
Loading...
Searching...
No Matches
GBTSTrigL2LayerNumberTool.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#include <stdexcept>
14
16 const std::string& n,
17 const IInterface* p ): AthAlgTool(t,n,p),
18 m_useNewScheme(false),
23{
24 declareInterface< ITrigL2LayerNumberTool >( this );
25 declareProperty( "UseNewLayerScheme", m_useNewScheme = false );
26}
27
29
30 StatusCode sc = AthAlgTool::initialize();
31
32 ATH_MSG_DEBUG("In initialize...");
33
34 sc = detStore()->retrieve(m_pixelId, "PixelID");
35 if (sc.isFailure()) {
36 ATH_MSG_FATAL("Could not get Pixel ID helper");
37 return sc;
38 }
39
40 sc = detStore()->retrieve(m_sctId, "SCT_ID");
41 if (sc.isFailure()) {
42 ATH_MSG_FATAL("Could not get SCT ID helper");
43 return sc;
44 }
45
46 sc = detStore()->retrieve(m_pixelManager);
47 if( sc.isFailure() ) {
48 ATH_MSG_ERROR("Could not retrieve Pixel DetectorManager from detStore.");
49 return sc;
50 }
51
52 sc = detStore()->retrieve(m_sctManager);
53 if( sc.isFailure() ) {
54 ATH_MSG_ERROR("Could not retrieve SCT DetectorManager from detStore.");
55 return sc;
56 }
57
58 //calculate the numbers
59
60 if(!m_useNewScheme) {
61
62 const InDetDD::SiNumerology& pixSiNum = m_pixelManager->numerology();
63 const InDetDD::SiNumerology& sctSiNum = m_sctManager->numerology();
64
65 m_MaxSiliconLayerNum = pixSiNum.numLayers()+pixSiNum.numDisks()+sctSiNum.numLayers()+sctSiNum.numDisks();
66 m_OffsetBarrelSCT = pixSiNum.numLayers();
67 m_OffsetEndcapPixels = pixSiNum.numLayers()+sctSiNum.numLayers();
69 m_OffsetEndcapSCT = pixSiNum.numLayers()+sctSiNum.numLayers()+pixSiNum.numDisks();
70 }
71 else {
73
74 ATH_MSG_DEBUG("Total number of unique silicon layers = "<<m_hashMap.size());
75
76 m_MaxSiliconLayerNum = (int)m_hashMap.size();
78 }
79
80
81 ATH_MSG_DEBUG("GBTSTrigL2LayerNumberTool initialized ");
82
83 report();
84
85 return sc;
86}
87
89{
90 StatusCode sc = AthAlgTool::finalize();
91 return sc;
92}
93
95
96 ATH_MSG_DEBUG("TrigL2 Layer numbering scheme:");
97 ATH_MSG_DEBUG("Total number of layers = "<<maxSiliconLayerNum());
98 ATH_MSG_DEBUG("OffsetEndcapPixels = "<<offsetEndcapPixels());
99 ATH_MSG_DEBUG("OffsetBarrelSCT = "<<offsetBarrelSCT());
100 ATH_MSG_DEBUG("OffsetEndcapSCT = "<<offsetEndcapSCT());
101}
102
103void GBTSTrigL2LayerNumberTool::createModuleHashMap(std::map<std::tuple<int,int,short,short>,std::vector<GBTSPhiEtaHash> >& hashMap) {
104
105
106 short subdetid = 1;
107
108 for(int hash = 0; hash<static_cast<int>(m_pixelId->wafer_hash_max()); hash++) {
109
110 Identifier offlineId = m_pixelId->wafer_id(hash);
111
112 if(offlineId==0) continue;
113
114 short barrel_ec = m_pixelId->barrel_ec(offlineId);
115 if(std::abs(barrel_ec)>2) {std::cout << "barrel " << " " << hash << std::endl; continue;}//no DBM needed
116
117 short phi_index = m_pixelId->phi_module(offlineId);
118 short eta_index = m_pixelId->eta_module(offlineId);
119 int lay_id = m_pixelId->layer_disk(offlineId);
120 int eta_mod = m_pixelId->eta_module(offlineId);
121
122 int vol_id = -1;
123 if(barrel_ec== 0) vol_id = 8;
124 if(barrel_ec==-2) vol_id = 7;
125 if(barrel_ec== 2) vol_id = 9;
126
127 int new_vol=0, new_lay=0;
128
129 if(vol_id == 7 || vol_id == 9) {
130 new_vol = 10*vol_id + lay_id;
131 new_lay = eta_mod;
132 }
133 else if(vol_id == 8) {
134 new_lay = 0;
135 new_vol = 10*vol_id + lay_id;
136 }
137
138 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, new_vol, new_lay);
139
140 std::map<std::tuple<int, int, short, short>,std::vector<GBTSPhiEtaHash> >::iterator it = hashMap.find(t);
141 if(it==hashMap.end())
142 hashMap.insert(std::pair<std::tuple<int, int, short, short>,std::vector<GBTSPhiEtaHash> >(t,std::vector<GBTSPhiEtaHash>(1, GBTSPhiEtaHash(phi_index, eta_index, hash) )));
143 else (*it).second.push_back(GBTSPhiEtaHash(phi_index, eta_index, hash));
144 }
145
146 if (false) {
147 subdetid = 2; //SCT
148
149 for(int hash = 0; hash<static_cast<int>(m_sctId->wafer_hash_max()); hash++) {
150
151 Identifier offlineId = m_sctId->wafer_id(hash);
152
153 if(offlineId==0) continue;
154
155 short barrel_ec = m_sctId->barrel_ec(offlineId);
156 short phi_index = m_sctId->phi_module(offlineId);
157 short eta_index = m_sctId->eta_module(offlineId);
158
159 int vol_id = 13;
160
161 if(barrel_ec) vol_id = 12;
162 if(barrel_ec>0) vol_id = 14;
163
164 int lay_id = m_sctId->layer_disk(offlineId);
165
166 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, vol_id, lay_id);
167
168 std::map<std::tuple<int, int, short, short>,std::vector<GBTSPhiEtaHash> >::iterator it = hashMap.find(t);
169 if(it==hashMap.end())
170 hashMap.insert(std::pair<std::tuple<int, int, short, short>,std::vector<GBTSPhiEtaHash> >(t,std::vector<GBTSPhiEtaHash>(1, GBTSPhiEtaHash(phi_index, eta_index, hash))));
171 else (*it).second.push_back(GBTSPhiEtaHash(phi_index, eta_index, hash));
172 }
173 }
174
175
176 m_pixelLayers.clear();
177 m_sctLayers.clear();
178
179 m_pixelLayers.resize(m_pixelId->wafer_hash_max(), -100);
180 m_sctLayers.resize(m_sctId->wafer_hash_max(), -100);
181 m_layerGeometry.resize(hashMap.size());
182
183 int layerId=0;
185 for(std::map<std::tuple<int,int,short,short>,std::vector<GBTSPhiEtaHash> >::iterator it = hashMap.begin();it!=hashMap.end();++it, layerId++) {
186
187 short vol_id = std::get<2>((*it).first);
188 short lay_id = std::get<3>((*it).first);
189
190 int combinedId = static_cast<int>(vol_id)*1000 + lay_id;
191
192 short subdetId = std::get<1>((*it).first);
193 short barrel_ec = std::get<0>((*it).first);
194
195 if(barrel_ec==-100) barrel_ec = 0;
196
197 if(barrel_ec == 0) m_LastBarrelLayer++;
198
199 m_layerGeometry[layerId].m_type = barrel_ec;
200 m_layerGeometry[layerId].m_subdet = combinedId;
201
202
203 float rc=0.0;
204 float minBound = 100000.0;
205 float maxBound =-100000.0;
206 int nModules = 0;
207
208 for(std::vector<GBTSPhiEtaHash>::iterator hIt = (*it).second.begin();hIt != (*it).second.end();++hIt) {
209
210 const InDetDD::SiDetectorElement *p{nullptr};
211
212 if(subdetId == 1) {//pixel
213 m_pixelLayers[(*hIt).m_hash] = layerId;
214 p = m_pixelManager->getDetectorElement((*hIt).m_hash);
215 }
216 if(subdetId == 2) {//SCT
217 m_sctLayers[(*hIt).m_hash] = layerId;
218 p = m_sctManager->getDetectorElement((*hIt).m_hash);
219 }
220
221 if (p==nullptr) {
222 ATH_MSG_ERROR("nullptr SiDetectorElement with idHash " << (*hIt).m_hash);
223 continue;
224 }
225 const Amg::Vector3D& C = p->center();
226 if(barrel_ec == 0) {
227 rc += sqrt(C(0)*C(0)+C(1)*C(1));
228 if(p->zMin() < minBound) minBound = p->zMin();
229 if(p->zMax() > maxBound) maxBound = p->zMax();
230 }
231 else {
232 rc += C(2);
233 if(p->rMin() < minBound) minBound = p->rMin();
234 if(p->rMax() > maxBound) maxBound = p->rMax();
235 }
236 nModules++;
237 }
238 if (nModules == 0)[[unlikely]]{
239 throw std::runtime_error("GBTSTrigL2LayerNumberTool::createModuleHashMap: nModules is zero.");
240 }
241 m_layerGeometry[layerId].m_refCoord = rc/nModules;
242 m_layerGeometry[layerId].m_minBound = minBound;
243 m_layerGeometry[layerId].m_maxBound = maxBound;
244 }
245
246 int M = (layerId-m_LastBarrelLayer)/2;
247
248 ATH_MSG_DEBUG("List of unique layers in Pixel and SCT :");
249 for(int l=0;l<layerId;l++) {
250
251 int oldL = l;
252
253 if(l>m_LastBarrelLayer-1) {
254 oldL = l-m_LastBarrelLayer;
255 oldL = oldL < M ? oldL : oldL - M;
256 oldL += m_LastBarrelLayer;
257 }
258
259 if(m_layerGeometry[l].m_subdet==1) {
260 ATH_MSG_DEBUG("Layer "<<l<<" ("<<oldL<<") : PIX, reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<
261 " "<<m_layerGeometry[l].m_maxBound);
262 }
263 if(m_layerGeometry[l].m_subdet==2) {
264 ATH_MSG_DEBUG("Layer "<<l<<" ("<<oldL<<") : SCT, reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<
265 " "<<m_layerGeometry[l].m_maxBound);
266 }
267 }
268}
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_FATAL(x,...)
static Double_t sc
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:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
const InDetDD::PixelDetectorManager * m_pixelManager
std::vector< TrigInDetSiLayer > m_layerGeometry
std::map< std::tuple< int, int, short, short >, std::vector< GBTSPhiEtaHash > > m_hashMap
void createModuleHashMap(std::map< std::tuple< int, int, short, short >, std::vector< GBTSPhiEtaHash > > &)
GBTSTrigL2LayerNumberTool(const std::string &, const std::string &, const IInterface *)
const InDetDD::SCT_DetectorManager * m_sctManager
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.
struct color C
Eigen::Matrix< double, 3, 1 > Vector3D
#define unlikely(x)