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