ATLAS Offline Software
SiliconID.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3  */
4 
12 //<<<<<< INCLUDES >>>>>>
13 
16 #include "IdDict/IdDictDefs.h"
17 #include "GaudiKernel/MsgStream.h"
18 #include <iostream>
19 
23 
25  :
26  m_wafer_hash_max(0),
27  m_pixel_wafer_hash_max(0),
28  m_pixel_helper(nullptr),
29  m_sct_helper(nullptr)
30 {}
31 
32 SiliconID::SiliconID(const PixelID* pixel_helper, const SCT_ID* sct_helper)
33  :
34  m_wafer_hash_max(0),
35  m_pixel_wafer_hash_max(0),
36  m_pixel_helper(pixel_helper),
37  m_sct_helper(sct_helper)
38 {}
39 
40 
41 SiliconID::~SiliconID() = default;
42 
43 
44 
45 int
47  MsgStream log(m_msgSvc, "SiliconID");
48  if (m_msgSvc) log << MSG::INFO << "Initialize from dictionary" << endmsg;
49  else std::cout << " INFO SiliconID Initialize from dictionary" << std::endl;
50  // Check whether this helper should be reinitialized
51  if (!reinitialize(dict_mgr)) {
52  if (m_msgSvc) log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg;
53  else std::cout <<
54  " INFO SiliconID::initialize_from_dictionary - Request to reinitialize not satisfied - tags have not changed" <<
55  std::endl;
56  return(0);
57  } else {
58  if (m_msgSvc) log << MSG::DEBUG << "(Re)initialize" << endmsg;
59  else std::cout << " DEBUG SiliconID::initialize_from_dictionary - (Re)initialize" << std::endl;
60  }
61  // init base object
62  if (AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return(1);
63  // Register version of InnerDetector dictionary
64  if (register_dict_tag(dict_mgr, "InnerDetector")) return(1);
65  // Make sure that pix/sct helpers are initialized
66  // CANNOT MODIFY CONST HELPERS
69  return 0;
70 }
71 
72 // From hash get Identifier
73 int
74 SiliconID::get_id(const IdentifierHash& /*hash_id*/,
75  Identifier& id,
76  const IdContext* /*context*/) const {
77  int result = 1;
78  Identifier newid;
79 
80  id = newid;
81  return(result);
82 }
83 
84 int
86  IdentifierHash& hash_id,
87  const IdContext* /*context*/) const {
88  // Get the hash code from either a vec (for wafers) or calculate
89  // it (pixels). For the former, we convert to compact and call
90  // get_hash again. For the latter, we calculate the hash from the
91  // Identifier.
92 
93  int result = 1;
94 
95  hash_id = 0;
96  return(result);
97 }
98 
99 int
101  MsgStream log(m_msgSvc, "IdDictTest_SiliconID");
102 
103  if (m_msgSvc) log << MSG::INFO << "test_wafer_packing: wafer hash max, pix, sct "
104  << wafer_hash_max() << " "
105  << m_pixel_helper->wafer_hash_max() << " "
106  << m_sct_helper->wafer_hash_max() << " "
107  << endmsg;
108  else std::cout << " INFO SiliconID::test_wafer_packing: wafer hash max, pix, sct "
109  << wafer_hash_max() << " "
110  << m_pixel_helper->wafer_hash_max() << " "
111  << m_sct_helper->wafer_hash_max() << " "
112  << std::endl;
113 
114  bool error = false;
115 
116  int nids = 0;
117  int nblay = 0;
118  int nbar = 0;
119  int nbars = 0;
120  int nbarp = 0;
121  int nHashPix = 0;
122 
123  for (unsigned int i = 0; i < wafer_hash_max(); ++i, ++nids) {
124  Identifier id = wafer_id(i);
125  if (i < 10) {
126  if (m_msgSvc) log << MSG::INFO << "test_wafer_packing: id "
127  << show_to_string(id)
128  << endmsg;
129  else std::cout << " INFO SiliconID::test_wafer_packing: id "
130  << show_to_string(id)
131  << std::endl;
132  }
133 
134  // Check hash
136  if (hash != i) {
137  if (m_msgSvc) log << MSG::ERROR << "test_wafer_packing: wafer_hash not equal to i "
138  << "hash: " << hash << " i: " << i << " "
139  << show_to_string(id)
140  << endmsg;
141  else std::cout << " ERROR SiliconID::test_wafer_packing: wafer_hash not equal to i "
142  << "hash: " << hash << " i: " << i << " "
143  << show_to_string(id)
144  << std::endl;
145  error = true;
146  }
147 
148  // Check is_barrel
149  if (is_barrel(id)) {
150  nbar++;
151  if (is_sct(id)) {
152  nbars++;
153  if (!m_sct_helper->is_barrel(id)) {
154  if (m_msgSvc) log << MSG::ERROR << "test_wafer_packing: is_barrel fails for sct. "
155  << "hash: " << hash << " i: " << i << " "
156  << show_to_string(id)
157  << endmsg;
158  else std::cout << " ERROR SiliconID::test_wafer_packing: is_barrel fails for sct. "
159  << "hash: " << hash << " i: " << i << " "
160  << show_to_string(id)
161  << std::endl;
162  error = true;
163  }
164  } else {
165  nbarp++;
166  if (!m_pixel_helper->is_barrel(id)) {
167  if (m_msgSvc) log << MSG::ERROR << "test_wafer_packing: is_barrel fails for pixel. "
168  << "hash: " << hash << " i: " << i << " "
169  << show_to_string(id)
170  << endmsg;
171  else std::cout << " ERROR SiliconID::test_wafer_packing: is_barrel fails for pixel. "
172  << "hash: " << hash << " i: " << i << " "
173  << show_to_string(id)
174  << std::endl;
175  error = true;
176  }
177  }
178  }
179 
180  // Check is_blayer
181  if (is_blayer(id)) {
182  nblay++;
183  if (is_sct(id)) {
184  if (m_msgSvc) log << MSG::ERROR << "test_wafer_packing: is_blayer is sct. "
185  << "hash: " << hash << " i: " << i << " "
186  << show_to_string(id)
187  << endmsg;
188  else std::cout << " ERROR SiliconID::test_wafer_packing: is_blayer is sct. "
189  << "hash: " << hash << " i: " << i << " "
190  << show_to_string(id)
191  << std::endl;
192  error = true;
193  } else {
194  if (!m_pixel_helper->is_blayer(id)) {
195  if (m_msgSvc) log << MSG::ERROR << "test_wafer_packing: is_blayer fails for pixel. "
196  << "hash: " << hash << " i: " << i << " "
197  << show_to_string(id)
198  << endmsg;
199  else std::cout << " ERROR SiliconID::test_wafer_packing: is_blayer fails for pixel. "
200  << "hash: " << hash << " i: " << i << " "
201  << show_to_string(id)
202  << std::endl;
203  error = true;
204  }
205  }
206  }
207 
208  // Check is_pixel
209  if (is_hash_pixel(i) != is_pixel(id)) {
210  if (m_msgSvc) log << MSG::ERROR << "test_wafer_packing: is_hash_pixel "
211  << "hash: " << hash << " i: " << i << " "
212  << show_to_string(id)
213  << endmsg;
214  else std::cout << " ERROR SiliconID::test_wafer_packing: is_hash_pixel "
215  << "hash: " << hash << " i: " << i << " "
216  << show_to_string(id)
217  << std::endl;
218  error = true;
219  } else {
220  nHashPix++;
221  }
222  }
223 
224  if (m_msgSvc) {
225  log << MSG::INFO << "Looped over " << nids << " hashes "
226  << endmsg;
227  log << MSG::INFO << "Number of is_barrel (pix/sct): " << nbar
228  << " " << nbarp << " " << nbars
229  << endmsg;
230  log << MSG::INFO << "Number of is_blayer: " << nblay
231  << endmsg;
232  log << MSG::INFO << "Number of matching is_hash_pixel/is_pixel: " << nHashPix
233  << endmsg;
234  } else {
235  std::cout << " INFO Looped over " << nids << " hashes "
236  << std::endl;
237  std::cout << " INFO Number of is_barrel (pix/sct): " << nbar
238  << " " << nbarp << " " << nbars
239  << std::endl;
240  std::cout << " INFO Number of is_blayer: " << nblay
241  << std::endl;
242  std::cout << " INFO Number of matching is_hash_pixel/is_pixel: " << nHashPix
243  << std::endl;
244  }
245 
246 
247  if (error) return(1);
248 
249  return(0);
250 }
AtlasDetectorID::is_pixel
bool is_pixel(Identifier id) const
Definition: AtlasDetectorID.h:760
SiliconID::get_id
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override final
Create compact id from hash id (return == 0 for OK)
Definition: SiliconID.cxx:74
SiliconID::wafer_id
Identifier wafer_id(IdentifierHash wafer_hash) const
Identifier from hash.
Definition: SiliconID.h:122
AtlasDetectorID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition: AtlasDetectorID.cxx:320
get_generator_info.result
result
Definition: get_generator_info.py:21
SiliconID::wafer_hash_max
size_type wafer_hash_max(void) const
Hash table maximum sizes.
Definition: SiliconID.h:151
SiliconID::m_sct_helper
const SCT_ID * m_sct_helper
Definition: SiliconID.h:107
AtlasDetectorID::is_sct
bool is_sct(Identifier id) const
Definition: AtlasDetectorID.h:770
SiliconID::test_wafer_hashes
int test_wafer_hashes(void) const
Tests of packing.
Definition: SiliconID.cxx:100
SiliconID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: SiliconID.h:138
SiliconID::is_barrel
bool is_barrel(const Identifier &id) const
Test for barrel - generic, i.e. works for EITHER pixel or sct id.
Definition: SiliconID.h:158
AtlasDetectorID::m_msgSvc
IMessageSvc * m_msgSvc
pointer to the message service
Definition: AtlasDetectorID.h:368
PixelID::is_blayer
bool is_blayer(const Identifier &id) const
Test for b-layer - WARNING: id MUST be pixel id, otherwise answer is not accurate....
Definition: PixelID.h:633
SiliconID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override final
Initialization from the identifier dictionary.
Definition: SiliconID.cxx:46
SiliconID::m_wafer_hash_max
size_type m_wafer_hash_max
Definition: SiliconID.h:104
IdDictDefs.h
SiliconID::is_blayer
bool is_blayer(const Identifier &id) const
Test for pixle b-layer - generic, i.e. works for EITHER pixel or sct id.
Definition: SiliconID.h:171
IdDictMgr
Definition: IdDictDefs.h:32
PixelID::is_barrel
bool is_barrel(const Identifier &id) const
Test for barrel - WARNING: id MUST be pixel id, otherwise answer is not accurate. Use SiliconID for g...
Definition: PixelID.h:605
SiliconID::~SiliconID
~SiliconID(void)
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
SiliconID::is_hash_pixel
bool is_hash_pixel(IdentifierHash wafer_hash) const
Test whether hash is pixel or sct.
Definition: SiliconID.h:184
SiliconID.h
This is an Identifier helper class for both the Pixel and SCT subdetectors. This class defines identi...
SiliconID::SiliconID
SiliconID(void)
Definition: SiliconID.cxx:24
SiliconID::get_hash
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const override final
Create hash id from compact id (return == 0 for OK)
Definition: SiliconID.cxx:85
AtlasDetectorID::register_dict_tag
int register_dict_tag(const IdDictMgr &dict_mgr, const std::string &dict_name)
Register the file and tag names for a particular IdDict dictionary.
Definition: AtlasDetectorID.cxx:266
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:639
IdentifierHash.h
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:912
SiliconID::m_pixel_wafer_hash_max
size_type m_pixel_wafer_hash_max
Definition: SiliconID.h:105
AtlasDetectorID::reinitialize
bool reinitialize(const IdDictMgr &dict_mgr)
Test whether an idhelper should be reinitialized based on the change of tags.
Definition: AtlasDetectorID.cxx:284
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
SCT_ID
Definition: SCT_ID.h:68
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
IdentifierHash
Definition: IdentifierHash.h:38
PixelID
Definition: PixelID.h:67
error
Definition: IImpactPoint3dEstimator.h:70
IdContext
class IdContext
Definition: IdContext.h:34
SiliconID::m_pixel_helper
const PixelID * m_pixel_helper
Definition: SiliconID.h:106
SCT_ID::is_barrel
bool is_barrel(const Identifier &id) const
Test for barrel - WARNING: id MUST be sct id, otherwise answer is not accurate. Use SiliconID for gen...
Definition: SCT_ID.h:721