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