ATLAS Offline Software
Loading...
Searching...
No Matches
CaloLVL1_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
9#include "IdDict/IdDictMgr.h"
10#include "IdDict/IdDictRegion.h"
11#include "CxxUtils/StrFormat.h"
14#include <algorithm>
15#include <cassert>
16#include <cmath>
17#include <cstdio>
18#include <iostream>
19#include <set>
20#include <string>
21
22
24
25
27 AtlasDetectorID("CaloLVL1_ID", "Reg_Lvl1")
29 , m_CALO_INDEX(999)
30 , m_DETZSIDE_INDEX(999)
31 , m_SAMPLING_INDEX(999)
32 , m_REGION_INDEX(999)
33 , m_ETA_INDEX(999)
34 , m_PHI_INDEX(999)
35 , m_LAYER_INDEX(999)
36 , m_dict(nullptr)
40
41{
42
43}
44
46
47
48
51{
53 return {id, 0, m_REGION_INDEX};
54}
55
58{
60 return {id, 0, m_PHI_INDEX};
61}
62
65{
67 return {id, 0, m_LAYER_INDEX};
68}
69
70
71
72int CaloLVL1_ID::get_id (const IdentifierHash& hash_id, Identifier& id, const IdContext* context) const
73{
74 int result = 1;
75 id.clear();
76
77 size_t begin = (context) ? context->begin_index(): 0;
78 // cannot get hash if end is 0:
79 size_t end = (context) ? context->end_index() : 0;
80
81 if (0 == begin) {
82 if (m_REGION_INDEX == end) {
83 if (hash_id < (unsigned int)(m_region_vec.end() - m_region_vec.begin()))
84 {
85 id = m_region_vec[hash_id];
86 result = 0;
87 }
88 else
89 {
90 ATH_MSG_ERROR("hash_id out of range " << hash_id);
91 }
92 }
93 else if (m_PHI_INDEX == end) {
94 if (hash_id < (unsigned int)(m_tower_vec.end() - m_tower_vec.begin())) {
95 id = m_tower_vec[hash_id];
96 result = 0;
97 }
98 else
99 {
100 ATH_MSG_ERROR("hash_id out of range " << hash_id);
101 }
102 }
103 else if(m_LAYER_INDEX == end) {
104 if (hash_id < (unsigned int)(m_layer_vec.end() - m_layer_vec.begin())) {
105 id = m_layer_vec[hash_id];
106 result = 0;
107 }
108 else
109 {
110 ATH_MSG_ERROR("hash_id out of range " << hash_id);
111 }
112 }
113 }
114 return(result);
115}
116
117int CaloLVL1_ID::get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context) const
118{
119 hash_id = 0;
120 int result = 1;
121
122 size_t begin = (context) ? context->begin_index(): 0;
123 size_t end = (context) ? context->end_index() : 0;
124
125 if (0 == begin) {
126 if (m_REGION_INDEX == end) {
127 Identifier redId = region_id (id);
128 std::vector<Identifier>::const_iterator it = std::lower_bound(m_region_vec.begin(),m_region_vec.end(),redId);
129 if ( it != m_region_vec.end() ){
130 hash_id = it - m_region_vec.begin();
131 result = 0;
132 }
133 }
134 else if (m_PHI_INDEX == end) {
135
136 Identifier redId = tower_id (id);
137
138 std::vector<Identifier>::const_iterator it = std::lower_bound(m_tower_vec.begin(),m_tower_vec.end(),redId);
139 if ( it != m_tower_vec.end() ){
140 hash_id = it - m_tower_vec.begin();
141 result = 0;
142 }
143 }
144 else if (m_LAYER_INDEX == end) {
145
146 std::vector<Identifier>::const_iterator it = std::lower_bound(m_layer_vec.begin(),m_layer_vec.end(),id);
147 if ( it != m_layer_vec.end() ){
148 hash_id = it - m_layer_vec.begin();
149 result = 0;
150 }
151 }
152
153 else {
154 std::string errorMessage =
155 "Error in CaloLVL1_ID::get_hash, invalid context ";
156 throw CaloID_Exception(errorMessage , 10);
157 }
158 }
159
160 return (result);
161}
162
163
164
165
167{
168 ATH_MSG_INFO("initialize_from_dictionary");
169
170 // Check whether this helper should be reinitialized
171 if (!reinitialize(dict_mgr)) {
172 ATH_MSG_DEBUG("Request to reinitialize not satisfied - tags have not changed");
173 return (0);
174 }
175 else {
176 ATH_MSG_DEBUG("(Re)initialize");
177 }
178
179
180 // init base object
181 if(AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return (1);
182
183 // Register version of the Calorimeter dictionary
184 if (register_dict_tag(dict_mgr, "Calorimeter")) return(1);
185
186 m_dict = dict_mgr.find_dictionary ("Calorimeter");
187 if(!m_dict)
188 {
189 ATH_MSG_ERROR("initialize_from_dict - cannot access LVL1Calorimeter dictionary");
190 return(1);
191 }
192
193 // Initialize the field indices
194 if(initLevelsFromDict()) return (1);
195
196
197 // Find values for the calo and LVL1 (neg) fields
198 int caloValue = -1;
199 if (m_dict->get_label_value("subdet", "Calorimeter", caloValue))
200 {
201 ATH_MSG_ERROR("Could not get value for label 'Calorimeter' of field 'subdet' in dictionary " << m_dict->name());
202 return (1);
203 }
204
205 int lvl1CaloValue = -1;
206 // negative half
207 // if (m_dict->get_label_value("DetZside", "negative_lvl1_side", lvl1CaloValue))
208 // positive half FLG 12 Jul 07: negative side -> problem for test beam
209 if (m_dict->get_label_value("DetZside", "positive_lvl1_side", lvl1CaloValue))
210 {
211 ATH_MSG_ERROR("Could not get value for label 'positive_lvl1_side' of field 'DetZside in dictionary" << m_dict->name());
212 return (1);
213 }
214
215 // Set up id for region and range prefix
216 // NOTE: negative value is good enough to get multirange since the
217 // regions are symmetric in +/-eta
218 // FLG Jul 07: EXCEPT FOR CTB !!!!!!!!!!
219
220 ExpandedIdentifier reg_id;
221 reg_id.add(caloValue);
222 reg_id.add(lvl1CaloValue);
223 Range prefix;
224 m_full_region_range = m_dict->build_multirange(reg_id, group(), prefix, "region");
225 m_full_tower_range = m_dict->build_multirange(reg_id, group(), prefix, "phi");
226 m_full_layer_range = m_dict->build_multirange(reg_id, group(), prefix);
227
228 // Setup the hash tables
229 if(init_hashes()) return (1);
230
231 // Setup hash tables for finding neighbors
232 if(init_neighbors()) return (1);
233
234 ATH_MSG_DEBUG("CaloLVL1_ID::initialize_from_dict : ");
235 ATH_MSG_DEBUG(" tower range -> " << (std::string)m_full_tower_range);
236 ATH_MSG_DEBUG(" layer range -> " << (std::string)m_full_layer_range);
237
238 // Setup for hash calculation
239
240 // Regions have uniform eta/phi granularity
241 // The lookup table only needs to contain the
242 // hash offset for each region, the first eta index
243 // and the number of phi cells.
244
245 // The implementation requires:
246
247 // 1) a lookup table for each region containing hash offset,
248 // etamin and nphi
249 // 2) a decoder to access the "index" corresponding to the
250 // pnz/samp/reg fields. These fields use 6 bits, so the
251 // vector has a length of 64 for 16 regions.
252
253
254 // Create decoder for fields pnz to region
256 m_lvl1_impl.bits() +
257 m_sampling_impl.bits() +
258 m_region_impl.bits();
259 IdDictFieldImplementation::size_type bits_offset = m_lvl1_impl.bits_offset();
260 m_pnz_reg_impl.set_bits(bits, bits_offset);
261 int size = (1 << bits);
262
263 // Set up vector as lookup table for hash calculation.
264 m_hash_calcs.resize(size);
265
266 for (unsigned int i = 0; i < m_region_hash_max; ++i) {
267
268 Identifier regId = region_id(i) ;
269
270 HashCalc hc;
271
272 int etamin = eta_min(regId);
273 Identifier min = tower_id ( regId, etamin, 0);
275 hc.m_hash = min_hash;
276 hc.m_etamin = etamin;
277 hc.m_nphi = phi_max(min)+1 ;
278 m_hash_calcs[m_pnz_reg_impl.unpack(min)] = hc;
279
280 if (m_pnz_reg_impl.unpack(min) >= size)
281 {
282 ATH_MSG_DEBUG("Min > " << size);
284 ATH_MSG_DEBUG(" " << m_pnz_reg_impl.unpack(min));
285 }
286 }
287
288 // Check hash calculation
289 for (unsigned int i = 0; i < m_tower_hash_max; ++i) {
290 Identifier id = tower_id(i);
291 if (tower_hash(id) != i)
292 {
293 ATH_MSG_ERROR("***** Error tower ranges, id, hash, i = " << show_to_string(id));
294 ATH_MSG_ERROR(" , " << tower_hash(id));
295 ATH_MSG_ERROR(" , " << i);
296 }
297 }
298
299 return 0;
300
301}
302
303
304
305
306int CaloLVL1_ID::eta_min(const Identifier regId) const
307{
308 ExpandedIdentifier expId;
309 IdContext region_cntxt = region_context();
310 if(!get_expanded_id(regId, expId, &region_cntxt)) {
311 int result = -999;
312 for (unsigned int i = 0; i < m_full_tower_range.size(); ++i) {
313 const Range& range = m_full_tower_range[i];
314 if (range.match(expId)) {
315 const Range::field& eta_field = range[m_ETA_INDEX];
316 if (not eta_field.empty()) {
317 int etamin = eta_field.get_minimum();
318 if (-999 == result) {
319 result = etamin;
320 }
321 else {
322 if (etamin < result) result = etamin;
323 }
324 }
325 }
326 }
327 return (result);
328 }
329 return (-999);
330}
331
332int CaloLVL1_ID::eta_max(const Identifier regId) const
333{
334 ExpandedIdentifier expId;
335 IdContext region_cntxt = region_context();
336 if(!get_expanded_id(regId, expId, &region_cntxt)) {
337 int result = -999;
338 for (unsigned int i = 0; i < m_full_tower_range.size(); ++i) {
339 const Range& range = m_full_tower_range[i];
340 if (range.match(expId)) {
341 const Range::field& eta_field = range[m_ETA_INDEX];
342 if (not eta_field.empty()) {
343 int etamax = eta_field.get_maximum();
344 if (result < etamax) result = etamax;
345 }
346 }
347 }
348 return (result);
349 }
350 return (-999); // default
351}
352
353int CaloLVL1_ID::phi_max(const Identifier regId) const
354{
355 ExpandedIdentifier expId;
356 IdContext region_cntxt = region_context();
357 if(!get_expanded_id(regId, expId, &region_cntxt)) {
358 int result = -999;
359 for (unsigned int i = 0; i < m_full_tower_range.size(); ++i) {
360 const Range& range = m_full_tower_range[i];
361 if (range.match(expId)) {
362 const Range::field& phi_field = range[m_PHI_INDEX];
363 if (not phi_field.empty()) {
364 int phimax = phi_field.get_maximum();
365 if (result < phimax) result = phimax;
366 }
367 }
368 }
369 return (result);
370 }
371 return (-999); // default
372}
373
374int CaloLVL1_ID::layer_max(const Identifier regId) const
375{
376 ExpandedIdentifier expId;
377 IdContext region_cntxt = region_context();
378 if(!get_expanded_id(regId, expId, &region_cntxt)) {
379 int result = -999;
380 for (unsigned int i = 0; i < m_full_layer_range.size(); ++i) {
381 const Range& range = m_full_layer_range[i];
382 if (range.match(expId)) {
383 const Range::field& lay_field = range[m_LAYER_INDEX];
384 if (not lay_field.empty()) {
385 int laymax = lay_field.get_maximum();
386 if (result < laymax) result = laymax;
387 }
388 }
389 }
390 return (result);
391 }
392 return (-999); // default
393}
394
395int
397{
398 unsigned short index = id;
399 if (index < m_prev_phi_vec.size()) {
400 if (m_prev_phi_vec[index] == NOT_VALID_HASH) return (1);
401 prev = m_prev_phi_vec[index];
402 return (0);
403 }
404 return (1);
405}
406
407int
409{
410 unsigned short index = id;
411 if (index < m_next_phi_vec.size()) {
412 if (m_next_phi_vec[index] == NOT_VALID_HASH) return (1);
413 next = m_next_phi_vec[index];
414 return (0);
415 }
416 return (1);
417}
418
419int
421{
422 unsigned short index = id;
423 if (index < m_prev_eta_vec.size()) {
424 if (m_prev_eta_vec[index] == NOT_VALID_HASH) return (1);
425 prev = m_prev_eta_vec[index];
426 return (0);
427 }
428 return (1);
429}
430
431int
433{
434 unsigned short index = id;
435 if (index < m_next_eta_vec.size()) {
436 if (m_next_eta_vec[index] == NOT_VALID_HASH) return (1);
437 next = m_next_eta_vec[index];
438 return (0);
439 }
440 return (1);
441}
442
443
444 int CaloLVL1_ID::get_expanded_id (const Identifier& id, ExpandedIdentifier& exp_id, const IdContext* context) const
445{
446 // We assume that the context is >= region
447 exp_id.clear();
448 exp_id << calo_field_value()
449 << pos_neg_z(id)
450 << sampling(id)
451 << region(id);
452 if(context && context->end_index() >= m_ETA_INDEX) {
453 exp_id << eta(id);
454 if(context->end_index() >= m_PHI_INDEX) {
455 exp_id << phi(id);
456 if(context->end_index() >= m_LAYER_INDEX) {
457 exp_id << layer(id);
458 }
459 }
460 }
461 return (0);
462}
463
465 int eta, int phi ) const
466{
467 // Fill expanded id
469 id << pos_neg_z << sampling << region << eta << phi;
470
471 if (!m_full_tower_range.match(id)) {
472 std::string errorMessage = "CaloLVL1_ID::tower_id() result is not OK: ID, range = "
473 + std::string(id) + " , " + (std::string)m_full_tower_range;
474 throw CaloID_Exception(errorMessage , 2);
475 }
476}
477
478
480 int eta, int phi ) const
481{
482 // Fill expanded id
484
485 IdContext context = region_context();
486 if (get_expanded_id(regionId, id, &context)) {
487 std::string errorMessage = "CaloLVL1_ID::tower_id(regionId) result is not OK: ID= "
488 + show_to_string(regionId) ;
489 throw CaloID_Exception(errorMessage , 2);
490 }
491
492 id << eta << phi;
493
494 if (!m_full_tower_range.match(id)) {
495 std::string errorMessage = "CaloLVL1_ID::tower_id(regionId,field values) result is not OK: ID, range = "
496 + std::string(id) + " , " + (std::string)m_full_tower_range;
497 throw CaloID_Exception(errorMessage , 2);
498 }
499}
500
502{
503 // Fill expanded id
505 id << pos_neg_z << sampling << region ;
506
507 if (!m_full_region_range.match(id)) {
508 std::string errorMessage = "CaloLVL1_ID::region_id() result is not OK: ID, range = "
509 + std::string(id) + " , " + (std::string)m_full_region_range;
510 throw CaloID_Exception(errorMessage , 2);
511 }
512}
513
515 int eta, int phi, int layer ) const
516{
517 // Fill expanded id
519 id << pos_neg_z << sampling << region << eta << phi << layer;
520
521 if (!m_full_layer_range.match(id)) {
522 std::string errorMessage = "CaloLVL1_ID::layer_id(field values) result is not OK: ID, range = "
523 + std::string(id) + " , " + (std::string)m_full_layer_range;
524 throw CaloID_Exception(errorMessage , 2);
525 }
526}
527
529 int layer ) const
530{
531 // Fill expanded id
533
534 IdContext context = layer_context();
535 if (get_expanded_id(towerId, id, &context)) {
536 std::string errorMessage = "CaloLVL1_ID::layer_id(towerId, layer) result is not OK: ID= "
537 + show_to_string(towerId) ;
538 throw CaloID_Exception(errorMessage , 2);
539 }
540
541 id << layer;
542
543 if (!m_full_layer_range.match(id)) {
544 std::string errorMessage = "CaloLVL1_ID::layer_id(towerId) result is not OK: ID, range = "
545 + (std::string)id + " , " + (std::string)m_full_layer_range;
546 throw CaloID_Exception(errorMessage , 2);
547 }
548}
549
550
552{
553 if(!m_dict)
554 {
555 ATH_MSG_ERROR("initLevelsFromDict - dictionary NOT initialized");
556 return (1);
557 }
558
559 // Find out which identifier field corresponds to each level.
560
561 m_CALO_INDEX = 999 ;
562 m_DETZSIDE_INDEX = 999 ;
563 m_SAMPLING_INDEX = 999 ;
564 m_REGION_INDEX = 999 ;
565 m_ETA_INDEX = 999 ;
566 m_PHI_INDEX = 999 ;
567 m_LAYER_INDEX = 999 ;
568
569 // Save index to a LVL1 region for unpacking - search with region name
570 const IdDictRegion* reg = m_dict->find_region("Lvl1_0");
571 if (reg)
572 {
573 m_lvl1_region_index = reg->index();
574 }
575 else
576 {
577 ATH_MSG_ERROR("initLevelsFromDict - unable to find lvl1 region ");
578 return (1);
579 }
580
581 // Fing a LVL1 region
582 const IdDictField* field = m_dict->find_field("subdet") ;
583 if (field) {
584 m_CALO_INDEX = field->index();
585 }
586 else
587 {
588 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'subdet' field ");
589 return (1);
590 }
591
592 field = m_dict->find_field("DetZside") ;
593 if (field) {
594 m_DETZSIDE_INDEX = field->index();
595 }
596 else
597 {
598 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'DetZside' field ");
599 return (1);
600 }
601
602 field = m_dict->find_field("LVL1sampling") ;
603 if (field) {
604 m_SAMPLING_INDEX = field->index();
605 }
606 else
607 {
608 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'LVL1sampling' field ");
609 return (1);
610 }
611
612 field = m_dict->find_field("region") ;
613 if (field) {
614 m_REGION_INDEX = field->index();
615 }
616 else
617 {
618 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'region' field ");
619 return (1);
620 }
621
622 field = m_dict->find_field("eta") ;
623 if (field) {
624 m_ETA_INDEX = field->index();
625 }
626 else
627 {
628 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'eta' field ");
629 return (1);
630 }
631
632 field = m_dict->find_field("phi") ;
633 if (field) {
634 m_PHI_INDEX = field->index();
635 }
636 else
637 {
638 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'phi' field ");
639 return (1);
640 }
641
642 field = m_dict->find_field("layer") ;
643 if (field) {
644 m_LAYER_INDEX = field->index();
645 }
646 else
647 {
648 ATH_MSG_ERROR("initLevelsFromDict - unable to find 'layer' field ");
649 return (1);
650 }
651
652 // Set the field implementations
653
655
656 m_calo_impl = region.implementation(m_CALO_INDEX);
657 m_lvl1_impl = region.implementation(m_DETZSIDE_INDEX);
658 m_sampling_impl = region.implementation(m_SAMPLING_INDEX);
659 m_region_impl = region.implementation(m_REGION_INDEX);
660 m_eta_impl = region.implementation(m_ETA_INDEX);
661 m_phi_impl = region.implementation(m_PHI_INDEX);
662 m_layer_impl = region.implementation(m_LAYER_INDEX);
663
664 ATH_MSG_DEBUG("decode index and bit fields for each level: ");
665 ATH_MSG_DEBUG("calo " << m_calo_impl.show_to_string());
666 ATH_MSG_DEBUG("detzside " << m_lvl1_impl.show_to_string());
667 ATH_MSG_DEBUG("samp " << m_sampling_impl.show_to_string());
668 ATH_MSG_DEBUG("reg " << m_region_impl.show_to_string());
669 ATH_MSG_DEBUG("eta " << m_eta_impl.show_to_string());
670 ATH_MSG_DEBUG("phi " << m_phi_impl.show_to_string());
671 ATH_MSG_DEBUG("layer " << m_layer_impl.show_to_string());
672
673 return(0) ;
674}
675
676
678{
679 // tower hash
680 m_tower_hash_max = m_full_tower_range.cardinality();
682 unsigned int nids = 0;
683 std::set<Identifier> ids;
684 for (unsigned int i = 0; i < m_full_tower_range.size(); ++i) {
685 const Range& range = m_full_tower_range[i];
686 ConstRangeIterator rit(range);
687 auto first = rit.begin();
688 auto last = rit.end();
689 for (; first != last; ++first) {
690 const ExpandedIdentifier& exp_id = (*first);
691 Identifier tow_id = tower_id ( exp_id[m_DETZSIDE_INDEX],
692 exp_id[m_SAMPLING_INDEX],
693 exp_id[m_REGION_INDEX] ,
694 exp_id[m_ETA_INDEX] ,
695 exp_id[m_PHI_INDEX] ) ;
696 if(!(ids.insert(tow_id)).second)
697 {
698 ATH_MSG_ERROR("init_hashes duplicated id for TT id. nids= " << nids << " compact Id " << show_to_string(tow_id));
699 }
700 nids++;
701 }
702 }
703 if(ids.size() != m_tower_hash_max)
704 {
705 ATH_MSG_ERROR("init_hashes set size NOT EQUAL to hash max. size " << ids.size() << " hash max " << m_tower_hash_max);
706 return (1);
707 }
708
709 nids=0;
710 std::set<Identifier>::const_iterator first = ids.begin();
711 std::set<Identifier>::const_iterator last = ids.end();
712 for (;first != last && nids < m_tower_vec.size(); ++first) {
713 m_tower_vec[nids] = (*first) ;
714 nids++;
715 }
716
717 // layer hash
718 m_layer_hash_max = m_full_layer_range.cardinality();
720 nids = 0;
721 ids.clear();
722 for (unsigned int i = 0; i < m_full_layer_range.size(); ++i)
723 {
724 const Range& range = m_full_layer_range[i];
725 ConstRangeIterator rit(range);
726 auto first = rit.begin();
727 auto last = rit.end();
728 for (; first != last; ++first)
729 {
730 const ExpandedIdentifier& exp_id = (*first);
731 Identifier lay_id = layer_id ( exp_id[m_DETZSIDE_INDEX],
732 exp_id[m_SAMPLING_INDEX],
733 exp_id[m_REGION_INDEX] ,
734 exp_id[m_ETA_INDEX] ,
735 exp_id[m_PHI_INDEX] ,
736 exp_id[m_LAYER_INDEX] );
737 if(!(ids.insert(lay_id)).second)
738 {
739 ATH_MSG_ERROR("init_hashes duplicated id for extended TT id. nids= " << nids << " compact Id " << show_to_string(lay_id));
740 }
741 nids++;
742 }
743 }
744 if(ids.size() != m_layer_hash_max)
745 {
746 ATH_MSG_ERROR("init_hashes set size NOT EQUAL to hash max. size " << ids.size() << " hash max " << m_layer_hash_max);
747 return (1);
748 }
749
750 nids=0;
751 first = ids.begin();
752 last = ids.end();
753 for (;first != last && nids < m_layer_vec.size(); ++first) {
754 m_layer_vec[nids] = (*first) ;
755 nids++;
756 }
757
758
759 // region hash
762 nids = 0;
763 ids.clear();
764 for (unsigned int i = 0; i < m_full_region_range.size(); ++i) {
765 const Range& range = m_full_region_range[i];
766 ConstRangeIterator rit(range);
767 auto first = rit.begin();
768 auto last = rit.end();
769 for (; first != last; ++first) {
770 const ExpandedIdentifier& exp_id = (*first);
771 Identifier reg_id = region_id ( exp_id[m_DETZSIDE_INDEX],
772 exp_id[m_SAMPLING_INDEX],
773 exp_id[m_REGION_INDEX] );
774 if(!(ids.insert(reg_id)).second)
775 {
776 ATH_MSG_ERROR("init_hashes duplicated id for region id. nids= " << nids << " compact Id " << show_to_string(reg_id));
777 }
778 nids++;
779 }
780 }
781 if(ids.size() != m_region_hash_max)
782 {
783 ATH_MSG_ERROR("init_hashes set size NOT EQUAL to region hash max. size " << ids.size() << " region hash max " << m_region_hash_max);
784 return (1);
785 }
786 nids=0;
787 first = ids.begin();
788 last = ids.end();
789 for (;first != last && nids < m_region_vec.size(); ++first) {
790 m_region_vec[nids] = (*first) ;
791 nids++;
792 }
793
794 return (0);
795}
796
797
798
800{
805 for (unsigned int i = 0; i < m_full_tower_range.size(); ++i) {
806 const Range& range = m_full_tower_range[i];
807 ConstRangeIterator rit(range);
808 const Range::field& eta_field = range[m_ETA_INDEX];
809 const Range::field& phi_field = range[m_PHI_INDEX];
810 auto first = rit.begin();
811 auto last = rit.end();
812 for (; first != last; ++first) {
813 const ExpandedIdentifier& exp_id = (*first);
818 bool peta = eta_field.get_previous(exp_id[m_ETA_INDEX], previous_eta);
819 bool neta = eta_field.get_next (exp_id[m_ETA_INDEX], next_eta);
820 bool pphi = phi_field.get_previous(exp_id[m_PHI_INDEX], previous_phi);
821 bool nphi = phi_field.get_next (exp_id[m_PHI_INDEX], next_phi);
822
823 IdContext tcontext = tower_context();
824
825 // Get and save region id to speed things up
826 Identifier reg_id = region_id ( exp_id[m_DETZSIDE_INDEX],
827 exp_id[m_SAMPLING_INDEX],
828 exp_id[m_REGION_INDEX] );
829
830 // First get primary hash id
831 IdentifierHash hash_id;
832 Identifier id = tower_id (reg_id,
833 exp_id[m_ETA_INDEX],
834 exp_id[m_PHI_INDEX]);
835 if (get_hash(id, hash_id,&tcontext))
836 {
837 ATH_MSG_ERROR("init_neighbors - unable to get hash, compact");
838 return (1);
839 }
840
841 // index for the subsequent arrays
842 unsigned short index = hash_id;
843 assert (hash_id < m_prev_phi_vec.size());
844 assert (hash_id < m_next_phi_vec.size());
845 assert (hash_id < m_prev_eta_vec.size());
846 assert (hash_id < m_next_eta_vec.size());
847
848 if (pphi) {
849 // Get previous phi hash id
850 id = tower_id (reg_id,
851 exp_id[m_ETA_INDEX],
852 previous_phi);
853 // forward to compact -> hash
854 if (get_hash(id, hash_id,&tcontext))
855 {
856 ATH_MSG_ERROR("init_neighbors - unable to get previous phi hash, exp/compact");
857 return (1);
858 }
859 m_prev_phi_vec[index] = hash_id;
860 }
861
862 if (nphi) {
863 // Get next phi hash id
864 id = tower_id (reg_id,
865 exp_id[m_ETA_INDEX],
866 next_phi);
867 // forward to compact -> hash
868 if (get_hash(id, hash_id,&tcontext))
869 {
870 ATH_MSG_ERROR("init_neighbors - unable to get next phi hash, exp/compact");
871 return (1);
872 }
873 m_next_phi_vec[index] = hash_id;
874 }
875 if (peta) {
876 // Get previous eta hash id
877 id = tower_id (reg_id,
878 previous_eta,
879 exp_id[m_PHI_INDEX]);
880 // forward to compact -> hash
881 if (get_hash(id, hash_id,&tcontext))
882 {
883 ATH_MSG_ERROR("init_neighbors - unable to get previous eta hash, exp/compact");
884 return (1);
885 }
886 m_prev_eta_vec[index] = hash_id;
887 }
888
889 if (neta) {
890 // Get next eta hash id
891 id = tower_id (reg_id,
892 next_eta,
893 exp_id[m_PHI_INDEX]);
894 // forward to compact -> hash
895 if (get_hash(id, hash_id,&tcontext))
896 {
897 ATH_MSG_ERROR("init_neighbors - unable to get next eta hash, exp/compact");
898 return (1);
899 }
900 m_next_eta_vec[index] = hash_id;
901 } // end neta cond
902 } // end loop on identifiers
903 } // end loop on ranges
904 return (0);
905}
906
907
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Provide helper functions to create formatted strings.
#define min(a, b)
Definition cfImp.cxx:40
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 calo_field_value() const
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
const std::string & group() const
Group name for this helper.
ExpandedIdentifier calo_exp(void) const
AtlasDetectorID(const std::string &name, const std::string &group)
Exception class for Calo Identifiers.
small class holding the starting hash value, the min eta and the number of phi bins of each region
IdentifierHash m_hash
IdDictFieldImplementation m_region_impl
size_type m_tower_hash_max
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
access to hashes for neighbours in eta – towers only (no extended) return == 0 for neighbours found
size_type m_REGION_INDEX
size_type m_lvl1_region_index
MultiRange m_full_layer_range
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
access to hashes for neighbours in phi – towers only (no extended) return == 0 for neighbours found
IdentifierHash tower_hash(Identifier towerId) const
create hash id from tower id
int phi_max(const Identifier regId) const
min value of phi index (-999 == failure)
int eta_max(const Identifier regId) const
max value of eta index (-999 == failure)
size_type m_LAYER_INDEX
Identifier region_id(int pos_neg_z, int sampling, int region) const
build a region (of towers) identifier
int region(const Identifier id) const
return region according to :
size_type m_PHI_INDEX
std::vector< unsigned short > m_next_phi_vec
int initLevelsFromDict()
void region_id_checks(int pos_neg_z, int sampling, int region) const
size_type m_CALO_INDEX
size_type m_layer_hash_max
size_type m_DETZSIDE_INDEX
size_type m_region_hash_max
void layer_id_checks(int pos_neg_z, int sampling, int region, int eta, int phi, int layer) const
IdDictFieldImplementation m_layer_impl
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
access to hashes for neighbours in eta – towers only (no extended) return == 0 for neighbours found
IdDictFieldImplementation m_lvl1_impl
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const
create compact id from hash id (return == 0 for OK)
int layer_max(const Identifier regId) const
max value of phi index (-999 == failure)
size_type m_ETA_INDEX
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
initialization from the identifier dictionary
int eta_min(const Identifier regId) const
min value of eta index (-999 == failure)
MultiRange m_full_region_range
IdDictFieldImplementation m_eta_impl
std::vector< unsigned short > m_next_eta_vec
IdContext layer_context() const
access to IdContext's which define which levels of fields are contained in the id
IdDictFieldImplementation m_sampling_impl
std::vector< Identifier > m_tower_vec
int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
create expanded Identifier from Identifier (return == 0 for OK)
IdContext region_context() const
access to IdContext's which define which levels of fields are contained in the id
size_type m_SAMPLING_INDEX
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const
create hash id from compact id (return == 0 for OK)
int layer(const Identifier id) const
return layer according to :
std::vector< Identifier > m_region_vec
MultiRange m_full_tower_range
IdDictFieldImplementation m_phi_impl
IdDictFieldImplementation m_pnz_reg_impl
IdentifierHash tower_hash_binary_search(Identifier towerId) const
create hash id from tower id – method NOT optimised, please use tower_hash() above
virtual ~CaloLVL1_ID()
const IdDictDictionary * m_dict
int pos_neg_z(const Identifier id) const
return pos_neg_z according to :
std::vector< Identifier > m_layer_vec
int init_neighbors()
std::vector< unsigned short > m_prev_eta_vec
std::vector< HashCalc > m_hash_calcs
int sampling(const Identifier id) const
return sampling according to :
IdDictFieldImplementation m_calo_impl
Identifier tower_id(int pos_neg_z, int sampling, int region, int eta, int phi) const
build a tower identifier
int eta(const Identifier id) const
return eta according to :
std::vector< unsigned short > m_prev_phi_vec
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
access to hashes for neighbours in phi – towers only (no extended) return == 0 for neighbours found
IdContext tower_context() const
access to IdContext's which define which levels of fields are contained in the id
void tower_id_checks(int pos_neg_z, int sampling, int region, int eta, int phi) const
Identifier layer_id(int pos_neg_z, int sampling, int region, int eta, int phi, int layer) const
build a layer identifier
int phi(const Identifier id) const
return phi according to :
ConstRangeIterator end() const
ConstRangeIterator begin() const
void add(element_type value)
Append a value into a new field.
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
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
bool get_previous(element_type current, element_type &previous) const
Returns false if previous/next is at end of range, or not possible.
element_type get_minimum() const
Query the values.
bool empty() const
If true, this field does not have any constraints, and may hold any value representable by element_ty...
bool get_next(element_type current, element_type &next) const
element_type get_maximum() const
This is a "hash" representation of an Identifier.
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
std::string strformat(const char *fmt,...)
return a std::string according to a format fmt and varargs
Definition StrFormat.cxx:49
Definition index.py:1