ATLAS Offline Software
Loading...
Searching...
No Matches
TrigL2LayerNumberTool.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("TrigL2LayerNumberTool 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 TrigL2LayerNumberTool::createModuleHashMap(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >& hashMap) {
104
105 short subdetid = 1;
106
107 for(int hash = 0; hash<(int)m_pixelId->wafer_hash_max(); hash++) {
108
109 Identifier offlineId = m_pixelId->wafer_id(hash);
110
111 if(offlineId==0) continue;
112
113 short barrel_ec = m_pixelId->barrel_ec(offlineId);
114 if(std::abs(barrel_ec)>2) continue;//no DBM needed
115 short layer_disk = m_pixelId->layer_disk(offlineId);
116 short phi_index = m_pixelId->phi_module(offlineId);
117 short eta_index = m_pixelId->eta_module(offlineId);
118 //auto t = std::make_tuple(subdetid, barrel_ec, layer_disk);
119
120 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, layer_disk);
121
122 std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::iterator it = hashMap.find(t);
123 if(it==hashMap.end())
124 hashMap.insert(std::pair<std::tuple<short,short,short>,std::vector<PhiEtaHash> >(t,std::vector<PhiEtaHash>(1, PhiEtaHash(phi_index, eta_index, hash) )));
125 else (*it).second.push_back(PhiEtaHash(phi_index, eta_index, hash));
126 }
127 subdetid = 2;
128 for(int hash = 0; hash<(int)m_sctId->wafer_hash_max(); hash++) {
129
130 Identifier offlineId = m_sctId->wafer_id(hash);
131
132 if(offlineId==0) continue;
133
134 short barrel_ec = m_sctId->barrel_ec(offlineId);
135 short layer_disk = m_sctId->layer_disk(offlineId);
136 short phi_index = m_sctId->phi_module(offlineId);
137 short eta_index = m_sctId->eta_module(offlineId);
138
139 // auto t = std::make_tuple(subdetid, barrel_ec, layer_disk);
140
141 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, layer_disk);
142
143 std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::iterator it = hashMap.find(t);
144 if(it==hashMap.end())
145 hashMap.insert(std::pair<std::tuple<short,short,short>,std::vector<PhiEtaHash> >(t,std::vector<PhiEtaHash>(1, PhiEtaHash(phi_index, eta_index, hash))));
146 else (*it).second.push_back(PhiEtaHash(phi_index, eta_index, hash));
147 }
148
149 m_pixelLayers.clear();
150 m_sctLayers.clear();
151
152 m_pixelLayers.resize(m_pixelId->wafer_hash_max(), -100);
153 m_sctLayers.resize(m_sctId->wafer_hash_max(), -100);
154 m_layerGeometry.resize(hashMap.size());
155
156 int layerId=0;
158 for(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::iterator it = hashMap.begin();it!=hashMap.end();++it, layerId++) {
159
160 short subdetId = std::get<1>((*it).first);
161 short barrel_ec = std::get<0>((*it).first);
162 if(barrel_ec==-100) barrel_ec = 0;
163 //short layer_disc = std::get<2>((*it).first);
164
165 if(barrel_ec == 0) m_LastBarrelLayer++;
166
167 m_layerGeometry[layerId].m_type = barrel_ec;
168 m_layerGeometry[layerId].m_subdet = subdetId;
169
170 float rc=0.0;
171 float minBound = 100000.0;
172 float maxBound =-100000.0;
173 int nModules = 0;
174
175 for(std::vector<PhiEtaHash>::iterator hIt = (*it).second.begin();hIt != (*it).second.end();++hIt) {
176
177 const InDetDD::SiDetectorElement *p{nullptr};
178
179 if(subdetId == 1) {//pixel
180 m_pixelLayers[(*hIt).m_hash] = layerId;
181 p = m_pixelManager->getDetectorElement((*hIt).m_hash);
182 }
183 if(subdetId == 2) {//SCT
184 m_sctLayers[(*hIt).m_hash] = layerId;
185 p = m_sctManager->getDetectorElement((*hIt).m_hash);
186 }
187
188 if (p==nullptr) {
189 ATH_MSG_ERROR("nullptr SiDetectorElement with idHash " << (*hIt).m_hash);
190 continue;
191 }
192 const Amg::Vector3D& C = p->center();
193 if(barrel_ec == 0) {
194 rc += sqrt(C(0)*C(0)+C(1)*C(1));
195 if(p->zMin() < minBound) minBound = p->zMin();
196 if(p->zMax() > maxBound) maxBound = p->zMax();
197 }
198 else {
199 rc += C(2);
200 if(p->rMin() < minBound) minBound = p->rMin();
201 if(p->rMax() > maxBound) maxBound = p->rMax();
202 }
203 nModules++;
204 }
205 if (nModules == 0)[[unlikely]]{
206 throw std::runtime_error("TrigL2LayerNumberTool::createModuleHashMap: nModules is zero.");
207 }
208 m_layerGeometry[layerId].m_refCoord = rc/nModules;
209 m_layerGeometry[layerId].m_minBound = minBound;
210 m_layerGeometry[layerId].m_maxBound = maxBound;
211 }
212
213 int M = (layerId-m_LastBarrelLayer)/2;
214
215 ATH_MSG_DEBUG("List of unique layers in Pixel and SCT :");
216 for(int l=0;l<layerId;l++) {
217
218 int oldL = l;
219
220 if(l>m_LastBarrelLayer-1) {
221 oldL = l-m_LastBarrelLayer;
222 oldL = oldL < M ? oldL : oldL - M;
223 oldL += m_LastBarrelLayer;
224 }
225
226 if(m_layerGeometry[l].m_subdet==1) {
227 ATH_MSG_DEBUG("Layer "<<l<<" ("<<oldL<<") : PIX, reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<
228 " "<<m_layerGeometry[l].m_maxBound);
229 }
230 if(m_layerGeometry[l].m_subdet==2) {
231 ATH_MSG_DEBUG("Layer "<<l<<" ("<<oldL<<") : SCT, reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<
232 " "<<m_layerGeometry[l].m_maxBound);
233 }
234 }
235}
#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
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.
std::map< std::tuple< short, short, short >, std::vector< PhiEtaHash > > m_hashMap
virtual int offsetEndcapPixels() const
std::vector< short > m_sctLayers
virtual int offsetBarrelSCT() const
virtual int maxSiliconLayerNum() const
const InDetDD::SCT_DetectorManager * m_sctManager
TrigL2LayerNumberTool(const std::string &, const std::string &, const IInterface *)
std::vector< TrigInDetSiLayer > m_layerGeometry
virtual void report() const
std::vector< short > m_pixelLayers
const InDetDD::PixelDetectorManager * m_pixelManager
void createModuleHashMap(std::map< std::tuple< short, short, short >, std::vector< PhiEtaHash > > &)
virtual int offsetEndcapSCT() const
struct color C
Eigen::Matrix< double, 3, 1 > Vector3D
#define unlikely(x)