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 "GaudiKernel/MsgStream.h"
12 
13 #include "InDetIdentifier/TRT_ID.h"
15 #include "IdDict/IdDictField.h"
16 #include "IdDict/IdDictMgr.h"
17 #include "IdDict/IdDictRegion.h"
20 #include "Identifier/IdContext.h"
21 #include <set>
22 #include <algorithm>
23 #include <iostream>
24 #include <cassert>
25 
26 
28 
30  :
31  AtlasDetectorID("TRT_ID", "trt"),
32  m_is_valid(true),
33  m_trt_region_index(0),
34  m_INDET_INDEX(0),
35  m_TRT_INDEX(1),
36  m_BARREL_EC_INDEX(2),
37  m_PHI_MODULE_INDEX(3),
38  m_LAYER_OR_WHEEL_INDEX(4),
39  m_STRAW_LAYER_INDEX(5),
40  m_STRAW_INDEX(6),
41  m_dict(nullptr),
42  m_module_hash_max(0),
43  m_straw_layer_hash_max(0),
44  m_straw_hash_max(0) {
47 }
48 
49 TRT_ID::~TRT_ID() = default;
50 
51 void
52 TRT_ID::barrel_ec_id_checks(int barrel_ec) const {
53  // Check that id is within allowed range
54 
55  // Fill expanded id
57 
59 
60  if (!m_full_module_range.match(id)) { // module range check is sufficient
61  MsgStream log(m_msgSvc, "TRT_ID");
62  log << MSG::ERROR << " TRT_ID::barrel_ec_id result is NOT ok. ID, range "
63  << (std::string) id << " "
64  << (std::string) m_full_module_range << endmsg;
65  }
66 }
67 
68 void
70  int phi_module,
71  int layer_or_wheel) const {
72  // Check that id is within allowed range
73 
74  // Fill expanded id
76 
79 
80  if (!m_full_module_range.match(id)) { // module range check is sufficient
81  MsgStream log(m_msgSvc, "TRT_ID");
82  log << MSG::ERROR << " TRT_ID::module_id result is NOT ok. ID, range "
83  << (std::string) id << " "
84  << (std::string) m_full_module_range << endmsg;
85  }
86 }
87 
88 void
90  int phi_module,
91  int layer_or_wheel,
92  int straw_layer,
93  int straw) const {
94  // Check that id is within allowed range
95 
96  // Build identifier
98 
101 
102  if (!m_full_straw_range.match(id)) {
103  MsgStream log(m_msgSvc, "TRT_ID");
104  log << MSG::ERROR << " TRT_ID::straw_id result is NOT ok. ID, range "
105  << (std::string) id << " "
106  << (std::string) m_full_straw_range << endmsg;
107  }
108 }
109 
110 void
112  int phi_module,
113  int layer_or_wheel,
114  int straw_layer) const {
115  // Check that id is within allowed range
116 
117  // Build identifier
119 
122 
123  if (!m_full_straw_layer_range.match(id)) {
124  MsgStream log(m_msgSvc, "TRT_ID");
125  log << MSG::ERROR << " TRT_ID::layer_id result is NOT ok. ID, range "
126  << (std::string) id << " "
127  << (std::string) m_full_straw_layer_range << endmsg;
128 
129  }
130 }
131 
132 
133 int
135  MsgStream log(m_msgSvc, "TRT_ID");
136  log << MSG::INFO << "Initialize from dictionary msgSvc " << m_msgSvc << endmsg;
137  // Check whether this helper should be reinitialized
138  if (!reinitialize(dict_mgr)) {
139  log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg;
140  return(0);
141  } else {
142  log << MSG::DEBUG << "(Re)initialize" << endmsg;
143  }
144 
145  // init base object
147  m_is_valid = false;
148  return(1);
149  }
150 
151 
152  // Register version of InnerDetector dictionary
153  if (register_dict_tag(dict_mgr, "InnerDetector")) {
154  m_is_valid = false;
155  return(1);
156  }
157 
158 
159  m_dict = dict_mgr.find_dictionary("InnerDetector");
160  if (!m_dict) {
161  log << MSG::ERROR << " TRT_ID::initialize_from_dict - cannot access InnerDetector dictionary "
162  << endmsg;
163  m_is_valid = false;
164  return 1;
165  }
166 
167  // Initialize the field indices
168  if (initLevelsFromDict()) {
169  m_is_valid = false;
170  return(1);
171  }
172 
173 
174  //
175  // Set barrel field for testing is_barrel
176  //
177  int barrel_value;
179  // negative barrel
180  if (m_dict->get_label_value("barrel_endcap", "negative_barrel", barrel_value)) {
181  log << MSG::ERROR << "Could not get value for label 'barrel' of field 'barrel_endcap' in dictionary "
182  << m_dict->name()
183  << endmsg;
184 
185  m_is_valid = false;
186  return(1);
187  }
188  m_barrel_field.add_value(barrel_value);
189  // negative barrel
190  if (m_dict->get_label_value("barrel_endcap", "positive_barrel", barrel_value)) {
191  log << MSG::ERROR << "Could not get value for label 'barrel' of field 'barrel_endcap' in dictionary "
192  << m_dict->name()
193  << endmsg;
194 
195  m_is_valid = false;
196  return(1);
197  }
198  m_barrel_field.add_value(barrel_value);
199  log << MSG::DEBUG << " TRT_ID::initialize_from_dict "
200  << "Set barrel field values: "
201  << (std::string) m_barrel_field
202  << endmsg;
203 
204 
205  //
206  // Build multirange for the valid set of identifiers
207  //
208 
209 
210  // Find value for the field InnerDetector
211  const IdDictDictionary* atlasDict = dict_mgr.find_dictionary("ATLAS");
212 
213  int inDetField = -1;
214  if (atlasDict->get_label_value("subdet", "InnerDetector", inDetField)) {
215  log << MSG::ERROR << "Could not get value for label 'InnerDetector' of field 'subdet' in dictionary "
216  << atlasDict->name()
217  << endmsg;
218 
219  m_is_valid = false;
220  return(1);
221  }
222 
223  // Find value for the field TRT
224  int trtField = -1;
225  if (m_dict->get_label_value("part", "TRT", trtField)) {
226  log << MSG::ERROR << "Could not get value for label 'TRT' of field 'part' in dictionary "
227  << m_dict->name()
228  << endmsg;
229 
230  m_is_valid = false;
231  return(1);
232  }
233  log << MSG::DEBUG << " TRT_ID::initialize_from_dict "
234  << "Found field values: InDet/TRT "
235  << inDetField << "/"
236  << trtField
237  << endmsg;
238 
239 
240  // Set up id for region and range prefix
242  region_id.add(inDetField);
243  region_id.add(trtField);
244  Range prefix;
248 
249  init_hashes();
250 
251  log << MSG::DEBUG << " TRT_ID::initialize_from_dict "
252  << endmsg;
253  log << MSG::DEBUG << "Module range -> " << (std::string) m_full_module_range
254  << endmsg;
255  log << MSG::DEBUG << "Straw layer range -> " << (std::string) m_full_straw_layer_range
256  << endmsg;
257  log << MSG::DEBUG << "Straw range -> " << (std::string) m_full_straw_range
258  << endmsg;
259 
260 
261  return 0;
262 }
263 
264 void
266  //
267  // create two vecs (module and straw layer) to retrieve the hashes
268  // for compact ids
269  //
270 
271  // module hash
272  MsgStream log(m_msgSvc, "TRT_ID");
273 
274  log << MSG::DEBUG << "Module range -> " << (std::string) m_full_module_range
275  << endmsg;
276 
277 
278 
279 
282  unsigned int nids = 0;
283  std::set<Identifier> ids;
284  for (unsigned int i = 0; i < m_full_module_range.size(); ++i) {
285  const Range& range = m_full_module_range[i];
287  for (const auto & exp_id: rit) {
289  exp_id[m_PHI_MODULE_INDEX],
290  exp_id[m_LAYER_OR_WHEEL_INDEX]);
291  if (!(ids.insert(id)).second) {
292  log << MSG::ERROR << " TRT_ID::init_hashes "
293  << " Error: duplicated id for module id. nid " << nids
294  << " compact id " << show_to_string(id)
295  << " id " << std::string(exp_id)
296  << endmsg;
297 
298  }
299  nids++;
300  }
301  }
302  if (ids.size() != m_module_hash_max) {
303  log << MSG::ERROR << " TRT_ID::init_hashes "
304  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
305  << " hash max " << m_module_hash_max
306  << endmsg;
307 
308  } else {
309  log << MSG::DEBUG << " TRT_ID::init_hashes "
310  << " module hash max " << m_module_hash_max
311  << endmsg;
312 
313  }
314 
315  nids = 0;
316  std::set<Identifier>::const_iterator first = ids.begin();
317  std::set<Identifier>::const_iterator last = ids.end();
318  for (; first != last && nids < m_module_vec.size(); ++first) {
319  m_module_vec[nids] = (*first);
320  nids++;
321  }
322 
323  // straw_layer hash
326  nids = 0;
327  ids.clear();
328  for (unsigned int i = 0; i < m_full_straw_layer_range.size(); ++i) {
331  for (const auto & exp_id: rit) {
333  exp_id[m_PHI_MODULE_INDEX],
334  exp_id[m_LAYER_OR_WHEEL_INDEX],
335  exp_id[m_STRAW_LAYER_INDEX]);
336  if (!(ids.insert(id)).second) {
337  log << MSG::ERROR << " TRT_ID::init_hashes "
338  << " Error: duplicated id for straw layer id. nid " << nids
339  << " compact id " << show_to_string(id)
340  << " id " << std::string(exp_id)
341  << endmsg;
342 
343  nids++;
344  }
345  }
346  }
347 
348  if (ids.size() != m_straw_layer_hash_max) {
349  log << MSG::ERROR << " TRT_ID::init_hashes "
350  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
351  << " hash max " << m_straw_layer_hash_max
352  << endmsg;
353  } else {
354  log << MSG::DEBUG << " TRT_ID::init_hashes "
355  << " straw layer hash max " << m_straw_layer_hash_max
356  << endmsg;
357 
358  }
359 
360  nids = 0;
361  first = ids.begin();
362  last = ids.end();
363  for (; first != last && nids < m_straw_layer_vec.size(); ++first) {
364  m_straw_layer_vec[nids] = (*first);
365  nids++;
366  }
367 
368 
369  // Init vector for binary lookup
371 
372 
373  // Setup for hash calculation for straw ids
374 
375 
376  // We use a HashCalc object to save the information needed to
377  // calculate the hash from the decoded values of a straw id.
378  //
379  // The number of HashCalc objects needed are 2x the number of
380  // ranges - one for each pos/neg. There are then two additional
381  // lookup tables, one for each of barrel and endcap, to access the
382  // index into the HashCalc table. Here we set up the HashCalc
383  // table and the additional tables for accessing the index.
384 
385  // Set up vector as lookup table for hash calculation.
386  unsigned int hcIndex = 0;
387  unsigned int nRanges = m_full_straw_range.size();
388  m_hash_calcs.resize(2 * nRanges); // allow for pos/neg
389 
390 // std::vector<bool> startHashFound(4,false);
391 // m_beStartHash.resize(4);
392 
393 
394  for (unsigned int i = 0; i < m_full_straw_range.size(); ++i) {
395  const Range* range = &m_full_straw_range[i];
396  ExpandedIdentifier exp_id = range->minimum();
398  exp_id[m_PHI_MODULE_INDEX],
399  exp_id[m_LAYER_OR_WHEEL_INDEX],
400  exp_id[m_STRAW_LAYER_INDEX],
401  exp_id[m_STRAW_INDEX]);
402  IdentifierHash min_neg = straw_hash_bin(min);
403 
404  // Calculate the offset in phi
405  Identifier next_phi = straw_id(exp_id[m_BARREL_EC_INDEX],
406  exp_id[m_PHI_MODULE_INDEX] + 1,
407  exp_id[m_LAYER_OR_WHEEL_INDEX],
408  exp_id[m_STRAW_LAYER_INDEX],
409  exp_id[m_STRAW_INDEX]);
410  IdentifierHash deltaPhi = straw_hash_bin(next_phi) - min_neg;
411 
412  // barrel or endcap
414 
415 
416  // both pos and neg available?
417  bool two_sides = ((*range)[m_BARREL_EC_INDEX].get_indices() == 2);
418 
419  // fill lookup table with index to HashCalc
420  unsigned int lay_min = (*range)[m_LAYER_OR_WHEEL_INDEX].get_minimum();
421  unsigned int nlayers = (*range)[m_LAYER_OR_WHEEL_INDEX].get_indices();
422  unsigned int str_lay_min = (*range)[m_STRAW_LAYER_INDEX].get_minimum();
423  unsigned int nstr_layers = (*range)[m_STRAW_LAYER_INDEX].get_indices();
424  unsigned int start;
425  unsigned int end;
426 
427  if (isBarrel) {
428  // use layer and straw layer to distinguish which HashCalc
429  start = lay_min * 32 + str_lay_min;
430  end = start + nstr_layers;
432  for (unsigned int i = start; i < end; ++i) {
433  m_hash_calcs_barrel_indexes[i].first = hcIndex;
434  }
435 
436  } else {
437  // use layer alone to distinguish which HashCalc
438  start = lay_min;
439  end = start + nlayers;
441  for (unsigned int i = start; i < end; ++i) {
442  m_hash_calcs_endcap_indexes[i].first = hcIndex;
443  }
444 
445  }
446 
447 
448  // Set up HashCalc objet
449  HashCalc hc;
450  hc.m_hash = min_neg;
451 // hc.m_barrel_ec = exp_id[m_BARREL_EC_INDEX];
452  hc.m_deltaPhi = deltaPhi;
453  hc.m_layerMin = (*range)[m_LAYER_OR_WHEEL_INDEX].get_minimum();
454  hc.m_strLayerMin = (*range)[m_STRAW_LAYER_INDEX].get_minimum();
455 
456  hc.m_nStrawLayers = (*range)[m_STRAW_LAYER_INDEX].get_indices() *
457  (*range)[m_STRAW_INDEX].get_indices();
458  hc.m_nstraws = (*range)[m_STRAW_INDEX].get_indices();
459 
460 
461  m_hash_calcs[hcIndex] = hc;
462  hcIndex++;
463 
464  // Now repeat if there are both pos/neg
465 
466  if (two_sides) {
467  if (isBarrel) {
468  // use layer and straw layer to distinguish which HashCalc
469  start = lay_min * 32 + str_lay_min;
470  end = start + nstr_layers;
472  for (unsigned int i = start; i < end; ++i) {
473  m_hash_calcs_barrel_indexes[i].second = hcIndex;
474  }
475 
476  } else {
477  // use layer alone to distinguish which HashCalc
478  start = lay_min;
479  end = start + nlayers;
481  for (unsigned int i = start; i < end; ++i) {
482  m_hash_calcs_endcap_indexes[i].second = hcIndex;
483  }
484 
485  }
486 
487 
488 
489  // Flip sign for bec if 2 symmetric sides (ATLAS case, not TB)
491  exp_id[m_PHI_MODULE_INDEX],
492  exp_id[m_LAYER_OR_WHEEL_INDEX],
493  exp_id[m_STRAW_LAYER_INDEX],
494  exp_id[m_STRAW_INDEX]);
495  IdentifierHash min_pos = straw_hash_bin(min);
496  hc.m_hash = min_pos;
497  m_hash_calcs[hcIndex] = hc;
498  hcIndex++;
499  }
500  }
501 
502  // clear vector
504 }
505 
506 void
508  m_straw_vec.clear();
509 }
510 
511 void
513  // We init straw hashes separately to be able to reset the vector
514  // afterwards
515 
516  MsgStream log(m_msgSvc, "TRT_ID");
517 
518  // straw hash - we do not keep a vec for the straws - too large
521  unsigned int nids = 0;
522  std::set<Identifier> ids;
523 
524  for (unsigned int i = 0; i < m_full_straw_range.size(); ++i) {
525  const Range& range = m_full_straw_range[i];
527  for (const auto & exp_id:rit) {
529  exp_id[m_PHI_MODULE_INDEX],
530  exp_id[m_LAYER_OR_WHEEL_INDEX],
531  exp_id[m_STRAW_LAYER_INDEX],
532  exp_id[m_STRAW_INDEX]);
533  if (!(ids.insert(id)).second) {
534  log << MSG::ERROR << " TRT_ID::init_hashes "
535  << " Error: duplicated id for straw id. nid " << nids
536  << " compact id " << show_to_string(id)
537  << " id " << std::string(exp_id)
538  << endmsg;
539 
540  }
541  nids++;
542  }
543  }
544  if (ids.size() != m_straw_hash_max) {
545  log << MSG::ERROR << " TRT_ID::init_hashes "
546  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
547  << " hash max " << m_straw_hash_max
548  << endmsg;
549 
550  } else {
551  log << MSG::DEBUG << " TRT_ID::init_hashes "
552  << " straw hash max " << m_straw_hash_max
553  << endmsg;
554 
555  }
556 
557  nids = 0;
558  std::set<Identifier>::const_iterator first = ids.begin();
559  std::set<Identifier>::const_iterator last = ids.end();
560  for (; first != last && nids < m_straw_vec.size(); ++first) {
561  m_straw_vec[nids] = (*first);
562  nids++;
563  }
564 }
565 
566 int
568  MsgStream log(m_msgSvc, "TRT_ID");
569 
570  if (!m_dict) {
571  log << MSG::ERROR << " TRT_ID::initLevelsFromDict - dictionary NOT initialized "
572  << endmsg;
573 
574  return(1);
575  }
576 
577  // Find out which identifier field corresponds to each level. Use
578  // names to find each field/leve.
579 
580  m_INDET_INDEX = 999;
581  m_TRT_INDEX = 999;
582  m_BARREL_EC_INDEX = 999;
583  m_PHI_MODULE_INDEX = 999;
585  m_STRAW_LAYER_INDEX = 999;
586  m_STRAW_INDEX = 999;
587 
588  // Save index to a TRT region for unpacking
590  id << indet_field_value() << trt_field_value();
592  log << MSG::WARNING << "TRT_ID::initLevelsFromDict - unable to initialize TRT_ID helper "
593  << endmsg;
594  log << MSG::WARNING << "TRT_ID::initLevelsFromDict - we assume that the TRT does NOT exist for this layout "
595  << endmsg;
596 
597  return(1);
598  }
599 
600  // Find a TRT region
601  IdDictField* field = m_dict->find_field("subdet");
602  if (field) {
603  m_INDET_INDEX = field->index();
604  } else {
605  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'subdet' field "
606  << endmsg;
607 
608  return(1);
609  }
610  field = m_dict->find_field("part");
611  if (field) {
612  m_TRT_INDEX = field->index();
613  } else {
614  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'part' field "
615  << endmsg;
616 
617  return(1);
618  }
619  field = m_dict->find_field("barrel_endcap");
620  if (field) {
621  m_BARREL_EC_INDEX = field->index();
622  } else {
623  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'barrel_endcap' field "
624  << endmsg;
625 
626 
627  return(1);
628  }
629  field = m_dict->find_field("phi_sector");
630  if (field) {
631  m_PHI_MODULE_INDEX = field->index();
632  } else {
633  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'phi_sector' field "
634  << endmsg;
635 
636 
637  return(1);
638  }
639  field = m_dict->find_field("layer_or_wheel");
640  if (field) {
641  m_LAYER_OR_WHEEL_INDEX = field->index();
642  } else {
643  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'layer' field "
644  << endmsg;
645 
646 
647  return(1);
648  }
649  field = m_dict->find_field("straw_layer");
650  if (field) {
651  m_STRAW_LAYER_INDEX = field->index();
652  } else {
653  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'straw_layer' field "
654  << endmsg;
655 
656 
657  return(1);
658  }
659  field = m_dict->find_field("straw");
660  if (field) {
661  m_STRAW_INDEX = field->index();
662  } else {
663  log << MSG::ERROR << "TRT_ID::initLevelsFromDict - unable to find 'straw' field "
664  << endmsg;
665 
666 
667  return(1);
668  }
669 
670  // Set the field implementations: for bec, lay/disk, eta/phi mod
671 
672  const IdDictRegion& region = m_dict->region(m_trt_region_index);
673 
681 
682  log << MSG::DEBUG << "decode index and bit fields for each level: " << endmsg;
683  log << MSG::DEBUG << "indet " << m_indet_impl.show_to_string() << endmsg;
684  log << MSG::DEBUG << "trt " << m_trt_impl.show_to_string() << endmsg;
685  log << MSG::DEBUG << "bec " << m_bec_impl.show_to_string() << endmsg;
686  log << MSG::DEBUG << "phi_mod " << m_phi_mod_impl.show_to_string() << endmsg;
687  log << MSG::DEBUG << "lay_wheel " << m_lay_wheel_impl.show_to_string() << endmsg;
688  log << MSG::DEBUG << "str_lay " << m_str_lay_impl.show_to_string() << endmsg;
689  log << MSG::DEBUG << "straw " << m_straw_impl.show_to_string() << endmsg;
690 
691  return(0);
692 }
693 
694 int
696  IdentifierHash& hash_id) const {
698  return(0);
699 }
700 
701 // From hash get Identifier
702 int
704  Identifier& id,
705  const IdContext* context) const {
706  int result = 1;
707 
708  id.clear();
709 
710  size_t begin = (context) ? context->begin_index() : 0;
711  // cannot get hash if end is 0:
712  size_t end = (context) ? context->end_index() : 0;
713  if (0 == begin) {
714  // No hashes yet for ids with prefixes
715  if (m_LAYER_OR_WHEEL_INDEX == end) {
716  if (hash_id < (unsigned int) (m_module_vec.end() - m_module_vec.begin())) {
717  id = m_module_vec[hash_id];
718  result = 0;
719  }
720  } else if (m_STRAW_LAYER_INDEX == end) {
721  if (hash_id < (unsigned int) (m_straw_layer_vec.end() - m_straw_layer_vec.begin())) {
722  id = m_straw_layer_vec[hash_id];
723  result = 0;
724  }
725  } else if (m_STRAW_INDEX == end) {
726  // Do not know how to calculate straw id from hash yet!!
727  std::cout << "Do not know how to calculate straw id from hash yet!!" << std::endl;
728  }
729  }
730  return(result);
731 }
732 
733 void
735  ExpandedIdentifier& exp_id,
736  const IdContext* context) const {
737  exp_id.clear();
738  exp_id << indet_field_value()
739  << trt_field_value()
740  << barrel_ec(id)
741  << phi_module(id)
742  << layer_or_wheel(id);
743  if (!context || context->end_index() >= m_STRAW_LAYER_INDEX) {
744  exp_id << straw_layer(id);
745  }
746  if (!context || context->end_index() == m_STRAW_INDEX) {
747  exp_id << straw(id);
748  }
749 }
750 
751 int
753  IdentifierHash& hash_id,
754  const IdContext* context) const {
755  // Get the hash code from either a vec (for modules and straw
756  // layers) or calculate it (straws). For the former, we convert to
757  // compact and call get_hash again. For the latter, we calculate
758  // the hash from the Identifier.
759 
760  int result = 1;
761 
762  hash_id = 0;
763  size_t begin = (context) ? context->begin_index() : 0;
764  size_t end = (context) ? context->end_index() : 0;
765 
766  if (0 == begin) {
767  // No hashes yet for ids with prefixes
768  if (m_LAYER_OR_WHEEL_INDEX == end) {
769  hash_id = module_hash(id);
770  if (hash_id.is_valid()) result = 0;
771  } else if (m_STRAW_LAYER_INDEX == end) {
772  hash_id = straw_layer_hash(id);
773  if (hash_id.is_valid()) result = 0;
774  } else if (context && context->end_index() == m_STRAW_INDEX) {
775  // Must calculate for straw hash
776  ExpandedIdentifier new_id;
777  get_expanded_id(id, new_id);
778  hash_id = m_full_straw_range.cardinalityUpTo(new_id);
779  result = 0;
780  }
781  }
782  return(result);
783 }
784 
785 int
787  // get max from dictionary
788  ExpandedIdentifier expId;
789  IdContext module_context1 = module_context();
790 
791  get_expanded_id(id, expId, &module_context1);
792  int result = 0;
793  for (unsigned int i = 0; i < m_full_straw_layer_range.size(); ++i) {
795  if (range.match(expId)) {
797  if (not field.empty()) {
798  int max = field.get_maximum();
799  result = result > max ? result : max;
800  }
801  }
802  }
803  return(result);
804 }
805 
806 int
807 TRT_ID::straw_max(const Identifier& id) const {
808  // get max from dictionary
809  ExpandedIdentifier expId;
810  IdContext straw_layer_context1 = straw_layer_context();
811 
812  get_expanded_id(id, expId, &straw_layer_context1);
813  for (unsigned int i = 0; i < m_full_straw_range.size(); ++i) {
814  const Range& range = m_full_straw_range[i];
815  if (range.match(expId)) {
817  if (not field.empty()) {
818  return(field.get_maximum());
819  }
820  }
821  }
822  return(-999); // default
823 }
824 
825 void
827  MsgStream log(m_msgSvc, "TRT_ID");
828  int nids = 0;
829  int nidsFailed = 0;
830 
832 
833 
834  // Check straw hashes
835  //bool debug = false;
836  for (unsigned int i = 0; i < m_straw_hash_max; ++i, ++nids) {
837  Identifier id = m_straw_vec[i];
839  IdentifierHash h2 = straw_hash(id);
840  //IdentifierHash h2 = straw_hash(id, debug);
841  if (h1 != h2) {
842  std::cout << "test_trt_ids - bad match: id, bin hash, hash: "
843  << nids << " "
844  << show_to_string(id) << " "
845  << h1 << " "
846  << h2 << std::endl;
847  nidsFailed++;
848  //debug = true;
849  }
850  Identifier id1 = straw_id(h1);
851  if (id != id1) {
852  std::cout << "test_trt_ids - bad match: id, bin hash, hash: "
853  << nids << " "
854  << show_to_string(id) << " "
855  << show_to_string(id1) << " "
856  << h1 << " "
857  << h2 << std::endl;
858  nidsFailed++;
859  }
860  if (i % 10000 == 5) {
861  std::cout << "test_trt_ids: id, bin hash, hash: "
862  << nids << " "
863  << show_to_string(id) << " "
864  << h1 << " "
865  << h2 << std::endl;
866  }
867  }
868 
869  std::cout << "Checked hash calculation for " << nids << " hashes and found "
870  << nidsFailed << " failures to match between binary lookup and calculation "
871  << std::endl;
872 
874 
875  nids = 0;
876  IdContext context = module_context();
878  const_id_iterator last = m_module_vec.end();
879  for (; first != last; ++first, ++nids) {
880  Identifier id = (*first);
881  ExpandedIdentifier exp_id;
882  get_expanded_id(id, exp_id, &context);
883  Identifier new_id = module_id(exp_id[m_BARREL_EC_INDEX],
884  exp_id[m_PHI_MODULE_INDEX],
885  exp_id[m_LAYER_OR_WHEEL_INDEX]);
886  if (id != new_id) {
887  log << MSG::ERROR << "TRT_ID::test_trt_ids: module new and old compacts not equal. New/old/expanded ids "
888  << nids << " "
889  << show_to_string(new_id) << " " << show_to_string(id) << " "
890  << (std::string) exp_id << endmsg;
891 
892  }
893 
894  IdentifierHash hashId;
895  if (get_hash(id, hashId, &context)) {
896  log << MSG::ERROR << "Unable to set trt hash id for det elem "
897  << show_to_string(id) << " " << nids
898  << endmsg;
899 
900  }
901  new_id = module_id(hashId);
902 
903  if (id != new_id) {
904  log << MSG::ERROR << "TRT_ID::test_trt_ids: module new and old compacts not equal. New/old/hash ids "
905  << nids << " "
906  << show_to_string(new_id) << " "
907  << show_to_string(id) << " " << MSG::hex
908  << hashId << MSG::dec
909  << endmsg;
910 
911  }
912  }
913 
914  nids = 0;
915  context = straw_layer_context();
916  first = m_straw_layer_vec.begin();
917  last = m_straw_layer_vec.end();
918  for (; first != last; ++first, ++nids) {
919  Identifier id = (*first);
920  ExpandedIdentifier exp_id;
921  get_expanded_id(id, exp_id, &context);
922  Identifier new_id = layer_id(exp_id[m_BARREL_EC_INDEX],
923  exp_id[m_PHI_MODULE_INDEX],
924  exp_id[m_LAYER_OR_WHEEL_INDEX],
925  exp_id[m_STRAW_LAYER_INDEX]);
926  if (id != new_id) {
927  log << MSG::ERROR << "TRT_ID::test_trt_ids: straw layer new and old compacts not equal. New/old/expanded ids "
928  << show_to_string(new_id) << " " << show_to_string(id) << " "
929  << (std::string) exp_id << endmsg;
930 
931  }
932 
933  IdContext strcontext = straw_context();
934 
935  // test straw ids
936  int nstraws = straw_max(id);
937  for (int i = 0; i < nstraws; ++i) {
938  id = straw_id(id, i);
939  get_expanded_id(id, exp_id, &strcontext);
940  new_id = straw_id(exp_id[m_BARREL_EC_INDEX],
941  exp_id[m_PHI_MODULE_INDEX],
942  exp_id[m_LAYER_OR_WHEEL_INDEX],
943  exp_id[m_STRAW_LAYER_INDEX],
944  exp_id[m_STRAW_INDEX]);
945  if (id != new_id) {
946  log << MSG::ERROR << "TRT_ID::test_trt_ids: straw new and old compacts not equal. New/old/expanded ids "
947  << show_to_string(new_id) << " " << show_to_string(id) << " "
948  << (std::string) exp_id << endmsg;
949 
950  }
951  }
952  }
953 
954  log << MSG::INFO << "TRT_ID::test_trt_ids: Successful tested "
955  << nids << " ids. "
956  << endmsg;
957 
958 }
959 
960 
963  // Check if TRT_ID is valid for this layout
964  if (!m_is_valid) invalidMessage();
965 
967  if (m_STRAW_INDEX < id.fields()) {
969  id[m_PHI_MODULE_INDEX],
972  id[m_STRAW_INDEX]);
973  }
974  return(result);
975 }
976 
977 
978 inline IdContext
980  // Check if TRT_ID is valid for this layout
981  if (!m_is_valid) invalidMessage();
982 
984  return(IdContext(id, 0, m_BARREL_EC_INDEX));
985 }
986 
987 
988 IdContext
990  // Check if TRT_ID is valid for this layout
991  if (!m_is_valid) invalidMessage();
992 
994  return(IdContext(id, 0, m_LAYER_OR_WHEEL_INDEX));
995 }
996 
997 
998 IdContext
1000  // Check if TRT_ID is valid for this layout
1001  if (!m_is_valid) invalidMessage();
1002 
1004  return(IdContext(id, 0, m_STRAW_LAYER_INDEX));
1005 }
1006 
1007 
1008 IdContext
1010  // Check if TRT_ID is valid for this layout
1011  if (!m_is_valid) invalidMessage();
1012 
1014  return(IdContext(id, 0, m_STRAW_INDEX));
1015 }
IdDictDictionary::find_region
IdDictRegion * find_region(const std::string &region_name) const
Definition: IdDictDictionary.cxx:101
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:606
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:290
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:255
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:69
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:807
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:512
TRT_ID::init_hashes
void init_hashes()
Definition: TRT_ID.cxx:265
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
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:350
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:695
TRT_ID::barrel_ec_id_checks
void barrel_ec_id_checks(int barrel_ec) const
Definition: TRT_ID.cxx:52
IdContext::end_index
size_type end_index() const
Definition: IdContext.h:46
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
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
AtlasDetectorID::m_msgSvc
IMessageSvc * m_msgSvc
pointer to the message service
Definition: AtlasDetectorID.h:369
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:332
AtlasDetectorID::trt_field_value
int trt_field_value() const
Definition: AtlasDetectorID.h:627
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()
IdDictDictionary::find_field
IdDictField * find_field(const std::string &name) const
Definition: IdDictDictionary.cxx:47
CalibDbCompareRT.region_id
region_id
Definition: CalibDbCompareRT.py:67
IdDictRegion
Definition: IdDictRegion.h:20
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:979
TRT_ID::m_STRAW_INDEX
size_type m_STRAW_INDEX
Definition: TRT_ID.h:329
IdDictRegion::implementation
const IdDictFieldImplementation & implementation(size_t i) const
Definition: IdDictRegion.cxx:34
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:15
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:703
TRT_ID::straw
int straw(const Identifier &id) const
Definition: TRT_ID.h:839
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:124
TRT_ID::m_module_hash_max
size_type m_module_hash_max
Definition: TRT_ID.h:334
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:752
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:989
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
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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:89
TRT_ID::TRT_ID
TRT_ID()
Definition: TRT_ID.cxx:29
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:734
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:803
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:830
TRT_ID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override final
Set the IdDictionary.
Definition: TRT_ID.cxx:134
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:821
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:201
IdDictDictionary::get_label_value
int get_label_value(const std::string &field, const std::string &label, int &value) const
Definition: IdDictDictionary.cxx:75
TRT_ID::straw_layer_max
int straw_layer_max(const Identifier &id) const
Max values for each field (-999 == failure)
Definition: TRT_ID.cxx:786
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:999
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:812
TRT_ID::test_trt_ids
void test_trt_ids()
Tests of packing.
Definition: TRT_ID.cxx:826
IdDictDictionary
Definition: IdDictDictionary.h:30
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:1009
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:221
TRT_ID::initLevelsFromDict
int initLevelsFromDict()
Definition: TRT_ID.cxx:567
IdDictField.h
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:365
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
MultiRange::size
size_type size() const
Definition: MultiRange.cxx:70
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
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:111
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
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:507
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:15
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