ATLAS Offline Software
Loading...
Searching...
No Matches
MuonIdHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "IdDict/IdDictMgr.h"
11
12const std::string MuonIdHelper::BAD_NAME = "UNKNOWN";
13
14MuonIdHelper::MuonIdHelper(const std::string& logName,
15 const std::string& group) :
16 AtlasDetectorID(logName.empty() ? "MuonIdHelper" : logName, group)
17{
18}
19
21 // Check whether this helper should be reinitialized
22 if (!reinitialize(dict_mgr)) {
23 ATH_MSG_INFO("Request to reinitialize not satisfied - tags have not changed");
24 return 0;
25 } else {
26 ATH_MSG_DEBUG("(Re)initialize");
27 }
28
29 // init base object
30 if (AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return 1;
31
32 // Register version of the MuonSpectrometer dictionary
33 if (register_dict_tag(dict_mgr, "MuonSpectrometer")) return 1;
34
35 m_dict = dict_mgr.find_dictionary("MuonSpectrometer");
36 if (!m_dict) {
37 ATH_MSG_ERROR(" initialize_from_dict - cannot access MuonSpectrometer dictionary ");
38 return 1;
39 }
40
41 // Initialize some of the field indices
42 if (initLevelsFromDict()) return 1;
43
44 //
45 // Build multirange for the valid set of identifiers
46 //
47
48 // Find value for the field MuonSpectrometer
49 int muonField = -1;
50 const IdDictDictionary* atlasDict = dict_mgr.find_dictionary("ATLAS");
51 if (atlasDict->get_label_value("subdet", "MuonSpectrometer", muonField)) {
52 ATH_MSG_ERROR("Could not get value for label 'MuonSpectrometer' of field 'subdet' in dictionary ");
53 return 1;
54 }
55
56 // Build MultiRange down to "technology" for all (muon) regions
57 ExpandedIdentifier region_id;
58 region_id.add(muonField);
59 Range prefix;
60 MultiRange muon_range = m_dict->build_multirange(region_id, prefix, "technology");
61 if (muon_range.size()) {
62 ATH_MSG_INFO("MultiRange built successfully to Technology "
63 << "MultiRange size is " << muon_range.size());
64
65 } else {
66 ATH_MSG_ERROR("Muon MultiRange is empty");
67 return 1;
68 }
69
70 return 0;
71}
72
73// From hash get Identifier
74int MuonIdHelper::get_id(const IdentifierHash& hash_id, Identifier& id, const IdContext* context) const {
75 int result = 1;
76 id.clear();
77
78 size_t begin = (context) ? context->begin_index() : 0;
79 // cannot get hash if end is 0:
80 size_t end = (context) ? context->end_index() : 0;
81 if (0 == begin) {
82 // No hashes yet for ids with prefixes
83 if (m_MODULE_INDEX == end) {
84 if (hash_id < (unsigned int)(m_module_vec.end() - m_module_vec.begin())) {
85 id = m_module_vec[hash_id];
86 result = 0;
87 }
88 } else if (m_DETECTORELEMENT_INDEX == end) {
89 if (hash_id < (unsigned int)(m_detectorElement_vec.end() - m_detectorElement_vec.begin())) {
90 id = m_detectorElement_vec[hash_id];
91 result = 0;
92 }
93 } else if (m_CHANNEL_INDEX == end) {
94 if (hash_id < (unsigned int)(m_channel_vec.end() - m_channel_vec.begin())) {
95 id = m_channel_vec[hash_id];
96 result = 0;
97 }
98 }
99 }
100 return (result);
101}
102
104 // by binary search - overwritten in the derived classes
105 IdContext context = module_context();
106 hash_id = UINT_MAX;
107 size_t begin = context.begin_index();
108 size_t end = context.end_index();
109
110 if (0 == begin) {
111 // No hashes yet for ids with prefixes
112 if (m_MODULE_INDEX == end) {
113 id_vec_it it = std::lower_bound(m_module_vec.begin(), m_module_vec.end(), id);
114 if ((it != m_module_vec.end()) && (*it == id)) {
115 hash_id = it - m_module_vec.begin();
116 return 0;
117 }
118 }
119 }
120 ATH_MSG_WARNING("MuonIdHelper::get_module_hash(): Could not determine hash for identifier " << id.get_compact());
121 return 1;
122}
123
125 // by binary search - overwritten in the derived classes
126 hash_id = UINT_MAX;
128 size_t begin = context.begin_index();
129 size_t end = context.end_index();
130 if (0 == begin) {
131 if (m_DETECTORELEMENT_INDEX == end) {
132 id_vec_it it = std::lower_bound(m_detectorElement_vec.begin(), m_detectorElement_vec.end(), id);
133 if ((it != m_detectorElement_vec.end()) && (*it == id)) {
134 hash_id = it - m_detectorElement_vec.begin();
135 return 0;
136 }
137 }
138 }
139 ATH_MSG_WARNING("MuonIdHelper::get_detectorElement_hash(): Could not determine hash for identifier " << id.get_compact());
140 return 1;
141}
142
144 IdContext context = channel_context();
145 return get_hash(id, hash_id, &context);
146}
147
148int MuonIdHelper::get_hash(const Identifier& id, IdentifierHash& hash_id, const IdContext* context) const {
149 // Get the hash code from either a vec. We convert to compact
150 // and call get_hash again. For the latter, we calculate the hash from the
151 // Identifier.
152
153 int result = 1;
154 hash_id = 0;
155 size_t begin = (context) ? context->begin_index() : 0;
156 // size_t end = (context) ? context->end_index() : 0;
157 if (0 == begin) {
158 // No hashes yet for ids with prefixes
159 result = get_hash_calc(id, hash_id, context);
160 }
161 return (result);
162}
163
164int MuonIdHelper::get_expanded_id(const Identifier& id, ExpandedIdentifier& exp_id, const IdContext* context) const {
165 return (get_expanded_id_calc(id, exp_id, context));
166}
167
168int MuonIdHelper::get_id(const ExpandedIdentifier& old_id, Identifier& new_id) const {
169 // Copy old_id into new_id and get compact if possible
170 int result = 0;
171 new_id.clear();
172
173 ExpandedIdentifier dummy_id;
174 IdContext context(dummy_id, 0, old_id.fields() - 1);
175 Identifier compact_id;
176 if (!get_compact_id(old_id, compact_id, &context)) { new_id = compact_id; }
177 return (result);
178}
179
180// From compact, get ExpandedIdentifier
181int MuonIdHelper::get_expanded_id_calc(const Identifier& compact_id, ExpandedIdentifier& id, const IdContext* context) const {
182 int result = 1;
183 id.clear();
184 if (m_dict) {
185 // some preconditions in the case that the dictionary existd
186 size_t begin = (context) ? context->begin_index() : 0;
187 size_t end = (context) ? context->end_index() : m_CHANNEL_INDEX;
188 assert(end <= m_CHANNEL_INDEX);
189 if (0 == end) {
190 result = 0;
191 } else if (0 == begin) {
193 result = m_dict->unpack(this->group(), compact_id, empty, end, id);
194 // Ensure that the expected number of fields were unpacked.
195 if (id.fields() != end+1) result = 1;
196 } else {
197 // Non-zero prefix - we assume that the prefix contains
198 // the IdDet level
199 result = m_dict->unpack(this->group(), compact_id, context->prefix_id(), end, id);
200 }
201 }
202 if (!id.isValid()) {
203 return EXIT_FAILURE;
204 }
205 return result;
206}
207
208int MuonIdHelper::get_compact_id(const ExpandedIdentifier& id, Identifier& compact_id, const IdContext* context) const {
209 // Get compact for all fields provided
210 int result = 1;
211 compact_id = (Identifier::value_type)0;
212 int exp_id[10];
213
214 for (size_t i = 0; i < id.fields(); i++) exp_id[i] = id[i];
215
216 if (m_dict && id.fields() > 0) {
217 size_t begin = (context) ? context->begin_index() : 0;
218 size_t end = (context) ? context->end_index() : id.fields() - 1;
219 result = m_dict->pack32(exp_id, begin, end, m_GROUP_INDEX, compact_id);
220 // result = m_dict->pack32(id, begin, end, compact_id);
221 }
222 return (result);
223}
224
225int MuonIdHelper::get_hash_calc(const Identifier& compact_id, IdentifierHash& hash_id, const IdContext* context) const {
226 // Get the hash code from vec (for wafers only).
227 hash_id = UINT_MAX;
228 size_t begin = (context) ? context->begin_index() : 0;
229 size_t end = (context) ? context->end_index() : 0;
230
231 if (0 == begin) {
232 // No hashes yet for ids with prefixes
233 if (m_MODULE_INDEX == end) {
234 return get_module_hash(compact_id, hash_id);
235 } else if (m_DETECTORELEMENT_INDEX == end) {
236 return get_detectorElement_hash(compact_id, hash_id);
237 } else if (m_CHANNEL_INDEX == end) {
238 id_vec_it it = std::lower_bound(m_channel_vec.begin(), m_channel_vec.end(), compact_id);
239 if ((it != m_channel_vec.end()) && (*it == compact_id)) {
240 hash_id = it - m_channel_vec.begin();
241 return 0;
242 }
243 }
244 }
245 ATH_MSG_WARNING("MuonIdHelper::get_hash_calc(): Could not determine hash for identifier " << compact_id.get_compact());
246 return 1;
247}
248
250 if (!m_dict) {
251 ATH_MSG_ERROR(" initLevelsFromDict - dictionary NOT initialized ");
252 return 1;
253 }
254
255 // Find out which identifier field corresponds to each level. Use
256 // names to find each field/leve.
257
258 m_MUON_INDEX = 999;
259 m_NAME_INDEX = 999;
260 m_ETA_INDEX = 999;
261 m_PHI_INDEX = 999;
262 m_CHANNEL_INDEX = 999;
263
264 // Save index to stations for unpacking
266 if (m_dict->find_region(id, m_station_region_index)) {
267 ATH_MSG_ERROR("initLevelsFromDict - unable to find a muon station index: id, reg"
268 << " " << std::string(id) << " " << m_station_region_index);
269
270 return 1;
271 }
272
273 // Find a Muon region
274 const IdDictField* field = m_dict->find_field("subdet");
275 if (field) {
276 m_MUON_INDEX = field->index();
277 } else {
278 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'subdet' field ");
279 return 1;
280 }
281 field = m_dict->find_field("stationName");
282 if (field) {
283 m_NAME_INDEX = field->index();
284
285 if (m_stationIdxToNameMap.empty()) {
286 // we only need to fill the vectors and sets once
287 for (size_t i = 0; i < field->get_label_number(); i++) {
288 std::string name = field->get_label(i);
289 int index = (int)field->get_label_value(name);
293 if (isStNameInTech(name)) m_stationInTech.insert(index);
294 // all chambers starting with B are in the barrel except the BEE chambers
295 if ('B' == name[0]) {
296 if (name[1] != 'E')
297 m_isBarrel.insert(index);
298 else
299 m_isSmall.insert(index); // BEE is in the small sector
300 if ('G' == name[2] || 'F' == name[2]) { m_isSmall.insert(index); }
301 } else if ('F' == name[2]) {
302 m_isForward.insert(index);
303 }
304 if ('S' == name[2]) { m_isSmall.insert(index); }
305 }
306 }
307
308 } else {
309 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'stationName' field ");
310 return 1;
311 }
312 field = m_dict->find_field("stationEta");
313 if (field) {
314 m_ETA_INDEX = field->index();
315 } else {
316 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'stationEta' field ");
317 return 1;
318 }
319 field = m_dict->find_field("stationPhi");
320 if (field) {
321 m_PHI_INDEX = field->index();
322 } else {
323 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'stationPhi' field ");
324 return 1;
325 }
326 field = m_dict->find_field("technology");
327 if (field) {
328 m_TECHNOLOGY_INDEX = field->index();
329
330 if (m_technologyNameToIdxMap.empty()) {
331 for (size_t i = 0; i < field->get_label_number(); ++i) {
332 std::string name = field->get_label(i);
333 int index = (int)field->get_label_value(name);
336 m_technologyIdxToNameMap[index] = std::move(name);
337 }
338 }
339
340 } else {
341 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'technology' field ");
342 return 1;
343 }
345
346 // Set the field implementations down to the technology
347 const IdDictRegion& region = m_dict->region(m_station_region_index);
350
351 // m_stationNameField = m_dict->find_field ("stationName"); // Philipp
352 // m_technologyField = m_dict->find_field ("technology"); // Philipp
353 return 0;
354}
355
357 //
358 // create a vector(s) to retrieve the hashes for compact ids. For
359 // the moment, we implement a hash for modules
360 //
361
362 // module hash
364 ATH_MSG_INFO("The element hash max is " << m_module_hash_max);
366 IdContext context = module_context();
367 unsigned int nids = 0;
368 std::set<Identifier> ids;
369 for (unsigned int i = 0; i < m_full_module_range.size(); ++i) {
370 const Range& range = m_full_module_range[i];
371 ConstRangeIterator rit(range);
372 for (const auto & expId:rit) {
373 Identifier id;
374 get_id(expId, id);
375 if (!(ids.insert(id)).second) {
376 ATH_MSG_ERROR("init_hashes "
377 << " Error: duplicated id for module id. nid " << (int)nids << " compact id " << id << " id ");
378 return 1;
379 }
380 nids++;
381 }
382 }
383 if (ids.size() != m_module_hash_max) {
384 ATH_MSG_ERROR("init_hashes "
385 << " Error: set size NOT EQUAL to element hash max. size " << ids.size() << " hash max " << m_module_hash_max);
386
387 return 1;
388 }
389
390 nids = 0;
391 std::set<Identifier>::const_iterator first = ids.begin();
392 std::set<Identifier>::const_iterator last = ids.end();
393 for (; first != last && nids < m_module_vec.size(); ++first) {
394 m_module_vec[nids] = (*first);
395 nids++;
396 }
397 // sort the vector of identifiers to be able to use std::lower_bound to find hashes
398 std::sort(m_module_vec.begin(), m_module_vec.end());
399 return 0;
400}
401
403 //
404 // create a vector(s) to retrieve the hashes for compact ids. For
405 // the moment, we implement a hash for readout channels
406 //
407
408 // detector element hash
410 ATH_MSG_INFO("The detector element hash max is " << m_detectorElement_hash_max);
413 unsigned int nids = 0;
414 std::set<Identifier> ids;
415 for (unsigned int i = 0; i < m_full_detectorElement_range.size(); ++i) {
416 const Range& range = m_full_detectorElement_range[i];
417 ConstRangeIterator rit(range);
418 for (const auto & expId:rit) {
419 Identifier id;
420 get_id(expId, id);
421 if (!(ids.insert(id)).second) {
422 ATH_MSG_ERROR("init_detectorElement_hashes "
423 << " Error: duplicated id for channel id. nid " << nids << " compact id " << id << " id ");
424
425 return 1;
426 }
427 nids++;
428 }
429 }
430 if (ids.size() != m_detectorElement_hash_max) {
431 ATH_MSG_ERROR("init_hashes "
432 << " Error: set size NOT EQUAL to hash max. size " << ids.size() << " hash max " << m_detectorElement_hash_max);
433 return 1;
434 }
435
436 nids = 0;
437 std::set<Identifier>::const_iterator first = ids.begin();
438 std::set<Identifier>::const_iterator last = ids.end();
439 for (; first != last && nids < m_detectorElement_vec.size(); ++first) {
440 m_detectorElement_vec[nids] = (*first);
441 nids++;
442 }
443 // sort the vector of identifiers to be able to use std::lower_bound to find hashes
445 return 0;
446}
447
449 //
450 // create a vector(s) to retrieve the hashes for compact ids. For
451 // the moment, we implement a hash for readout channels
452 //
453
454 // readout channel hash
456 ATH_MSG_INFO("The channel hash max is " << m_channel_hash_max);
458 IdContext context = channel_context();
459 unsigned int nids = 0;
460 std::set<Identifier> ids;
461 for (unsigned int i = 0; i < m_full_channel_range.size(); ++i) {
462 const Range& range = m_full_channel_range[i];
463 ConstRangeIterator rit(range);
464 for (const auto & expId:rit) {
465 Identifier id;
466 get_id(expId, id);
467
468 if (!(ids.insert(id)).second) {
469 ATH_MSG_ERROR("init_channel_hashes "
470 << " Error: duplicated id for channel id. nid " << nids << " compact id " << id << " id ");
471 return 1;
472 }
473 m_channel_vec[nids] = id;
474 nids++;
475 }
476 }
477 if (ids.size() != m_channel_hash_max) {
478 ATH_MSG_ERROR("init_hashes "
479 << " Error: set size NOT EQUAL to hash max. size " << ids.size() << " hash max " << m_channel_hash_max);
480
481 return 1;
482 }
483 // sort the vector of identifiers to be able to use std::lower_bound to find hashes
484 std::sort(m_channel_vec.begin(), m_channel_vec.end());
485 return 0;
486}
487
489 unsigned short index = id;
490 if (index < m_prev_phi_module_vec.size()) {
493 return 0;
494 }
495 return 1;
496}
497
499 unsigned short index = id;
500 if (index < m_next_phi_module_vec.size()) {
503 return 0;
504 }
505 return 1;
506}
507
509 unsigned short index = id;
510 if (index < m_prev_eta_module_vec.size()) {
513 return 0;
514 }
515 return 1;
516}
517
519 unsigned short index = id;
520 if (index < m_next_eta_module_vec.size()) {
523 return 0;
524 }
525 return 1;
526}
527
529 //
530 // create a vector(s) to retrieve the hashes for compact ids for
531 // module neighbors.
532 //
533
534 ATH_MSG_VERBOSE("MuonIdHelper::init_neighbors ");
539
540 for (unsigned int i = 0; i < m_full_module_range.size(); ++i) {
541 const Range& range = m_full_module_range[i];
542 const Range::field& phi_field = range[m_PHI_INDEX];
543 const Range::field& eta_field = range[m_ETA_INDEX];
544 ConstRangeIterator rit(range);
545 for (const auto & id: rit) {
550 bool pphi = phi_field.get_previous(id[m_PHI_INDEX], previous_phi);
551 bool nphi = phi_field.get_next(id[m_PHI_INDEX], next_phi);
552 bool peta = eta_field.get_previous(id[m_ETA_INDEX], previous_eta);
553 bool neta = eta_field.get_next(id[m_ETA_INDEX], next_eta);
554
555 Identifier compact_id;
556 IdContext wcontext = module_context();
557
558 // First get primary hash id
559 IdentifierHash hash_id;
560 if (!get_compact_id(id, compact_id, &wcontext)) {
561 // forward to compact -> hash
562 if (get_hash(compact_id, hash_id, &wcontext)) {
563 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get hash, exp/compact "
564 << " " << std::hex << compact_id << std::dec << endmsg);
565 return 1;
566 }
567 } else {
568 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get compact, exp/compact ");
569 return 1;
570 }
571
572 // index for the subsequent arrays
573 unsigned short index = hash_id;
574 assert(hash_id < m_prev_phi_module_vec.size());
575 assert(hash_id < m_next_phi_module_vec.size());
576 assert(hash_id < m_prev_eta_module_vec.size());
577 assert(hash_id < m_next_eta_module_vec.size());
578
579 if (pphi) {
580 // Get previous phi hash id
581 ExpandedIdentifier expId = id;
582 expId[m_PHI_INDEX] = previous_phi;
583 if (!get_compact_id(expId, compact_id, &wcontext)) {
584 // forward to compact -> hash
585 if (get_hash(compact_id, hash_id, &wcontext)) {
586 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get previous phi hash, exp/compact "
587 << " " << std::hex << compact_id << std::dec);
588 return 1;
589 }
590 } else {
591 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get previous phi compact, exp/compact ");
592 return 1;
593 }
594 m_prev_phi_module_vec[index] = hash_id;
595 }
596
597 if (nphi) {
598 // Get next phi hash id
599 ExpandedIdentifier expId = id;
600 expId[m_PHI_INDEX] = next_phi;
601 if (!get_compact_id(expId, compact_id, &wcontext)) {
602 // forward to compact -> hash
603 if (get_hash(compact_id, hash_id, &wcontext)) {
604 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get next phi hash, exp/compact "
605 << " " << std::hex << compact_id << std::dec);
606 return 1;
607 }
608 } else {
609 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get next phi compact, exp/compact ");
610 return 1;
611 }
612 m_next_phi_module_vec[index] = hash_id;
613 }
614
615 if (peta) {
616 // Get previous eta hash id
617 ExpandedIdentifier expId = id;
618 expId[m_ETA_INDEX] = previous_eta;
619 if (!get_compact_id(expId, compact_id, &wcontext)) {
620 // forward to compact -> hash
621 if (get_hash(compact_id, hash_id, &wcontext)) {
622 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get previous eta hash, exp/compact "
623 << " " << std::hex << compact_id << std::dec);
624 return 1;
625 }
626 } else {
627 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get previous eta compact, exp/compact ");
628 return 1;
629 }
630 m_prev_eta_module_vec[index] = hash_id;
631 }
632
633 if (neta) {
634 // Get next eta hash id
635 ExpandedIdentifier expId = id;
636 expId[m_ETA_INDEX] = next_eta;
637 if (!get_compact_id(expId, compact_id, &wcontext)) {
638 // forward to compact -> hash
639 if (get_hash(compact_id, hash_id, &wcontext)) {
640 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get next eta hash, exp/compact "
641 << " " << std::hex << compact_id << std::dec);
642 return 1;
643 }
644 } else {
645 ATH_MSG_ERROR(" MuonIdHelper::init_neighbors - unable to get next eta compact, exp/compact ");
646 return 1;
647 }
648 m_next_eta_module_vec[index] = hash_id;
649 }
650 }
651 }
652 ATH_MSG_VERBOSE("Finish init_neighors() ...");
653 return 0;
654}
655
657 if (m_dict) {
658 int nids = 0;
659 IdContext context = module_context();
660 const_id_iterator first = m_module_vec.begin();
661 const_id_iterator last = m_module_vec.end();
662 for (; first != last; ++first, ++nids) {
663 Identifier compact = (*first);
665 if (get_expanded_id(compact, id, &context)) {
666 ATH_MSG_ERROR("test_module_packing: Unable to get expanded id. Compact id " << compact);
667 continue;
668 }
669 Identifier new_compact;
670 if (get_compact_id(id, new_compact, &context)) {
671 ATH_MSG_ERROR("test_module_packing: Unable to get compact id. Expanded id " << std::string(id));
672 continue;
673 }
674 if (compact != new_compact) {
675 ATH_MSG_ERROR("test_module_packing: new and old compacts not equal "
676 << "New/old/expanded ids " << new_compact << " " << compact << " " << std::string(id));
677 continue;
678 }
679 }
680
681 ATH_MSG_INFO("test_module_packing: Successful tested " << nids << " ids. ");
682 } else {
683 ATH_MSG_ERROR("Unable to test module is packing - no dictionary has been defined. ");
684 }
685}
686
687void MuonIdHelper::test_id(const Identifier& id, const IdContext& context) const {
688 Identifier compact = id;
689 ExpandedIdentifier new_id;
690 if (get_expanded_id(compact, new_id, &context)) {
691 ATH_MSG_ERROR("Unable to get expanded id. Compact id " << compact);
692 return;
693 }
694 Identifier new_compact;
695 if (get_compact_id(new_id, new_compact, &context)) {
696 ATH_MSG_ERROR("Unable to get compact id. Expanded id " << show_to_string(id));
697 return;
698 }
699 if (compact != new_compact) {
700 ATH_MSG_ERROR("new and old compacts not equal. New/old/expanded ids " << new_compact << " " << compact << " "
701 << show_to_string(id));
702 return;
703 }
704}
705
706// Prepend the station ID
707
709 ExpandedIdentifier exp_id;
710 IdContext muon_context(exp_id, 0, m_MUON_INDEX);
711 if (get_expanded_id(id, exp_id, &muon_context)) {
712 ATH_MSG_ERROR(" MUON_ID result is NOT ok. MUON id " << show_to_string(id) << " Fields not appended ");
713 } else {
714 exp_id << stationName << stationEta << stationPhi << technology;
715 get_id(exp_id, id); // Fill output
716 }
717}
718
720 std::string name = stationNameString(stationName(id));
721
722 if (name.size() >= 2) {
723 if ('I' == name[1] || '4' == name[1]) return 0;
724 if ('E' == name[1] || '1' == name[1]) return 1;
725 if ('M' == name[1] || '2' == name[1]) return 2;
726 if ('O' == name[1] || '3' == name[1]) return 3;
727 }
728 if (name == "CSS" || name == "CSL") return 0;
729 ATH_MSG_ERROR(" MuonId::stationRegion / id = " << show_to_string(id) << " stationnamestring = " << name);
730 return -1;
731}
732
733/*******************************************************************************/
735/*******************************************************************************/
740/*******************************************************************************/
745/*******************************************************************************/
750/*******************************************************************************/
755/*******************************************************************************/
757/*******************************************************************************/
759/*******************************************************************************/
761/*******************************************************************************/
762const std::vector<Identifier>& MuonIdHelper::idVector() const { return m_module_vec; }
763/*******************************************************************************/
765/*******************************************************************************/
767/*******************************************************************************/
769/*******************************************************************************/
771
773/*******************************************************************************/
775/*******************************************************************************/
776// Check common station fields
782
783/*******************************************************************************/
787/*******************************************************************************/
788// Check if ID for muon system
789bool MuonIdHelper::is_muon(const Identifier& id) const { return AtlasDetectorID::is_muon(id); }
790/*******************************************************************************/
791// Check if ID for MDT
792bool MuonIdHelper::is_mdt(const Identifier& id) const { return AtlasDetectorID::is_mdt(id); }
793/*******************************************************************************/
794// Check if ID for CSC
795bool MuonIdHelper::is_csc(const Identifier& id) const { return AtlasDetectorID::is_csc(id); }
796/*******************************************************************************/
797// Check if ID for RPC
798bool MuonIdHelper::is_rpc(const Identifier& id) const { return AtlasDetectorID::is_rpc(id); }
799/*******************************************************************************/
800// Check if ID for TGC
801bool MuonIdHelper::is_tgc(const Identifier& id) const { return AtlasDetectorID::is_tgc(id); }
802/*******************************************************************************/
803// Check if ID for sTGC
804bool MuonIdHelper::is_stgc(const Identifier& id) const { return AtlasDetectorID::is_stgc(id); }
805/*******************************************************************************/
806// Check if ID for MicroMegas
807bool MuonIdHelper::is_mm(const Identifier& id) const { return AtlasDetectorID::is_mm(id); }
808/*******************************************************************************/
809// Access to components of the ID
811 int result = m_sta_impl.unpack(id);
812 return result;
813}
814/*******************************************************************************/
816 int result = m_eta_impl.unpack(id);
817 return result;
818}
819/*******************************************************************************/
821 int result = m_phi_impl.unpack(id);
822 return result;
823}
824/*******************************************************************************/
826 int result = m_tec_impl.unpack(id);
827 return result;
828}
829/*******************************************************************************/
831/*******************************************************************************/
833/*******************************************************************************/
834// Methods used by Moore
835bool MuonIdHelper::isBarrel(const Identifier& id) const { return isBarrel(stationName(id)); }
836/*******************************************************************************/
837bool MuonIdHelper::isEndcap(const Identifier& id) const { return isEndcap(stationName(id)); }
838/*******************************************************************************/
839bool MuonIdHelper::isForward(const Identifier& id) const { return isForward(stationName(id)); }
840/*******************************************************************************/
841bool MuonIdHelper::isSmall(const Identifier& id) const { return isSmall(stationName(id)); }
842/*******************************************************************************/
843bool MuonIdHelper::isBarrel(const int& stationNameIndex) const { return (m_isBarrel.count(stationNameIndex) == 1); }
844/*******************************************************************************/
845bool MuonIdHelper::isEndcap(const int& stationNameIndex) const { return (m_isBarrel.count(stationNameIndex) == 0); }
846/*******************************************************************************/
847bool MuonIdHelper::isForward(const int& stationNameIndex) const { return (m_isForward.count(stationNameIndex) == 1); }
848/*******************************************************************************/
849bool MuonIdHelper::isSmall(const int& stationNameIndex) const { return (m_isSmall.count(stationNameIndex) == 1); }
850/*******************************************************************************/
851// Access to name and technology maps
852int MuonIdHelper::stationNameIndex(const std::string& name) const {
853 std::map<std::string, int>::const_iterator itr = m_stationNameToIdxMap.find(name);
854 if (itr != m_stationNameToIdxMap.end()) return itr->second;
855 return -1;
856}
857/*******************************************************************************/
858int MuonIdHelper::technologyIndex(const std::string& name) const {
859 std::map<std::string, int>::const_iterator itr = m_technologyNameToIdxMap.find(name);
860 if (itr != m_technologyNameToIdxMap.end()) return itr->second;
861 return -1;
862}
863/*******************************************************************************/
864const std::string& MuonIdHelper::stationNameString(const int& index) const {
865 assert(index >= 0 && index <= stationNameIndexMax());
866 std::map<int, std::string>::const_iterator itr = m_stationIdxToNameMap.find(index);
867 if (itr != m_stationIdxToNameMap.end()) return itr->second;
868 return BAD_NAME;
869}
870/*******************************************************************************/
871const std::string& MuonIdHelper::technologyString(const int& index) const {
872 assert(index >= 0 && index <= technologyNameIndexMax());
873 std::map<int, std::string>::const_iterator itr = m_technologyIdxToNameMap.find(index);
874 if (itr != m_technologyIdxToNameMap.end()) return itr->second;
875 return BAD_NAME;
876}
877/*******************************************************************************/
878int MuonIdHelper::nStationNames() const { return (int)m_isSmall.size(); }
879/*******************************************************************************/
880bool MuonIdHelper::isInitialized() const { return m_init; }
881/*******************************************************************************/
#define endmsg
#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)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
static const Attributes_t empty
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.
bool is_mdt(Identifier id) const
ExpandedIdentifier muon_exp(void) const
int register_dict_tag(const IdDictMgr &dict_mgr, const std::string &dict_name)
Register the file and tag names for a particular IdDict dictionary.
bool is_stgc(Identifier id) const
bool is_rpc(Identifier id) const
bool is_tgc(Identifier id) const
bool is_muon(Identifier id) const
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
bool is_csc(Identifier id) const
Identifier muon(void) const
bool is_mm(Identifier id) const
const std::string & group() const
Group name for this helper.
AtlasDetectorID(const std::string &name, const std::string &group)
size_type fields() const
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
const ExpandedIdentifier & prefix_id() const
Accessors.
Definition IdContext.h:44
int get_label_value(const std::string &field, const std::string &label, int &value) const
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
const IdDictFieldImplementation & implementation(size_t i) const
bool get_previous(element_type current, element_type &previous) const
Returns false if previous/next is at end of range, or not possible.
bool get_next(element_type current, element_type &next) const
This is a "hash" representation of an Identifier.
void clear()
Reset to invalid state.
value_type get_compact() const
Get the compact id.
A MultiRange combines several Ranges.
Definition MultiRange.h:17
size_type size() const
std::vector< Identifier >::const_iterator const_id_iterator
int stationNameIndex(const std::string &name) const
virtual int get_channel_hash(const Identifier &id, IdentifierHash &hash_id) const
int stationEta(const Identifier &id) const
std::set< int > m_isForward
const_id_iterator module_end() const
IdDictFieldImplementation m_phi_impl
size_t m_GROUP_INDEX
const std::string & technologyString(const int &index) const
IdDictFieldImplementation m_tec_impl
int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
Create expanded id from compact id (return == 0 for OK)
const_id_iterator module_begin() const
Iterators over full set of ids.
virtual int get_detectorElement_hash(const Identifier &id, IdentifierHash &hash_id) const
bool is_rpc(const Identifier &id) const
void test_id(const Identifier &id, const IdContext &context) const
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
size_type m_PHI_INDEX
std::map< int, std::string > m_technologyIdxToNameMap
Mapping int -> string.
const MultiRange & multiRange() const
multirange
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override
Create compact id from hash id (return == 0 for OK)
size_type m_CHANNEL_INDEX
virtual int get_hash_calc(const Identifier &compact_id, IdentifierHash &hash_id, const IdContext *context) const
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
void test_module_packing() const
Tests of packing.
hash_vec m_next_phi_module_vec
int technologyIndex(const std::string &name) const
size_type m_station_region_index
bool is_csc(const Identifier &id) const
IdDictFieldImplementation m_sta_impl
hash_vec m_prev_eta_module_vec
const_id_iterator channel_end() const
size_type m_NAME_INDEX
static const std::string BAD_NAME
std::map< int, std::string > m_stationIdxToNameMap
Mapping int -> string.
MultiRange m_full_module_range
bool is_muon(const Identifier &id) const
id_vec m_channel_vec
bool is_stgc(const Identifier &id) const
IdDictFieldImplementation m_eta_impl
bool validTechnology(int technology) const
void addStationID(Identifier &id, int stationName, int stationEta, int stationPhi, int technology) const
int get_compact_id(const ExpandedIdentifier &id, Identifier &compact_id, const IdContext *context) const
Identifier muon() const
bool isEndcap(const Identifier &id) const
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const
size_type module_hash_max() const
the maximum hash value
const std::vector< Identifier > & idVector() const
the id's
bool isForward(const Identifier &id) const
MultiRange m_full_detectorElement_range
size_type m_ETA_INDEX
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
const IdDictDictionary * m_dict
int nStationNames() const
bool is_tgc(const Identifier &id) const
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
IdContext module_context() const
id for module
int stationNameIndexMax() const
int stationRegion(const Identifier &id) const
IdContext technology_context() const
access to IdContext's which define which levels or fields are contained in the Muon id
int stationPhi(const Identifier &id) const
size_type m_DETECTORELEMENT_INDEX
int technology(const Identifier &id) const
int stationName(const Identifier &id) const
int init_channel_hashes()
int initLevelsFromDict()
size_type channel_hash_max() const
const_id_iterator channel_begin() const
Iterators over full set of ids.
size_type m_module_hash_max
bool isBarrel(const Identifier &id) const
bool isSmall(const Identifier &id) const
int m_technologyIndexMax
IdContext detectorElement_context() const
id for detector element
hash_vec m_next_eta_module_vec
id_vec m_detectorElement_vec
bool is_mm(const Identifier &id) const
virtual int init_detectorElement_hashes()
int technologyNameIndexMax() const
hash_vec m_prev_phi_module_vec
bool is_mdt(const Identifier &id) const
virtual bool isStNameInTech(const std::string &stationName) const =0
The valid element checks converted the identifier to a stationName string in order to assess whether ...
IdDictFieldImplementation m_muon_impl
std::set< int > m_isBarrel
size_type m_MODULE_INDEX
bool validStation(int stationName, int technology) const
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const override
Create hash id from compact id (return == 0 for OK)
size_type m_detectorElement_hash_max
const_id_iterator detectorElement_end() const
static constexpr int NOT_VALID_HASH
Identifier::size_type size_type
std::map< std::string, int > m_stationNameToIdxMap
Mapping string -> int.
MultiRange m_full_channel_range
IdContext channel_context() const
id for channel
std::set< int > m_stationInTech
size_type m_channel_hash_max
std::set< int > m_isSmall
const std::string & stationNameString(const int &index) const
bool isInitialized() const
MuonIdHelper(const std::string &logName, const std::string &group)
id_vec::const_iterator id_vec_it
int get_expanded_id_calc(const Identifier &compact_id, ExpandedIdentifier &id, const IdContext *context) const
size_type m_MUON_INDEX
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
id_vec m_module_vec
size_type m_TECHNOLOGY_INDEX
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
Access to hashes for neighbors in phi and eta (return == 0 for neighbor found)
std::map< std::string, int > m_technologyNameToIdxMap
Mapping string -> int.
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition index.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.