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