ATLAS Offline Software
TRT_ID.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 /***************************************************************************
6  Inner Detector identifier package
7  -------------------------------------------
8 ***************************************************************************/
9 
10 
11 #include "InDetIdentifier/TRT_ID.h"
13 #include "IdDict/IdDictField.h"
14 #include "IdDict/IdDictMgr.h"
15 #include "IdDict/IdDictRegion.h"
18 #include "Identifier/IdContext.h"
19 #include <set>
20 #include <algorithm>
21 #include <iostream>
22 #include <cassert>
23 
24 
26 
28  :
29  AtlasDetectorID("TRT_ID", "trt"),
30  m_is_valid(true),
31  m_trt_region_index(0),
32  m_INDET_INDEX(0),
33  m_TRT_INDEX(1),
34  m_BARREL_EC_INDEX(2),
35  m_PHI_MODULE_INDEX(3),
36  m_LAYER_OR_WHEEL_INDEX(4),
37  m_STRAW_LAYER_INDEX(5),
38  m_STRAW_INDEX(6),
39  m_dict(nullptr),
40  m_module_hash_max(0),
41  m_straw_layer_hash_max(0),
42  m_straw_hash_max(0) {
45 }
46 
47 TRT_ID::~TRT_ID() = default;
48 
49 void
50 TRT_ID::barrel_ec_id_checks(int barrel_ec) const {
51  // Check that id is within allowed range
52 
53  // Fill expanded id
55 
57 
58  if (!m_full_module_range.match(id)) { // module range check is sufficient
59  ATH_MSG_ERROR(" TRT_ID::barrel_ec_id result is NOT ok. ID, range "
60  << (std::string) id << " "
61  << (std::string) m_full_module_range);
62  }
63 }
64 
65 void
67  int phi_module,
68  int layer_or_wheel) const {
69  // Check that id is within allowed range
70 
71  // Fill expanded id
73 
76 
77  if (!m_full_module_range.match(id)) { // module range check is sufficient
78  ATH_MSG_ERROR(" TRT_ID::module_id result is NOT ok. ID, range "
79  << (std::string) id << " "
80  << (std::string) m_full_module_range);
81  }
82 }
83 
84 void
86  int phi_module,
87  int layer_or_wheel,
88  int straw_layer,
89  int straw) const {
90  // Check that id is within allowed range
91 
92  // Build identifier
94 
97 
98  if (!m_full_straw_range.match(id)) {
99  ATH_MSG_ERROR(" TRT_ID::straw_id result is NOT ok. ID, range "
100  << (std::string) id << " "
101  << (std::string) m_full_straw_range);
102  }
103 }
104 
105 void
107  int phi_module,
108  int layer_or_wheel,
109  int straw_layer) const {
110  // Check that id is within allowed range
111 
112  // Build identifier
114 
117 
118  if (!m_full_straw_layer_range.match(id)) {
119  ATH_MSG_ERROR(" TRT_ID::layer_id result is NOT ok. ID, range "
120  << (std::string) id << " "
121  << (std::string) m_full_straw_layer_range);
122 
123  }
124 }
125 
126 
127 int
129  ATH_MSG_INFO("Initialize from dictionary");
130  // Check whether this helper should be reinitialized
131  if (!reinitialize(dict_mgr)) {
132  ATH_MSG_INFO("Request to reinitialize not satisfied - tags have not changed");
133  return(0);
134  } else {
135  ATH_MSG_DEBUG("(Re)initialize");
136  }
137 
138  // init base object
140  m_is_valid = false;
141  return(1);
142  }
143 
144 
145  // Register version of InnerDetector dictionary
146  if (register_dict_tag(dict_mgr, "InnerDetector")) {
147  m_is_valid = false;
148  return(1);
149  }
150 
151 
152  m_dict = dict_mgr.find_dictionary("InnerDetector");
153  if (!m_dict) {
154  ATH_MSG_ERROR(" TRT_ID::initialize_from_dict - cannot access InnerDetector dictionary ");
155  m_is_valid = false;
156  return 1;
157  }
158 
159  // Initialize the field indices
160  if (initLevelsFromDict()) {
161  m_is_valid = false;
162  return(1);
163  }
164 
165 
166  //
167  // Set barrel field for testing is_barrel
168  //
169  int barrel_value;
171  // negative barrel
172  if (m_dict->get_label_value("barrel_endcap", "negative_barrel", barrel_value)) {
173  ATH_MSG_ERROR("Could not get value for label 'barrel' of field 'barrel_endcap' in dictionary "
174  << m_dict->name());
175 
176  m_is_valid = false;
177  return(1);
178  }
179  m_barrel_field.add_value(barrel_value);
180  // negative barrel
181  if (m_dict->get_label_value("barrel_endcap", "positive_barrel", barrel_value)) {
182  ATH_MSG_ERROR("Could not get value for label 'barrel' of field 'barrel_endcap' in dictionary "
183  << m_dict->name());
184 
185  m_is_valid = false;
186  return(1);
187  }
188  m_barrel_field.add_value(barrel_value);
189  ATH_MSG_DEBUG(" TRT_ID::initialize_from_dict "
190  << "Set barrel field values: "
191  << (std::string) m_barrel_field);
192 
193  //
194  // Build multirange for the valid set of identifiers
195  //
196 
197 
198  // Find value for the field InnerDetector
199  const IdDictDictionary* atlasDict = dict_mgr.find_dictionary("ATLAS");
200 
201  int inDetField = -1;
202  if (atlasDict->get_label_value("subdet", "InnerDetector", inDetField)) {
203  ATH_MSG_ERROR("Could not get value for label 'InnerDetector' of field 'subdet' in dictionary "
204  << atlasDict->name());
205 
206  m_is_valid = false;
207  return(1);
208  }
209 
210  // Find value for the field TRT
211  int trtField = -1;
212  if (m_dict->get_label_value("part", "TRT", trtField)) {
213  ATH_MSG_ERROR("Could not get value for label 'TRT' of field 'part' in dictionary "
214  << m_dict->name());
215 
216  m_is_valid = false;
217  return(1);
218  }
219  ATH_MSG_DEBUG(" TRT_ID::initialize_from_dict "
220  << "Found field values: InDet/TRT "
221  << inDetField << "/"
222  << trtField);
223 
224 
225  // Set up id for region and range prefix
227  region_id.add(inDetField);
228  region_id.add(trtField);
229  Range prefix;
233 
234  init_hashes();
235 
236  ATH_MSG_DEBUG(" TRT_ID::initialize_from_dict ");
237  ATH_MSG_DEBUG("Module range -> " << (std::string) m_full_module_range);
238  ATH_MSG_DEBUG("Straw layer range -> " << (std::string) m_full_straw_layer_range);
239  ATH_MSG_DEBUG("Straw range -> " << (std::string) m_full_straw_range);
240 
241  return 0;
242 }
243 
244 void
246  //
247  // create two vecs (module and straw layer) to retrieve the hashes
248  // for compact ids
249  //
250 
251  // module hash
252 
253  ATH_MSG_DEBUG("Module range -> " << (std::string) m_full_module_range);
254 
257  unsigned int nids = 0;
258  std::set<Identifier> ids;
259  for (unsigned int i = 0; i < m_full_module_range.size(); ++i) {
260  const Range& range = m_full_module_range[i];
262  for (const auto & exp_id: rit) {
264  exp_id[m_PHI_MODULE_INDEX],
265  exp_id[m_LAYER_OR_WHEEL_INDEX]);
266  if (!(ids.insert(id)).second) {
267  ATH_MSG_ERROR(" TRT_ID::init_hashes "
268  << " Error: duplicated id for module id. nid " << nids
269  << " compact id " << show_to_string(id)
270  << " id " << std::string(exp_id));
271 
272  }
273  nids++;
274  }
275  }
276  if (ids.size() != m_module_hash_max) {
277  ATH_MSG_ERROR(" TRT_ID::init_hashes "
278  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
279  << " hash max " << m_module_hash_max);
280 
281  } else {
282  ATH_MSG_DEBUG(" TRT_ID::init_hashes "
283  << " module hash max " << m_module_hash_max);
284 
285  }
286 
287  nids = 0;
288  std::set<Identifier>::const_iterator first = ids.begin();
289  std::set<Identifier>::const_iterator last = ids.end();
290  for (; first != last && nids < m_module_vec.size(); ++first) {
291  m_module_vec[nids] = (*first);
292  nids++;
293  }
294 
295  // straw_layer hash
298  nids = 0;
299  ids.clear();
300  for (unsigned int i = 0; i < m_full_straw_layer_range.size(); ++i) {
303  for (const auto & exp_id: rit) {
305  exp_id[m_PHI_MODULE_INDEX],
306  exp_id[m_LAYER_OR_WHEEL_INDEX],
307  exp_id[m_STRAW_LAYER_INDEX]);
308  if (!(ids.insert(id)).second) {
309  ATH_MSG_ERROR(" TRT_ID::init_hashes "
310  << " Error: duplicated id for straw layer id. nid " << nids
311  << " compact id " << show_to_string(id)
312  << " id " << std::string(exp_id));
313 
314  nids++;
315  }
316  }
317  }
318 
319  if (ids.size() != m_straw_layer_hash_max) {
320  ATH_MSG_ERROR(" TRT_ID::init_hashes "
321  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
322  << " hash max " << m_straw_layer_hash_max);
323  } else {
324  ATH_MSG_DEBUG(" TRT_ID::init_hashes "
325  << " straw layer hash max " << m_straw_layer_hash_max);
326 
327  }
328 
329  nids = 0;
330  first = ids.begin();
331  last = ids.end();
332  for (; first != last && nids < m_straw_layer_vec.size(); ++first) {
333  m_straw_layer_vec[nids] = (*first);
334  nids++;
335  }
336 
337 
338  // Init vector for binary lookup
340 
341 
342  // Setup for hash calculation for straw ids
343 
344 
345  // We use a HashCalc object to save the information needed to
346  // calculate the hash from the decoded values of a straw id.
347  //
348  // The number of HashCalc objects needed are 2x the number of
349  // ranges - one for each pos/neg. There are then two additional
350  // lookup tables, one for each of barrel and endcap, to access the
351  // index into the HashCalc table. Here we set up the HashCalc
352  // table and the additional tables for accessing the index.
353 
354  // Set up vector as lookup table for hash calculation.
355  unsigned int hcIndex = 0;
356  unsigned int nRanges = m_full_straw_range.size();
357  m_hash_calcs.resize(2 * nRanges); // allow for pos/neg
358 
359 // std::vector<bool> startHashFound(4,false);
360 // m_beStartHash.resize(4);
361 
362 
363  for (unsigned int i = 0; i < m_full_straw_range.size(); ++i) {
364  const Range* range = &m_full_straw_range[i];
365  ExpandedIdentifier exp_id = range->minimum();
367  exp_id[m_PHI_MODULE_INDEX],
368  exp_id[m_LAYER_OR_WHEEL_INDEX],
369  exp_id[m_STRAW_LAYER_INDEX],
370  exp_id[m_STRAW_INDEX]);
371  IdentifierHash min_neg = straw_hash_bin(min);
372 
373  // Calculate the offset in phi
374  Identifier next_phi = straw_id(exp_id[m_BARREL_EC_INDEX],
375  exp_id[m_PHI_MODULE_INDEX] + 1,
376  exp_id[m_LAYER_OR_WHEEL_INDEX],
377  exp_id[m_STRAW_LAYER_INDEX],
378  exp_id[m_STRAW_INDEX]);
379  IdentifierHash deltaPhi = straw_hash_bin(next_phi) - min_neg;
380 
381  // barrel or endcap
383 
384 
385  // both pos and neg available?
386  bool two_sides = ((*range)[m_BARREL_EC_INDEX].get_indices() == 2);
387 
388  // fill lookup table with index to HashCalc
389  unsigned int lay_min = (*range)[m_LAYER_OR_WHEEL_INDEX].get_minimum();
390  unsigned int nlayers = (*range)[m_LAYER_OR_WHEEL_INDEX].get_indices();
391  unsigned int str_lay_min = (*range)[m_STRAW_LAYER_INDEX].get_minimum();
392  unsigned int nstr_layers = (*range)[m_STRAW_LAYER_INDEX].get_indices();
393  unsigned int start;
394  unsigned int end;
395 
396  if (isBarrel) {
397  // use layer and straw layer to distinguish which HashCalc
398  start = lay_min * 32 + str_lay_min;
399  end = start + nstr_layers;
401  for (unsigned int i = start; i < end; ++i) {
402  m_hash_calcs_barrel_indexes[i].first = hcIndex;
403  }
404 
405  } else {
406  // use layer alone to distinguish which HashCalc
407  start = lay_min;
408  end = start + nlayers;
410  for (unsigned int i = start; i < end; ++i) {
411  m_hash_calcs_endcap_indexes[i].first = hcIndex;
412  }
413 
414  }
415 
416 
417  // Set up HashCalc objet
418  HashCalc hc;
419  hc.m_hash = min_neg;
420 // hc.m_barrel_ec = exp_id[m_BARREL_EC_INDEX];
421  hc.m_deltaPhi = deltaPhi;
422  hc.m_layerMin = (*range)[m_LAYER_OR_WHEEL_INDEX].get_minimum();
423  hc.m_strLayerMin = (*range)[m_STRAW_LAYER_INDEX].get_minimum();
424 
425  hc.m_nStrawLayers = (*range)[m_STRAW_LAYER_INDEX].get_indices() *
426  (*range)[m_STRAW_INDEX].get_indices();
427  hc.m_nstraws = (*range)[m_STRAW_INDEX].get_indices();
428 
429 
430  m_hash_calcs[hcIndex] = hc;
431  hcIndex++;
432 
433  // Now repeat if there are both pos/neg
434 
435  if (two_sides) {
436  if (isBarrel) {
437  // use layer and straw layer to distinguish which HashCalc
438  start = lay_min * 32 + str_lay_min;
439  end = start + nstr_layers;
441  for (unsigned int i = start; i < end; ++i) {
442  m_hash_calcs_barrel_indexes[i].second = hcIndex;
443  }
444 
445  } else {
446  // use layer alone to distinguish which HashCalc
447  start = lay_min;
448  end = start + nlayers;
450  for (unsigned int i = start; i < end; ++i) {
451  m_hash_calcs_endcap_indexes[i].second = hcIndex;
452  }
453 
454  }
455 
456 
457 
458  // Flip sign for bec if 2 symmetric sides (ATLAS case, not TB)
460  exp_id[m_PHI_MODULE_INDEX],
461  exp_id[m_LAYER_OR_WHEEL_INDEX],
462  exp_id[m_STRAW_LAYER_INDEX],
463  exp_id[m_STRAW_INDEX]);
464  IdentifierHash min_pos = straw_hash_bin(min);
465  hc.m_hash = min_pos;
466  m_hash_calcs[hcIndex] = hc;
467  hcIndex++;
468  }
469  }
470 
471  // clear vector
473 }
474 
475 void
477  m_straw_vec.clear();
478 }
479 
480 void
482  // We init straw hashes separately to be able to reset the vector
483  // afterwards
484 
485  // straw hash - we do not keep a vec for the straws - too large
488  unsigned int nids = 0;
489  std::set<Identifier> ids;
490 
491  for (unsigned int i = 0; i < m_full_straw_range.size(); ++i) {
492  const Range& range = m_full_straw_range[i];
494  for (const auto & exp_id:rit) {
496  exp_id[m_PHI_MODULE_INDEX],
497  exp_id[m_LAYER_OR_WHEEL_INDEX],
498  exp_id[m_STRAW_LAYER_INDEX],
499  exp_id[m_STRAW_INDEX]);
500  if (!(ids.insert(id)).second) {
501  ATH_MSG_ERROR(" TRT_ID::init_hashes "
502  << " Error: duplicated id for straw id. nid " << nids
503  << " compact id " << show_to_string(id)
504  << " id " << std::string(exp_id));
505 
506  }
507  nids++;
508  }
509  }
510  if (ids.size() != m_straw_hash_max) {
511  ATH_MSG_ERROR(" TRT_ID::init_hashes "
512  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
513  << " hash max " << m_straw_hash_max);
514 
515  } else {
516  ATH_MSG_DEBUG(" TRT_ID::init_hashes "
517  << " straw hash max " << m_straw_hash_max);
518 
519  }
520 
521  nids = 0;
522  std::set<Identifier>::const_iterator first = ids.begin();
523  std::set<Identifier>::const_iterator last = ids.end();
524  for (; first != last && nids < m_straw_vec.size(); ++first) {
525  m_straw_vec[nids] = (*first);
526  nids++;
527  }
528 }
529 
530 int
532 
533  if (!m_dict) {
534  ATH_MSG_ERROR(" TRT_ID::initLevelsFromDict - dictionary NOT initialized ");
535 
536  return(1);
537  }
538 
539  // Find out which identifier field corresponds to each level. Use
540  // names to find each field/leve.
541 
542  m_INDET_INDEX = 999;
543  m_TRT_INDEX = 999;
544  m_BARREL_EC_INDEX = 999;
545  m_PHI_MODULE_INDEX = 999;
547  m_STRAW_LAYER_INDEX = 999;
548  m_STRAW_INDEX = 999;
549 
550  // Save index to a TRT region for unpacking
552  id << indet_field_value() << trt_field_value();
554  ATH_MSG_WARNING("TRT_ID::initLevelsFromDict - unable to initialize TRT_ID helper ");
555  ATH_MSG_WARNING("TRT_ID::initLevelsFromDict - we assume that the TRT does NOT exist for this layout ");
556 
557  return(1);
558  }
559 
560  // Find a TRT region
561  const IdDictField* field = m_dict->find_field("subdet");
562  if (field) {
563  m_INDET_INDEX = field->index();
564  } else {
565  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'subdet' field ");
566 
567  return(1);
568  }
569  field = m_dict->find_field("part");
570  if (field) {
571  m_TRT_INDEX = field->index();
572  } else {
573  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'part' field ");
574 
575  return(1);
576  }
577  field = m_dict->find_field("barrel_endcap");
578  if (field) {
579  m_BARREL_EC_INDEX = field->index();
580  } else {
581  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'barrel_endcap' field ");
582 
583 
584  return(1);
585  }
586  field = m_dict->find_field("phi_sector");
587  if (field) {
588  m_PHI_MODULE_INDEX = field->index();
589  } else {
590  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'phi_sector' field ");
591 
592 
593  return(1);
594  }
595  field = m_dict->find_field("layer_or_wheel");
596  if (field) {
597  m_LAYER_OR_WHEEL_INDEX = field->index();
598  } else {
599  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'layer' field ");
600 
601 
602  return(1);
603  }
604  field = m_dict->find_field("straw_layer");
605  if (field) {
606  m_STRAW_LAYER_INDEX = field->index();
607  } else {
608  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'straw_layer' field ");
609 
610 
611  return(1);
612  }
613  field = m_dict->find_field("straw");
614  if (field) {
615  m_STRAW_INDEX = field->index();
616  } else {
617  ATH_MSG_ERROR("TRT_ID::initLevelsFromDict - unable to find 'straw' field ");
618 
619 
620  return(1);
621  }
622 
623  // Set the field implementations: for bec, lay/disk, eta/phi mod
624 
625  const IdDictRegion& region = m_dict->region(m_trt_region_index);
626 
634 
635  ATH_MSG_DEBUG("decode index and bit fields for each level: ");
640  ATH_MSG_DEBUG("lay_wheel " << m_lay_wheel_impl.show_to_string());
643 
644  return(0);
645 }
646 
647 int
649  IdentifierHash& hash_id) const {
651  return(0);
652 }
653 
654 // From hash get Identifier
655 int
657  Identifier& id,
658  const IdContext* context) const {
659  int result = 1;
660 
661  id.clear();
662 
663  size_t begin = (context) ? context->begin_index() : 0;
664  // cannot get hash if end is 0:
665  size_t end = (context) ? context->end_index() : 0;
666  if (0 == begin) {
667  // No hashes yet for ids with prefixes
668  if (m_LAYER_OR_WHEEL_INDEX == end) {
669  if (hash_id < (unsigned int) (m_module_vec.end() - m_module_vec.begin())) {
670  id = m_module_vec[hash_id];
671  result = 0;
672  }
673  } else if (m_STRAW_LAYER_INDEX == end) {
674  if (hash_id < (unsigned int) (m_straw_layer_vec.end() - m_straw_layer_vec.begin())) {
675  id = m_straw_layer_vec[hash_id];
676  result = 0;
677  }
678  } else if (m_STRAW_INDEX == end) {
679  // Do not know how to calculate straw id from hash yet!!
680  std::cout << "Do not know how to calculate straw id from hash yet!!" << std::endl;
681  }
682  }
683  return(result);
684 }
685 
686 void
688  ExpandedIdentifier& exp_id,
689  const IdContext* context) const {
690  exp_id.clear();
691  exp_id << indet_field_value()
692  << trt_field_value()
693  << barrel_ec(id)
694  << phi_module(id)
695  << layer_or_wheel(id);
696  if (!context || context->end_index() >= m_STRAW_LAYER_INDEX) {
697  exp_id << straw_layer(id);
698  }
699  if (!context || context->end_index() == m_STRAW_INDEX) {
700  exp_id << straw(id);
701  }
702 }
703 
704 int
706  IdentifierHash& hash_id,
707  const IdContext* context) const {
708  // Get the hash code from either a vec (for modules and straw
709  // layers) or calculate it (straws). For the former, we convert to
710  // compact and call get_hash again. For the latter, we calculate
711  // the hash from the Identifier.
712 
713  int result = 1;
714 
715  hash_id = 0;
716  size_t begin = (context) ? context->begin_index() : 0;
717  size_t end = (context) ? context->end_index() : 0;
718 
719  if (0 == begin) {
720  // No hashes yet for ids with prefixes
721  if (m_LAYER_OR_WHEEL_INDEX == end) {
722  hash_id = module_hash(id);
723  if (hash_id.is_valid()) result = 0;
724  } else if (m_STRAW_LAYER_INDEX == end) {
725  hash_id = straw_layer_hash(id);
726  if (hash_id.is_valid()) result = 0;
727  } else if (context && context->end_index() == m_STRAW_INDEX) {
728  // Must calculate for straw hash
729  ExpandedIdentifier new_id;
730  get_expanded_id(id, new_id);
731  hash_id = m_full_straw_range.cardinalityUpTo(new_id);
732  result = 0;
733  }
734  }
735  return(result);
736 }
737 
738 int
740  // get max from dictionary
741  ExpandedIdentifier expId;
742  IdContext module_context1 = module_context();
743 
744  get_expanded_id(id, expId, &module_context1);
745  int result = 0;
746  for (unsigned int i = 0; i < m_full_straw_layer_range.size(); ++i) {
748  if (range.match(expId)) {
750  if (not field.empty()) {
751  int max = field.get_maximum();
752  result = result > max ? result : max;
753  }
754  }
755  }
756  return(result);
757 }
758 
759 int
760 TRT_ID::straw_max(const Identifier& id) const {
761  // get max from dictionary
762  ExpandedIdentifier expId;
763  IdContext straw_layer_context1 = straw_layer_context();
764 
765  get_expanded_id(id, expId, &straw_layer_context1);
766  for (unsigned int i = 0; i < m_full_straw_range.size(); ++i) {
767  const Range& range = m_full_straw_range[i];
768  if (range.match(expId)) {
770  if (not field.empty()) {
771  return(field.get_maximum());
772  }
773  }
774  }
775  return(-999); // default
776 }
777 
778 void
780  int nids = 0;
781  int nidsFailed = 0;
782 
784 
785 
786  // Check straw hashes
787  //bool debug = false;
788  for (unsigned int i = 0; i < m_straw_hash_max; ++i, ++nids) {
789  Identifier id = m_straw_vec[i];
791  IdentifierHash h2 = straw_hash(id);
792  //IdentifierHash h2 = straw_hash(id, debug);
793  if (h1 != h2) {
794  std::cout << "test_trt_ids - bad match: id, bin hash, hash: "
795  << nids << " "
796  << show_to_string(id) << " "
797  << h1 << " "
798  << h2 << std::endl;
799  nidsFailed++;
800  //debug = true;
801  }
802  Identifier id1 = straw_id(h1);
803  if (id != id1) {
804  std::cout << "test_trt_ids - bad match: id, bin hash, hash: "
805  << nids << " "
806  << show_to_string(id) << " "
807  << show_to_string(id1) << " "
808  << h1 << " "
809  << h2 << std::endl;
810  nidsFailed++;
811  }
812  if (i % 10000 == 5) {
813  std::cout << "test_trt_ids: id, bin hash, hash: "
814  << nids << " "
815  << show_to_string(id) << " "
816  << h1 << " "
817  << h2 << std::endl;
818  }
819  }
820 
821  std::cout << "Checked hash calculation for " << nids << " hashes and found "
822  << nidsFailed << " failures to match between binary lookup and calculation "
823  << std::endl;
824 
826 
827  nids = 0;
828  IdContext context = module_context();
830  const_id_iterator last = m_module_vec.end();
831  for (; first != last; ++first, ++nids) {
832  Identifier id = (*first);
833  ExpandedIdentifier exp_id;
834  get_expanded_id(id, exp_id, &context);
835  Identifier new_id = module_id(exp_id[m_BARREL_EC_INDEX],
836  exp_id[m_PHI_MODULE_INDEX],
837  exp_id[m_LAYER_OR_WHEEL_INDEX]);
838  if (id != new_id) {
839  ATH_MSG_ERROR("TRT_ID::test_trt_ids: module new and old compacts not equal. New/old/expanded ids "
840  << nids << " "
841  << show_to_string(new_id) << " " << show_to_string(id) << " "
842  << (std::string) exp_id);
843 
844  }
845 
846  IdentifierHash hashId;
847  if (get_hash(id, hashId, &context)) {
848  ATH_MSG_ERROR("Unable to set trt hash id for det elem "
849  << show_to_string(id) << " " << nids);
850 
851  }
852  new_id = module_id(hashId);
853 
854  if (id != new_id) {
855  ATH_MSG_ERROR("TRT_ID::test_trt_ids: module new and old compacts not equal. New/old/hash ids "
856  << nids << " "
857  << show_to_string(new_id) << " "
858  << show_to_string(id) << " "
859  << std::hex << hashId << std::dec);
860 
861  }
862  }
863 
864  nids = 0;
865  context = straw_layer_context();
866  first = m_straw_layer_vec.begin();
867  last = m_straw_layer_vec.end();
868  for (; first != last; ++first, ++nids) {
869  Identifier id = (*first);
870  ExpandedIdentifier exp_id;
871  get_expanded_id(id, exp_id, &context);
872  Identifier new_id = layer_id(exp_id[m_BARREL_EC_INDEX],
873  exp_id[m_PHI_MODULE_INDEX],
874  exp_id[m_LAYER_OR_WHEEL_INDEX],
875  exp_id[m_STRAW_LAYER_INDEX]);
876  if (id != new_id) {
877  ATH_MSG_ERROR("TRT_ID::test_trt_ids: straw layer new and old compacts not equal. New/old/expanded ids "
878  << show_to_string(new_id) << " " << show_to_string(id) << " "
879  << (std::string) exp_id);
880 
881  }
882 
883  IdContext strcontext = straw_context();
884 
885  // test straw ids
886  int nstraws = straw_max(id);
887  for (int i = 0; i < nstraws; ++i) {
888  id = straw_id(id, i);
889  get_expanded_id(id, exp_id, &strcontext);
890  new_id = straw_id(exp_id[m_BARREL_EC_INDEX],
891  exp_id[m_PHI_MODULE_INDEX],
892  exp_id[m_LAYER_OR_WHEEL_INDEX],
893  exp_id[m_STRAW_LAYER_INDEX],
894  exp_id[m_STRAW_INDEX]);
895  if (id != new_id) {
896  ATH_MSG_ERROR("TRT_ID::test_trt_ids: straw new and old compacts not equal. New/old/expanded ids "
897  << show_to_string(new_id) << " " << show_to_string(id) << " "
898  << (std::string) exp_id);
899 
900  }
901  }
902  }
903 
904  ATH_MSG_INFO("TRT_ID::test_trt_ids: Successfully tested "
905  << nids << " ids.");
906 
907 }
908 
909 
912  // Check if TRT_ID is valid for this layout
913  if (!m_is_valid) invalidMessage();
914 
916  if (m_STRAW_INDEX < id.fields()) {
918  id[m_PHI_MODULE_INDEX],
921  id[m_STRAW_INDEX]);
922  }
923  return(result);
924 }
925 
926 
927 inline IdContext
929  // Check if TRT_ID is valid for this layout
930  if (!m_is_valid) invalidMessage();
931 
933  return(IdContext(id, 0, m_BARREL_EC_INDEX));
934 }
935 
936 
937 IdContext
939  // Check if TRT_ID is valid for this layout
940  if (!m_is_valid) invalidMessage();
941 
943  return(IdContext(id, 0, m_LAYER_OR_WHEEL_INDEX));
944 }
945 
946 
947 IdContext
949  // Check if TRT_ID is valid for this layout
950  if (!m_is_valid) invalidMessage();
951 
953  return(IdContext(id, 0, m_STRAW_LAYER_INDEX));
954 }
955 
956 
957 IdContext
959  // Check if TRT_ID is valid for this layout
960  if (!m_is_valid) invalidMessage();
961 
963  return(IdContext(id, 0, m_STRAW_INDEX));
964 }
TRT_ID::m_bec_impl
IdDictFieldImplementation m_bec_impl
Definition: TRT_ID.h:369
IdDictMgr.h
TRT_ID::m_is_valid
bool m_is_valid
Definition: TRT_ID.h:321
AtlasDetectorID::indet_field_value
int indet_field_value() const
Provide efficient access to individual field values, for subclass idhelpers.
Definition: AtlasDetectorID.h:464
ConstRangeIterator
Definition: RangeIterator.h:46
TRT_ID::m_LAYER_OR_WHEEL_INDEX
size_type m_LAYER_OR_WHEEL_INDEX
Definition: TRT_ID.h:327
TRT_ID::m_full_straw_range
MultiRange m_full_straw_range
Definition: TRT_ID.h:331
TRT_ID::layer_id
Identifier layer_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
For an individual straw layer.
Definition: TRT_ID.h:494
IdDictDictionary::build_multirange
MultiRange build_multirange() const
Get MultiRange for full dictionary.
Definition: IdDictDictionary.cxx:309
TRT_ID::m_trt_region_index
size_type m_trt_region_index
Definition: TRT_ID.h:322
TRT::Hit::straw
@ straw
Definition: HitInfo.h:82
AtlasDetectorID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition: AtlasDetectorID.cxx:257
TRT_ID::m_hash_calcs
std::vector< HashCalc > m_hash_calcs
Definition: TRT_ID.h:363
TRT_ID::m_PHI_MODULE_INDEX
size_type m_PHI_MODULE_INDEX
Definition: TRT_ID.h:326
TRT_ID::module_id_checks
void module_id_checks(int barrel_ec, int phi_module, int layer_or_wheel) const
Definition: TRT_ID.cxx:66
get_generator_info.result
result
Definition: get_generator_info.py:21
TRT_ID::straw_max
int straw_max(const Identifier &id) const
Definition: TRT_ID.cxx:760
TRT_ID::m_full_straw_layer_range
MultiRange m_full_straw_layer_range
Definition: TRT_ID.h:332
TRT_ID::init_straw_hash_vector
void init_straw_hash_vector()
The init will use up ~2 MB of memory, so one should do init, use straw_id and then reset.
Definition: TRT_ID.cxx:481
TRT_ID::init_hashes
void init_hashes()
Definition: TRT_ID.cxx:245
TRT_ID::m_STRAW_LAYER_INDEX
size_type m_STRAW_LAYER_INDEX
Definition: TRT_ID.h:328
TRT_ID::m_phi_mod_impl
IdDictFieldImplementation m_phi_mod_impl
Definition: TRT_ID.h:370
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRT_ID::straw_hash
IdentifierHash straw_hash(Identifier straw_id) const
straw hash from id - optimized
Definition: TRT_ID.h:705
IdDictFieldImplementation::show_to_string
std::string show_to_string(void) const
Definition: IdDictFieldImplementation.cxx:32
IdDictDictionary::region
const IdDictRegion & region(size_t i) const
Region at index i.
Definition: IdDictDictionary.h:354
TRT_ID::m_straw_layer_vec
hash_vec m_straw_layer_vec
Definition: TRT_ID.h:339
TRT_ID::HashCalc::m_deltaPhi
size_type m_deltaPhi
Definition: TRT_ID.h:354
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:161
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
IdDictDictionary.h
MultiRange::cardinalityUpTo
size_type cardinalityUpTo(const ExpandedIdentifier &id) const
Definition: MultiRange.cxx:88
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:13
TRT_ID::get_straw_layer_hash_calc
int get_straw_layer_hash_calc(const ExpandedIdentifier &id, IdentifierHash &hash_id) const
Special method for timing tests.
Definition: TRT_ID.cxx:648
TRT_ID::barrel_ec_id_checks
void barrel_ec_id_checks(int barrel_ec) const
Definition: TRT_ID.cxx:50
IdContext::end_index
size_type end_index() const
Definition: IdContext.h:46
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
ReadBchFromCrest.begin
begin
Definition: ReadBchFromCrest.py:80
IdDictDictionary::find_field
const IdDictField * find_field(const std::string &name) const
Definition: IdDictDictionary.cxx:47
TRT_ID::m_BARREL_EC_INDEX
size_type m_BARREL_EC_INDEX
Definition: TRT_ID.h:325
IdentifierField::clear
void clear()
Set methods.
Definition: IdentifierField.cxx:224
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
TRT_ID::m_trt_impl
IdDictFieldImplementation m_trt_impl
Definition: TRT_ID.h:368
TRT_ID::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: TRT_ID.h:87
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
IdDictDictionary::name
const std::string & name() const
Dictionary name.
Definition: IdDictDictionary.h:336
AtlasDetectorID::trt_field_value
int trt_field_value() const
Definition: AtlasDetectorID.h:485
TRT_ID::m_TRT_INDEX
size_type m_TRT_INDEX
Definition: TRT_ID.h:324
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
TRT_ID::m_straw_hash_max
size_type m_straw_hash_max
Definition: TRT_ID.h:336
TRT_ID::m_str_lay_impl
IdDictFieldImplementation m_str_lay_impl
Definition: TRT_ID.h:372
TRT_ID::m_dict
const IdDictDictionary * m_dict
Definition: TRT_ID.h:330
TRT_ID::~TRT_ID
~TRT_ID()
CalibDbCompareRT.region_id
region_id
Definition: CalibDbCompareRT.py:67
IdDictRegion
Definition: IdDictRegion.h:21
TRT_ID::HashCalc::m_layerMin
size_type m_layerMin
Definition: TRT_ID.h:355
TRT_ID::module_hash
IdentifierHash module_hash(Identifier module_id) const
module hash from id - optimized
Definition: TRT_ID.h:669
TRT_ID::HashCalc::m_nStrawLayers
size_type m_nStrawLayers
Definition: TRT_ID.h:357
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
TRT_ID::m_hash_calcs_barrel_indexes
std::vector< intPair > m_hash_calcs_barrel_indexes
Definition: TRT_ID.h:364
TRT_ID::barrel_context
IdContext barrel_context() const
barrel_ec id
Definition: TRT_ID.cxx:928
TRT_ID::m_STRAW_INDEX
size_type m_STRAW_INDEX
Definition: TRT_ID.h:329
IdDictDictionary::find_region
const IdDictRegion * find_region(const std::string &region_name) const
Definition: IdDictDictionary.cxx:114
IdDictRegion::implementation
const IdDictFieldImplementation & implementation(size_t i) const
Definition: IdDictRegion.cxx:38
TRT_ID::HashCalc::m_nstraws
size_type m_nstraws
Definition: TRT_ID.h:358
IdentifierField::match
bool match(element_type value) const
The basic match operation Given a value, test to see if it satisfies the constraints for this field.
Definition: IdentifierField.cxx:71
IdDictMgr
Definition: IdDictMgr.h:16
IdContext::begin_index
size_type begin_index() const
Definition: IdContext.h:45
TRT_ID::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: TRT_ID.cxx:656
TRT_ID::straw
int straw(const Identifier &id) const
Definition: TRT_ID.h:833
TRT_ID::m_module_hash_max
size_type m_module_hash_max
Definition: TRT_ID.h:334
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IdContext.h
TRT_ID::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: TRT_ID.cxx:705
TRT_ID::m_INDET_INDEX
size_type m_INDET_INDEX
Definition: TRT_ID.h:323
lumiFormat.i
int i
Definition: lumiFormat.py:85
TRT_ID::module_context
IdContext module_context() const
module id
Definition: TRT_ID.cxx:938
TRT_ID::straw_hash_bin
IdentifierHash straw_hash_bin(Identifier straw_id) const
Definition: TRT_ID.h:760
TRT_ID::m_straw_layer_hash_max
size_type m_straw_layer_hash_max
Definition: TRT_ID.h:335
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT_ID::straw_id_checks
void straw_id_checks(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Definition: TRT_ID.cxx:85
TRT_ID::TRT_ID
TRT_ID()
Definition: TRT_ID.cxx:27
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
TRT_ID::m_indet_impl
IdDictFieldImplementation m_indet_impl
Definition: TRT_ID.h:367
TRT_ID::m_straw_vec
hash_vec m_straw_vec
Definition: TRT_ID.h:340
TRT_ID::HashCalc
Definition: TRT_ID.h:343
TRT_ID::get_expanded_id
void get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context=0) const
Definition: TRT_ID.cxx:687
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:797
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:824
TRT_ID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override final
Set the IdDictionary.
Definition: TRT_ID.cxx:128
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:815
IdentifierHash::is_valid
bool is_valid() const
Check if id is in a valid state.
TRT_ID::m_module_vec
hash_vec m_module_vec
Definition: TRT_ID.h:338
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:203
IdDictDictionary::get_label_value
int get_label_value(const std::string &field, const std::string &label, int &value) const
Definition: IdDictDictionary.cxx:92
TRT_ID::straw_layer_max
int straw_layer_max(const Identifier &id) const
Max values for each field (-999 == failure)
Definition: TRT_ID.cxx:739
TRT_ID::m_hash_calcs_endcap_indexes
std::vector< intPair > m_hash_calcs_endcap_indexes
Definition: TRT_ID.h:365
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
TRT_ID::straw_layer_context
IdContext straw_layer_context() const
straw_layer id
Definition: TRT_ID.cxx:948
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
IdentifierHash.h
RangeIterator.h
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:29
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:806
TRT_ID::test_trt_ids
void test_trt_ids()
Tests of packing.
Definition: TRT_ID.cxx:779
IdDictDictionary
Definition: IdDictDictionary.h:31
TRT_ID::m_full_module_range
MultiRange m_full_module_range
Definition: TRT_ID.h:333
MultiRange::match
int match(const ExpandedIdentifier &id) const
Match an identifier.
Definition: MultiRange.cxx:57
TRT_ID::straw_context
IdContext straw_context() const
straw id
Definition: TRT_ID.cxx:958
TRT_ID::m_straw_impl
IdDictFieldImplementation m_straw_impl
Definition: TRT_ID.h:373
AtlasDetectorID::reinitialize
bool reinitialize(const IdDictMgr &dict_mgr)
Test whether an idhelper should be reinitialized based on the change of tags.
Definition: AtlasDetectorID.cxx:223
TRT_ID::initLevelsFromDict
int initLevelsFromDict()
Definition: TRT_ID.cxx:531
IdDictField.h
IdDictMgr::find_dictionary
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:116
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:367
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MultiRange::size
size_type size() const
Definition: MultiRange.cxx:70
DeMoScan.first
bool first
Definition: DeMoScan.py:534
TRT_ID::layer_id_checks
void layer_id_checks(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
Definition: TRT_ID.cxx:106
IdentifierField
This is the individual specification for the range of one ExpandedIdentifier IdentifierField.
Definition: IdentifierField.h:83
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
ExpandedIdentifier::clear
void clear()
Erase all fields.
TRT_ID::m_lay_wheel_impl
IdDictFieldImplementation m_lay_wheel_impl
Definition: TRT_ID.h:371
TRT_ID::HashCalc::m_hash
IdentifierHash m_hash
Definition: TRT_ID.h:353
TRT_ID::reset_straw_hash_vector
void reset_straw_hash_vector()
Definition: TRT_ID.cxx:476
TRT_ID::invalidMessage
void invalidMessage() const
Definition: TRT_ID.h:780
IdDictRegion.h
TRT_ID::m_barrel_field
Range::field m_barrel_field
Definition: TRT_ID.h:337
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:105
IdDictField
Definition: IdDictField.h:16
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition: MultiRange.cxx:82
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
IdentifierField::add_value
void add_value(element_type value)
Definition: IdentifierField.cxx:250
TRT_ID::HashCalc::m_strLayerMin
size_type m_strLayerMin
Definition: TRT_ID.h:356
AtlasDetectorID
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Definition: AtlasDetectorID.h:52
TRT_ID::straw_layer_hash
IdentifierHash straw_layer_hash(Identifier straw_layer_id) const
straw_layer hash from id - optimized
Definition: TRT_ID.h:687
TRT_ID::module_id
Identifier module_id(int barrel_ec, int phi_module, int layer_or_wheel) const
For an individual module phi sector.
Definition: TRT_ID.h:442
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:575
Identifier
Definition: IdentifierFieldParser.cxx:14