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