ATLAS Offline Software
TrigL2LayerNumberTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 #include "TrigL2LayerNumberTool.h"
13 
15  const std::string& n,
16  const IInterface* p ): AthAlgTool(t,n,p),
17  m_useNewScheme(false),
18  m_MaxSiliconLayerNum(-1),
19  m_OffsetEndcapPixels(-1),
20  m_OffsetBarrelSCT(-1),
21  m_OffsetEndcapSCT(-1)
22 {
23  declareInterface< ITrigL2LayerNumberTool >( this );
24  declareProperty( "UseNewLayerScheme", m_useNewScheme = false );
25 }
26 
28 
30 
31  ATH_MSG_DEBUG("In initialize...");
32 
33  sc = detStore()->retrieve(m_pixelId, "PixelID");
34  if (sc.isFailure()) {
35  ATH_MSG_FATAL("Could not get Pixel ID helper");
36  return sc;
37  }
38 
39  sc = detStore()->retrieve(m_sctId, "SCT_ID");
40  if (sc.isFailure()) {
41  ATH_MSG_FATAL("Could not get SCT ID helper");
42  return sc;
43  }
44 
45  sc = detStore()->retrieve(m_pixelManager);
46  if( sc.isFailure() ) {
47  ATH_MSG_ERROR("Could not retrieve Pixel DetectorManager from detStore.");
48  return sc;
49  }
50 
51  sc = detStore()->retrieve(m_sctManager);
52  if( sc.isFailure() ) {
53  ATH_MSG_ERROR("Could not retrieve SCT DetectorManager from detStore.");
54  return sc;
55  }
56 
57  //calculate the numbers
58 
59  if(!m_useNewScheme) {
60 
61  const InDetDD::SiNumerology& pixSiNum = m_pixelManager->numerology();
62  const InDetDD::SiNumerology& sctSiNum = m_sctManager->numerology();
63 
64  m_MaxSiliconLayerNum = pixSiNum.numLayers()+pixSiNum.numDisks()+sctSiNum.numLayers()+sctSiNum.numDisks();
65  m_OffsetBarrelSCT = pixSiNum.numLayers();
66  m_OffsetEndcapPixels = pixSiNum.numLayers()+sctSiNum.numLayers();
68  m_OffsetEndcapSCT = pixSiNum.numLayers()+sctSiNum.numLayers()+pixSiNum.numDisks();
69  }
70  else {
72 
73  ATH_MSG_DEBUG("Total number of unique silicon layers = "<<m_hashMap.size());
74 
77  }
78 
79 
80  ATH_MSG_DEBUG("TrigL2LayerNumberTool initialized ");
81 
82  report();
83 
84  return sc;
85 }
86 
88 {
90  return sc;
91 }
92 
94 
95  ATH_MSG_DEBUG("TrigL2 Layer numbering scheme:");
96  ATH_MSG_DEBUG("Total number of layers = "<<maxSiliconLayerNum());
97  ATH_MSG_DEBUG("OffsetEndcapPixels = "<<offsetEndcapPixels());
98  ATH_MSG_DEBUG("OffsetBarrelSCT = "<<offsetBarrelSCT());
99  ATH_MSG_DEBUG("OffsetEndcapSCT = "<<offsetEndcapSCT());
100 }
101 
102 void TrigL2LayerNumberTool::createModuleHashMap(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >& hashMap) {
103 
104  short subdetid = 1;
105 
106  for(int hash = 0; hash<(int)m_pixelId->wafer_hash_max(); hash++) {
107 
108  Identifier offlineId = m_pixelId->wafer_id(hash);
109 
110  if(offlineId==0) continue;
111 
112  short barrel_ec = m_pixelId->barrel_ec(offlineId);
113  if(std::abs(barrel_ec)>2) continue;//no DBM needed
114  short layer_disk = m_pixelId->layer_disk(offlineId);
115  short phi_index = m_pixelId->phi_module(offlineId);
116  short eta_index = m_pixelId->eta_module(offlineId);
117  //auto t = std::make_tuple(subdetid, barrel_ec, layer_disk);
118 
119  auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, layer_disk);
120 
121  std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::iterator it = hashMap.find(t);
122  if(it==hashMap.end())
123  hashMap.insert(std::pair<std::tuple<short,short,short>,std::vector<PhiEtaHash> >(t,std::vector<PhiEtaHash>(1, PhiEtaHash(phi_index, eta_index, hash) )));
124  else (*it).second.push_back(PhiEtaHash(phi_index, eta_index, hash));
125  }
126  subdetid = 2;
127  for(int hash = 0; hash<(int)m_sctId->wafer_hash_max(); hash++) {
128 
129  Identifier offlineId = m_sctId->wafer_id(hash);
130 
131  if(offlineId==0) continue;
132 
133  short barrel_ec = m_sctId->barrel_ec(offlineId);
134  short layer_disk = m_sctId->layer_disk(offlineId);
135  short phi_index = m_sctId->phi_module(offlineId);
136  short eta_index = m_sctId->eta_module(offlineId);
137 
138  // auto t = std::make_tuple(subdetid, barrel_ec, layer_disk);
139 
140  auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, layer_disk);
141 
142  std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::iterator it = hashMap.find(t);
143  if(it==hashMap.end())
144  hashMap.insert(std::pair<std::tuple<short,short,short>,std::vector<PhiEtaHash> >(t,std::vector<PhiEtaHash>(1, PhiEtaHash(phi_index, eta_index, hash))));
145  else (*it).second.push_back(PhiEtaHash(phi_index, eta_index, hash));
146  }
147 
148  m_pixelLayers.clear();
149  m_sctLayers.clear();
150 
151  m_pixelLayers.resize(m_pixelId->wafer_hash_max(), -100);
152  m_sctLayers.resize(m_sctId->wafer_hash_max(), -100);
153  m_layerGeometry.resize(hashMap.size());
154 
155  int layerId=0;
157  for(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::iterator it = hashMap.begin();it!=hashMap.end();++it, layerId++) {
158 
159  short subdetId = std::get<1>((*it).first);
160  short barrel_ec = std::get<0>((*it).first);
161  if(barrel_ec==-100) barrel_ec = 0;
162  //short layer_disc = std::get<2>((*it).first);
163 
164  if(barrel_ec == 0) m_LastBarrelLayer++;
165 
166  m_layerGeometry[layerId].m_type = barrel_ec;
167  m_layerGeometry[layerId].m_subdet = subdetId;
168 
169  float rc=0.0;
170  float minBound = 100000.0;
171  float maxBound =-100000.0;
172  int nModules = 0;
173 
174  for(std::vector<PhiEtaHash>::iterator hIt = (*it).second.begin();hIt != (*it).second.end();++hIt) {
175 
176  const InDetDD::SiDetectorElement *p{nullptr};
177 
178  if(subdetId == 1) {//pixel
179  m_pixelLayers[(*hIt).m_hash] = layerId;
180  p = m_pixelManager->getDetectorElement((*hIt).m_hash);
181  }
182  if(subdetId == 2) {//SCT
183  m_sctLayers[(*hIt).m_hash] = layerId;
184  p = m_sctManager->getDetectorElement((*hIt).m_hash);
185  }
186 
187  if (p==nullptr) {
188  ATH_MSG_ERROR("nullptr SiDetectorElement with idHash " << (*hIt).m_hash);
189  continue;
190  }
191  const Amg::Vector3D& C = p->center();
192  if(barrel_ec == 0) {
193  rc += sqrt(C(0)*C(0)+C(1)*C(1));
194  if(p->zMin() < minBound) minBound = p->zMin();
195  if(p->zMax() > maxBound) maxBound = p->zMax();
196  }
197  else {
198  rc += C(2);
199  if(p->rMin() < minBound) minBound = p->rMin();
200  if(p->rMax() > maxBound) maxBound = p->rMax();
201  }
202  nModules++;
203  }
204  m_layerGeometry[layerId].m_refCoord = rc/nModules;
205  m_layerGeometry[layerId].m_minBound = minBound;
206  m_layerGeometry[layerId].m_maxBound = maxBound;
207  }
208 
209  int M = (layerId-m_LastBarrelLayer)/2;
210 
211  ATH_MSG_DEBUG("List of unique layers in Pixel and SCT :");
212  for(int l=0;l<layerId;l++) {
213 
214  int oldL = l;
215 
216  if(l>m_LastBarrelLayer-1) {
217  oldL = l-m_LastBarrelLayer;
218  oldL = oldL < M ? oldL : oldL - M;
219  oldL += m_LastBarrelLayer;
220  }
221 
222  if(m_layerGeometry[l].m_subdet==1) {
223  ATH_MSG_DEBUG("Layer "<<l<<" ("<<oldL<<") : PIX, reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<
224  " "<<m_layerGeometry[l].m_maxBound);
225  }
226  if(m_layerGeometry[l].m_subdet==2) {
227  ATH_MSG_DEBUG("Layer "<<l<<" ("<<oldL<<") : SCT, reference coordinate ="<< m_layerGeometry[l].m_refCoord<<" boundaries: "<<m_layerGeometry[l].m_minBound<<
228  " "<<m_layerGeometry[l].m_maxBound);
229  }
230  }
231 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrigL2LayerNumberTool::finalize
StatusCode finalize()
Definition: TrigL2LayerNumberTool.cxx:87
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
TrigL2LayerNumberTool::m_layerGeometry
std::vector< TrigInDetSiLayer > m_layerGeometry
Definition: TrigL2LayerNumberTool.h:100
TrigL2LayerNumberTool::offsetEndcapPixels
virtual int offsetEndcapPixels() const
Definition: TrigL2LayerNumberTool.h:59
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
InDetDD::SiDetectorManager::numerology
const SiNumerology & numerology() const
Access Numerology.
Definition: SiDetectorManager.h:126
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrigL2LayerNumberTool::offsetEndcapSCT
virtual int offsetEndcapSCT() const
Definition: TrigL2LayerNumberTool.h:61
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TrigL2LayerNumberTool::TrigL2LayerNumberTool
TrigL2LayerNumberTool(const std::string &, const std::string &, const IInterface *)
Definition: TrigL2LayerNumberTool.cxx:14
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PhiEtaHash
Definition: TrigL2LayerNumberTool.h:23
initialize
void initialize()
Definition: run_EoverP.cxx:894
DMTest::C
C_v1 C
Definition: C.h:26
TrigL2LayerNumberTool::m_hashMap
std::map< std::tuple< short, short, short >, std::vector< PhiEtaHash > > m_hashMap
Definition: TrigL2LayerNumberTool.h:98
skel.it
it
Definition: skel.GENtoEVGEN.py:423
PixelModuleFeMask_create_db.nModules
nModules
Definition: PixelModuleFeMask_create_db.py:47
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
TrigL2LayerNumberTool::m_sctId
const SCT_ID * m_sctId
Definition: TrigL2LayerNumberTool.h:91
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TrigL2LayerNumberTool::m_LastBarrelLayer
int m_LastBarrelLayer
Definition: TrigL2LayerNumberTool.h:89
InDetDD::SCT_DetectorManager::getDetectorElement
virtual SiDetectorElement * getDetectorElement(const Identifier &id) const override
access to individual elements via Identifier
Definition: SCT_DetectorManager.cxx:64
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TrigL2LayerNumberTool::offsetBarrelSCT
virtual int offsetBarrelSCT() const
Definition: TrigL2LayerNumberTool.h:60
TrigL2LayerNumberTool::maxSiliconLayerNum
virtual int maxSiliconLayerNum() const
Definition: TrigL2LayerNumberTool.h:58
PixelDetectorManager.h
TrigL2LayerNumberTool::m_sctManager
const InDetDD::SCT_DetectorManager * m_sctManager
Definition: TrigL2LayerNumberTool.h:94
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SiNumerology.h
TrigL2LayerNumberTool::report
virtual void report() const
Definition: TrigL2LayerNumberTool.cxx:93
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigL2LayerNumberTool::m_sctLayers
std::vector< short > m_sctLayers
Definition: TrigL2LayerNumberTool.h:99
TrigL2LayerNumberTool::m_OffsetEndcapSCT
int m_OffsetEndcapSCT
Definition: TrigL2LayerNumberTool.h:88
TrigL2LayerNumberTool::m_OffsetEndcapPixels
int m_OffsetEndcapPixels
Definition: TrigL2LayerNumberTool.h:86
TrigL2LayerNumberTool::m_pixelManager
const InDetDD::PixelDetectorManager * m_pixelManager
Definition: TrigL2LayerNumberTool.h:93
InDetDD::SiNumerology::numDisks
int numDisks() const
Number of disks.
TrigL2LayerNumberTool::m_useNewScheme
bool m_useNewScheme
Definition: TrigL2LayerNumberTool.h:82
TrigL2LayerNumberTool::m_MaxSiliconLayerNum
int m_MaxSiliconLayerNum
Definition: TrigL2LayerNumberTool.h:85
InDetDD::SiNumerology::numLayers
int numLayers() const
Number of layers.
createCablingJSON.eta_index
int eta_index
Definition: createCablingJSON.py:9
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
TrigL2LayerNumberTool::m_pixelLayers
std::vector< short > m_pixelLayers
Definition: TrigL2LayerNumberTool.h:99
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:639
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:912
TrigL2LayerNumberTool.h
InDetDD::SiNumerology
Definition: SiNumerology.h:27
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
SiDetectorElement.h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
TrigL2LayerNumberTool::createModuleHashMap
void createModuleHashMap(std::map< std::tuple< short, short, short >, std::vector< PhiEtaHash > > &)
Definition: TrigL2LayerNumberTool.cxx:102
AthAlgTool
Definition: AthAlgTool.h:26
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
SCT_DetectorManager.h
TrigL2LayerNumberTool::m_pixelId
const PixelID * m_pixelId
Definition: TrigL2LayerNumberTool.h:92
PixelID::phi_module
int phi_module(const Identifier &id) const
Definition: PixelID.h:644
TrigL2LayerNumberTool::m_OffsetBarrelSCT
int m_OffsetBarrelSCT
Definition: TrigL2LayerNumberTool.h:87
InDetDD::PixelDetectorManager::getDetectorElement
virtual SiDetectorElement * getDetectorElement(const Identifier &id) const override
access to individual elements : via Identifier
Definition: PixelDetectorManager.cxx:80
TrigL2LayerNumberTool::initialize
StatusCode initialize()
Definition: TrigL2LayerNumberTool.cxx:27