ATLAS Offline Software
Loading...
Searching...
No Matches
CaloLVL1_ID.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef CALOLVL1_ID_H
6#define CALOLVL1_ID_H
7
13
15
16#include <vector>
17#include <ranges>
18#include <algorithm>
19
20
63class IdentifierHash;
64
66{
67public:
68
69 typedef Identifier::size_type size_type ;
70
71
73
74 virtual ~CaloLVL1_ID();
75
78 int eta, int phi ) const ;
80 int eta, int phi, bool checks ) const ;
81
83 Identifier tower_id (const Identifier regionId,
84 int eta, int phi ) const ;
85 Identifier tower_id (const Identifier regionId,
86 int eta, int phi, bool checks ) const ;
87
89 Identifier tower_id (const Identifier layerId) const;
90
92 Identifier region_id ( int pos_neg_z, int sampling, int region ) const;
93 Identifier region_id ( int pos_neg_z, int sampling, int region, bool checks) const;
94
96 Identifier region_id ( const Identifier tower_or_layerId ) const;
97
98
101 int eta, int phi, int layer ) const;
103 int eta, int phi, int layer,
104 bool checks) const;
105
107 Identifier layer_id ( const Identifier towerId, int layer ) const;
108 Identifier layer_id ( const Identifier towerId, int layer, bool checks ) const;
109
110
113 IdContext region_context () const;
114
117 IdContext tower_context () const;
118
121 IdContext layer_context () const;
122
124 virtual int get_id (const IdentifierHash& hash_id, Identifier& id, const IdContext* context = 0 ) const;
125
127 virtual int get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context = 0 ) const;
128
130 Identifier region_id (IdentifierHash region_hash_id) const;
131
133 Identifier tower_id (IdentifierHash tower_hash_id) const;
134
136 IdentifierHash tower_hash (Identifier towerId) const;
139
141 virtual int initialize_from_dictionary (const IdDictMgr& dict_mgr);
142
144 size_type tower_hash_max () const;
146 size_type layer_hash_max () const;
148 size_type region_hash_max () const;
149
150
152 using id_iterator = std::vector<Identifier>::const_iterator;
154 using id_range = std::ranges::subrange<id_iterator>;
155
156
158 id_iterator region_begin () const;
160 id_iterator region_end () const;
162 id_range region_range () const;
163
165 id_iterator tower_begin () const;
167 id_iterator tower_end () const;
169 id_range tower_range () const;
170
172 id_iterator layer_begin () const;
174 id_iterator layer_end () const;
176 id_range layer_range () const;
177
180 bool is_tile (const Identifier id) const;
184 bool is_emb (const Identifier id) const;
187 bool is_barrel_end (const Identifier id) const;
190 bool is_emec (const Identifier id) const;
193 bool is_hec (const Identifier id) const;
196 bool is_fcal (const Identifier id) const;
197
210 int pos_neg_z (const Identifier id)const;
211
225 int sampling (const Identifier id)const;
226
239 int region (const Identifier id)const;
240
256 int eta (const Identifier id)const;
257
273 int phi (const Identifier id)const;
274
288 int layer (const Identifier id)const;
289
290
293 int eta_min(const Identifier regId) const;
296 int eta_max(const Identifier regId) const;
299 int phi_max(const Identifier regId) const;
302 int layer_max(const Identifier regId) const;
303
306 int get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const;
309 int get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const;
312 int get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const;
315 int get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const;
316
317private:
318
319
320 enum {NOT_VALID_HASH = 64000};
321
322
324 int get_expanded_id (const Identifier& id, ExpandedIdentifier& exp_id, const IdContext* context) const;
325
326
327 void tower_id_checks (int pos_neg_z, int sampling, int region,
328 int eta, int phi ) const;
329 void tower_id_checks (const Identifier regionId,
330 int eta, int phi ) const;
331 void region_id_checks ( int pos_neg_z, int sampling, int region ) const;
332
333 void layer_id_checks ( int pos_neg_z, int sampling, int region,
334 int eta, int phi, int layer ) const;
335 void layer_id_checks ( const Identifier towerId,
336 int layer ) const;
337
338
339 int initLevelsFromDict();
340
341 int init_hashes();
342
343 int init_neighbors();
344
345
354
356
363 std::vector<Identifier> m_tower_vec;
364 std::vector<Identifier> m_layer_vec;
365 std::vector<Identifier> m_region_vec;
366 std::vector<unsigned short> m_prev_phi_vec;
367 std::vector<unsigned short> m_next_phi_vec;
368 std::vector<unsigned short> m_prev_eta_vec;
369 std::vector<unsigned short> m_next_eta_vec;
370
377 {
378 public:
380 m_hash(0),
381 m_etamin(0),
382 m_nphi(0) {}
386 };
387 std::vector<HashCalc> m_hash_calcs;
388
389
390
398
400
401};
402
403//using the macros below we can assign an identifier (and a version)
404//This is required and checked at compile time when you try to record/retrieve
405CLASS_DEF( CaloLVL1_ID , 108133391 , 1 )
406
407
408//----------------------------------------------------------------------------
410 int eta, int phi, bool checks ) const
411{
413 // Pack fields independently
418 m_eta_impl.pack (eta, result);
419 m_phi_impl.pack (phi, result);
420
421 // Do checks
422 if(checks) {
424 }
425
426 return result;
427}
428
430 int eta, int phi ) const
431{
433}
434
435
436//----------------------------------------------------------------------------
438 int eta, int phi, bool checks ) const
439{
440 Identifier result(regionId);
441
442 // Reset the fields and then set the values
443 m_eta_impl.reset (result);
444 m_phi_impl.reset (result);
445 m_eta_impl.pack (eta, result);
446 m_phi_impl.pack (phi, result);
447
448 // Do checks
449 if(checks) {
450 tower_id_checks( regionId, eta, phi );
451 }
452
453 return result;
454}
455
457 int eta, int phi ) const
458{
459 return tower_id (regionId, eta, phi, do_checks());
460}
461
462
463//----------------------------------------------------------------------------
464inline Identifier CaloLVL1_ID::region_id ( const Identifier tower_or_layerId ) const
465{
466 Identifier result(tower_or_layerId);
467 // reset eta, phi, layer
468 m_eta_impl.reset(result);
469 m_phi_impl.reset(result);
470 m_layer_impl.reset(result);
471 return (result);
472}
473
474//----------------------------------------------------------------------------
475inline Identifier CaloLVL1_ID::tower_id ( const Identifier layerId ) const
476{
477 Identifier result(layerId);
478 // reset layer
479 m_layer_impl.reset(result);
480 return (result);
481}
482
483//----------------------------------------------------------------------------
485 bool checks)const
486{
488 // Pack fields independently
493
494 // Do checks
495 if(checks) {
497 }
498
499 return result;
500}
501
503{
505}
506
507//----------------------------------------------------------------------------
509 int eta, int phi, int layer,
510 bool checks) const
511{
513 // Pack fields independently
518 m_eta_impl.pack (eta, result);
519 m_phi_impl.pack (phi, result);
520 m_layer_impl.pack (layer, result);
521
522 // Do checks
523 if(checks) {
525 }
526
527 return result;
528}
529
531 int eta, int phi, int layer ) const
532{
534}
535
536//----------------------------------------------------------------------------
538 int layer, bool checks ) const
539{
540 Identifier result(towerId);
541
542 // Reset the fields and then set the values
543 m_layer_impl.reset (result);
544 m_layer_impl.pack (layer, result);
545 // Do checks
546 if(checks) {
547 layer_id_checks( towerId, layer );
548 }
549
550 return result;
551}
552
554 int layer ) const
555{
556 return layer_id (towerId, layer, do_checks());
557}
558
559//----------------------------------------------------------------------------
564
565//----------------------------------------------------------------------------
570
571//----------------------------------------------------------------------------
576
577
578//----------------------------------------------------------------------------
580{
581 return(m_region_vec.begin());
582}
583
584//----------------------------------------------------------------------------
586{
587 return(m_region_vec.end());
588}
589
590//----------------------------------------------------------------------------
595
596//----------------------------------------------------------------------------
598{
599 return(m_tower_vec.begin());
600}
601
602//----------------------------------------------------------------------------
604{
605 return(m_tower_vec.end());
606}
607
608//----------------------------------------------------------------------------
613
614//----------------------------------------------------------------------------
615
617{
618 return(m_layer_vec.begin());
619}
620
621//----------------------------------------------------------------------------
623{
624 return(m_layer_vec.end());
625}
626
627
628//----------------------------------------------------------------------------
633
634//----------------------------------------------------------------------------
635inline int CaloLVL1_ID::pos_neg_z(const Identifier id) const
636{
637 return (m_lvl1_impl.unpack(id));
638}
639
640//----------------------------------------------------------------------------
641inline int CaloLVL1_ID::sampling(const Identifier id) const
642{
643 return (m_sampling_impl.unpack(id));
644}
645
646//----------------------------------------------------------------------------
647inline int CaloLVL1_ID::region(const Identifier id) const
648{
649 return (m_region_impl.unpack(id));
650}
651
652//----------------------------------------------------------------------------
653inline int CaloLVL1_ID::eta(const Identifier id) const
654{
655 return (m_eta_impl.unpack(id));
656}
657
658//----------------------------------------------------------------------------
659inline int CaloLVL1_ID::phi(const Identifier id) const
660{
661 return (m_phi_impl.unpack(id));
662}
663
664//----------------------------------------------------------------------------
665inline int CaloLVL1_ID::layer(const Identifier id) const
666{
667 return (m_layer_impl.unpack(id));
668}
669
670
671//----------------------------------------------------------------------------
672inline bool CaloLVL1_ID::is_tile (const Identifier id) const
673{
674 // Must first check if this is a normal tile id
675 if (AtlasDetectorID::is_tile(id)) {
676 return (true);
677 }
678 else {
679 return (is_lvl1_trig_towers(id) && region(id) == 0 && sampling(id) == 1 && eta(id) < 15);
680 }
681}
682
683//----------------------------------------------------------------------------
684inline bool CaloLVL1_ID::is_emb (const Identifier id) const
685{
686 return (is_lvl1_trig_towers(id) && region(id) == 0 && sampling(id) == 0 && eta(id) < 14);
687}
688
689//----------------------------------------------------------------------------
690inline bool CaloLVL1_ID::is_barrel_end (const Identifier id) const
691{
692 return (is_lvl1_trig_towers(id) && region(id) == 0 && sampling(id) == 0 && eta(id) == 14);
693}
694
695//----------------------------------------------------------------------------
696inline bool CaloLVL1_ID::is_emec (const Identifier id) const
697{
698 return (is_lvl1_trig_towers(id) && sampling(id) == 0 &&
699 ((region(id) == 0 && eta(id) > 14) || region(id) == 1 || region(id) == 2 ));
700}
701
702//----------------------------------------------------------------------------
703inline bool CaloLVL1_ID::is_hec (const Identifier id) const
704{
705 return (is_lvl1_trig_towers(id) && sampling(id) == 1 &&
706 ((region(id) == 0 && eta(id) > 14) || region(id) == 1 || region(id) == 2 ));
707}
708
709//----------------------------------------------------------------------------
710inline bool CaloLVL1_ID::is_fcal (const Identifier id) const
711{
712 return (is_lvl1_trig_towers(id) && region(id) == 3 );
713}
714
715//----------------------------------------------------------------------------
717{
718 return(m_region_vec[region_hash_id]);
719}
720
721//----------------------------------------------------------------------------
723{
724 return(m_tower_vec[tower_hash_id]);
725}
726
727//----------------------------------------------------------------------------
729{
730 const HashCalc& hc = m_hash_calcs[m_pnz_reg_impl.unpack(towerId)];
731 return (hc.m_hash + (eta(towerId)-hc.m_etamin)*hc.m_nphi + phi(towerId));
732}
733
734//----------------------------------------------------------------------------
736{
737 std::vector<Identifier>::const_iterator it = std::lower_bound(m_tower_vec.begin(),m_tower_vec.end(),towerId);
738 if ( it != m_tower_vec.end() ){
739 return (it - m_tower_vec.begin());
740 }
741 return (0);
742}
743
744
745
746#endif // CALOLVL1_ID_H
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
virtual bool do_checks(void) const override
Checks are performed by default in debug compilation and NOT in optimized compilation.
int calo_field_value() const
bool is_tile(Identifier id) const
AtlasDetectorID(const std::string &name, const std::string &group)
bool is_lvl1_trig_towers(Identifier id) const
small class holding the starting hash value, the min eta and the number of phi bins of each region
IdentifierHash m_hash
Helper class for offline TT identifiers.
Definition CaloLVL1_ID.h:66
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
bool is_barrel_end(const Identifier id) const
Test wether given tower or layer is part of the EM barrel END.
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
std::ranges::subrange< id_iterator > id_range
Type for range over identifiers.
int initLevelsFromDict()
id_range region_range() const
range over regions
void region_id_checks(int pos_neg_z, int sampling, int region) const
bool is_emb(const Identifier id) const
Test wether given tower or layer is part of the EM barrel.
size_type m_CALO_INDEX
size_type m_layer_hash_max
size_type m_DETZSIDE_INDEX
id_iterator tower_begin() const
begin iterator over towers
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
bool is_tile(const Identifier id) const
Test wether given tower or layer is part of the Tile Calorimeter.
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
bool is_emec(const Identifier id) const
Test wether given tower or layer is part of the EM end-cap.
Identifier::size_type size_type
Definition CaloLVL1_ID.h:69
id_iterator region_begin() const
begin iterator over regions
IdDictFieldImplementation m_lvl1_impl
id_iterator layer_begin() const
begin iterators over layers
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
bool is_fcal(const Identifier id) const
Test wether given tower or layer is part of the FCAL.
int eta_min(const Identifier regId) const
min value of eta index (-999 == failure)
MultiRange m_full_region_range
id_iterator tower_end() const
end iterator over towers
IdDictFieldImplementation m_eta_impl
std::vector< unsigned short > m_next_eta_vec
size_type tower_hash_max() const
tower hash table max size
id_iterator region_end() const
end iterator over regions
id_iterator layer_end() const
end iterators over layers
IdContext layer_context() const
access to IdContext's which define which levels of fields are contained in the id
std::vector< Identifier >::const_iterator id_iterator
Type for iterators over identifiers.
id_range layer_range() const
range over layers
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 :
bool is_hec(const Identifier id) const
Test wether given tower or layer is part of the HEC.
std::vector< Identifier > m_region_vec
MultiRange m_full_tower_range
IdDictFieldImplementation m_phi_impl
IdDictFieldImplementation m_pnz_reg_impl
id_range tower_range() const
range over towers
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
size_type layer_hash_max() const
layer hash table max size
size_type region_hash_max() const
region hash table max size
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 :
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
This is a "hash" representation of an Identifier.
A MultiRange combines several Ranges.
Definition MultiRange.h:17