ATLAS Offline Software
Loading...
Searching...
No Matches
JGTowerBase_ID.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
12#ifndef JGTOWERBASE_ID_H
13#define JGTOWERBASE_ID_H
14
20
22
23#include <vector>
24#include <ranges>
25#include <algorithm>
26
27class IdentifierHash;
28class IdDictRegion;
29
31{
32public:
33 enum { NOT_VALID=999999 };
34
35 typedef Identifier::size_type size_type ;
36
37 JGTowerBase_ID(const std::string& name, const std::string& group);
38
39 virtual ~JGTowerBase_ID();
40
43 int eta, int phi ) const ;
45 int eta, int phi, bool checks ) const ;
46
48 Identifier tower_id (const Identifier regionId,
49 int eta, int phi ) const ;
50 Identifier tower_id (const Identifier regionId,
51 int eta, int phi, bool checks ) const ;
52
54 Identifier region_id ( int pos_neg, int sampling, int region ) const;
55 Identifier region_id ( int pos_neg, int sampling, int region, bool checks ) const;
56
60
63 IdContext tower_context () const;
64
66 virtual int get_id (const IdentifierHash& hash_id, Identifier& id, const IdContext* context = 0 ) const;
67
69 virtual int get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context = 0 ) const;
70
72
74 Identifier region_id (IdentifierHash region_hash_id) const;
75
76 Identifier region_id ( const Identifier tower_Id ) const;
77
79 Identifier tower_id (IdentifierHash tower_hash_id) const;
80
82 IdentifierHash tower_hash (Identifier towerId) const;
85
87 virtual int initialize_base_from_dictionary (const IdDictMgr& dict_mgr, const std::string& t_pre);
88
91
94
95
97 using id_iterator = std::vector<Identifier>::const_iterator;
99 using id_range = std::ranges::subrange<id_iterator>;
100
101
103 id_iterator region_begin () const;
105 id_iterator region_end () const;
107 id_range reg_range () const;
108
110 id_iterator tower_begin () const;
112 id_iterator tower_end () const;
114 id_range tower_range () const;
115
116 // /** Test wether given tower or layer is part of the Tile Calorimeter
117 // @warning does NOT take as input a REGION identifier */
118 // bool has_tile (const Identifier id) const;
119 // /** Test wether given tower or layer is part of the EM barrel
120 // @warning does NOT take as input a REGION identifier
121 // @warning excluding 'barrel end'! */
122 // bool has_emb (const Identifier id) const;
123 // /** Test wether given tower or layer is part of the EM barrel END
124 // @warning does NOT take as input a REGION identifier */
125 // bool has_barrel_end (const Identifier id) const;
126 // /** Test wether given tower or layer is part of the EM end-cap
127 // @warning does NOT take as input a REGION identifier */
128 // bool has_emec (const Identifier id) const;
129 // /** Test wether given tower or layer is part of the HEC
130 // @warning does NOT take as input a REGION identifier */
131 // bool has_hec (const Identifier id) const;
132 // /** Test wether given tower or layer is part of the FCAL
133 // @warning does NOT take as input a REGION identifier */
134 // bool has_fcal (const Identifier id) const;
135
148 int pos_neg (const Identifier id)const;
149
163 int sampling (const Identifier id)const;
164
183 int region (const Identifier id)const;
184
207 int eta (const Identifier id)const;
208
231 int phi (const Identifier id)const;
232
235 int eta_min(const Identifier regId) const;
238 int eta_max(const Identifier regId) const;
241 int phi_max(const Identifier regId) const;
242
247 float etaGranularity(const Identifier regId) const;
248
253 float phiGranularity(const Identifier regId) const;
254
259 float eta0(const Identifier regId) const;
260
265 float phi0(const Identifier regId) const;
266
269 int get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const;
272 int get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const;
275 int get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const;
278 int get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const;
279
280 int fill_vec_of_dict_regions (const std::string& group_name = "");
281
282 const std::vector<const IdDictRegion*>& dictRegions() const;
283
284private:
285
286
287 enum {NOT_VALID_HASH = 64000};
288
289
291 int get_expanded_id (const Identifier& id, ExpandedIdentifier& exp_id, const IdContext* context) const;
292 void tower_id_checks (int pos_neg, int sampling, int region,
293 int eta, int phi ) const;
294 void tower_id_checks (const Identifier regionId,
295 int eta, int phi ) const;
296 void region_id_checks ( int pos_neg, int sampling, int region ) const;
297
298 int initLevelsFromDict(const std::string& t_pre) ;
299
300 int init_hashes();
301
302 int init_neighbors();
303
304
312
314
319 std::vector<Identifier> m_tower_vec;
320 std::vector<Identifier> m_region_vec;
321 std::vector<unsigned short> m_prev_phi_vec;
322 std::vector<unsigned short> m_next_phi_vec;
323 std::vector<unsigned short> m_prev_eta_vec;
324 std::vector<unsigned short> m_next_eta_vec;
325
327 std::vector<const IdDictRegion*> m_vecOfDictRegions;
328
335 {
336 public:
338 m_hash(0),
339 m_etamin(0),
340 m_nphi(0) {}
344 };
345 std::vector<HashCalc> m_hash_calcs;
346
347
348
355
357
358};
359
360//using the macros below we can assign an identifier (and a version)
361//This is required and checked at compile time when you try to record/retrieve
362CLASS_DEF( JGTowerBase_ID , 131336095, 1 )
363
365 int eta, int phi, bool checks ) const
366{
368 // Pack fields independently
373 m_eta_impl.pack (eta, result);
374 m_phi_impl.pack (phi, result);
375
376 // Do checks
377 if(checks) {
379 }
380
381 return result;
382}
383
385 int eta, int phi ) const
386{
388}
389
390//----------------------------------------------------------------------------
392 int eta, int phi, bool checks ) const
393{
394 Identifier result(regionId);
395
396 // Reset the fields and then set the values
397 m_eta_impl.reset (result);
398 m_phi_impl.reset (result);
399 m_eta_impl.pack (eta, result);
400 m_phi_impl.pack (phi, result);
401
402 // Do checks
403 if(checks) {
404 tower_id_checks( regionId, eta, phi );
405 }
406
407 return result;
408}
409
411 int eta, int phi ) const
412{
413 return tower_id (regionId, eta, phi, do_checks());
414}
415
416
417//----------------------------------------------------------------------------
422
423//----------------------------------------------------------------------------
428
429
430//----------------------------------------------------------------------------
432{
433 return(m_region_vec.begin());
434}
435
436//----------------------------------------------------------------------------
438{
439 return(m_region_vec.end());
440}
441
442//----------------------------------------------------------------------------
447
448//----------------------------------------------------------------------------
450{
451 return(m_tower_vec.begin());
452}
453
454//----------------------------------------------------------------------------
456{
457 return(m_tower_vec.end());
458}
459
460//----------------------------------------------------------------------------
465
466//----------------------------------------------------------------------------
467inline int JGTowerBase_ID::pos_neg(const Identifier id) const
468{
469 return (m_jgtower_impl.unpack(id));
470}
471
472//----------------------------------------------------------------------------
473inline int JGTowerBase_ID::sampling(const Identifier id) const
474{
475 return (m_sampling_impl.unpack(id));
476}
477//----------------------------------------------------------------------------
478inline int JGTowerBase_ID::region(const Identifier id) const
479{
480 return (m_region_impl.unpack(id));
481}
482
483//----------------------------------------------------------------------------
484inline int JGTowerBase_ID::eta(const Identifier id) const
485{
486 return (m_eta_impl.unpack(id));
487}
488
489//----------------------------------------------------------------------------
490inline int JGTowerBase_ID::phi(const Identifier id) const
491{
492 return (m_phi_impl.unpack(id));
493}
494
495// //----------------------------------------------------------------------------
496// inline bool JGTowerBase_ID::has_tile (const Identifier id) const
497// {
498// // Must first check if this is a normal tile id
499// if (AtlasDetectorID::is_tile(id)) {
500// return (true);
501// }
502// /* else { */
503// /* return (has_jgtower_trig_towers(id) && region(id) == 0 && sampling(id) == 1 && eta(id) < 15); */
504// /* } */
505// }
506
507// //----------------------------------------------------------------------------
508// inline bool JGTowerBase_ID::has_emb (const Identifier id) const
509// {
510// return true;//(has_jgtower_trig_towers(id) && region(id) == 0 && sampling(id) == 0 && eta(id) < 14);
511// }
512
513// //----------------------------------------------------------------------------
514// inline bool JGTowerBase_ID::has_barrel_end (const Identifier id) const
515// {
516// return true;//(has_jgtower_trig_towers(id) && region(id) == 0 && sampling(id) == 0 && eta(id) == 14);
517// }
518
519// //----------------------------------------------------------------------------
520// inline bool JGTowerBase_ID::has_emec (const Identifier id) const
521// {
522// return true;//(has_jgtower_trig_towers(id) && sampling(id) == 0 &&
523// //((region(id) == 0 && eta(id) > 14) || region(id) == 1 || region(id) == 2 ));
524// }
525
526// //----------------------------------------------------------------------------
527// inline bool JGTowerBase_ID::has_hec (const Identifier id) const
528// {
529// return true;//(has_jgtower_trig_towers(id) && sampling(id) == 1 &&
530// //((region(id) == 0 && eta(id) > 14) || region(id) == 1 || region(id) == 2 ));
531// }
532
533// //----------------------------------------------------------------------------
534// inline bool JGTowerBase_ID::has_fcal (const Identifier id) const
535// {
536// return true;//(has_jgtower_trig_towers(id) && region(id) == 3 );
537// }
538
539//----------------------------------------------------------------------------
541{
542 return(m_region_vec[region_hash_id]);
543}
544//----------------------------------------------------------------------------
545inline Identifier JGTowerBase_ID::region_id ( const Identifier tower_Id ) const
546{
547 Identifier result(tower_Id);
548 // reset eta, phi, layer
549 m_eta_impl.reset(result);
550 m_phi_impl.reset(result);
551 return (result);
552}
553
554//----------------------------------------------------------------------------
556 bool checks) const
557{
559 // Pack fields independently
564
565 // Do checks
566 if(checks) {
568 }
569
570 return result;
571}
572
574{
576}
577
578
579//----------------------------------------------------------------------------
581{
582 return(m_tower_vec[tower_hash_id]);
583}
584
585//----------------------------------------------------------------------------
587{
588 const HashCalc& hc = m_hash_calcs[m_pnz_reg_impl.unpack(towerId)];
589 return (hc.m_hash + (eta(towerId)-hc.m_etamin)*hc.m_nphi + phi(towerId));
590}
591
592//----------------------------------------------------------------------------
594{
595 std::vector<Identifier>::const_iterator it = std::lower_bound(m_tower_vec.begin(),m_tower_vec.end(),towerId);
596 if ( it != m_tower_vec.end() ){
597 return (it - m_tower_vec.begin());
598 }
599 return (0);
600}
601
602inline
603const std::vector<const IdDictRegion*>& JGTowerBase_ID::dictRegions() const
604{ return m_vecOfDictRegions;
605}
606
607#endif // CALOJGTOWER_ID_H
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
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
const std::string & group() const
Group name for this helper.
AtlasDetectorID(const std::string &name, const std::string &group)
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.
small class holding the starting hash value, the min eta and the number of phi bins of each region
int sampling(const Identifier id) const
return sampling according to :
int fill_vec_of_dict_regions(const std::string &group_name="")
id_iterator tower_end() const
end iterator over towers
float eta0(const Identifier regId) const
Return the minimum eta of region, or NOT_VALID.
id_range tower_range() const
range over towers
int eta_max(const Identifier regId) const
max value of eta index (-999 == failure)
Identifier::size_type size_type
std::vector< Identifier >::const_iterator id_iterator
Type for iterators over identifiers.
IdDictFieldImplementation m_region_impl
size_type m_calo_region_hash_max
int region(const Identifier id) const
return region according to :
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
std::vector< unsigned short > m_next_phi_vec
size_type tower_hash_max() const
tower hash table max size
IdentifierHash tower_hash_binary_search(Identifier towerId) const
create hash id from tower id – method NOT optimised, please use tower_hash() above
int eta_min(const Identifier regId) const
min value of eta index (-999 == failure)
int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
create expanded Identifier from Identifier (return == 0 for OK)
size_type m_PHI_INDEX
int pos_neg(const Identifier id) const
Test wether given tower or layer is part of the Tile Calorimeter.
float phiGranularity(const Identifier regId) const
Return the phi granularity of a region, or NOT_VALID.
std::vector< Identifier > m_tower_vec
size_type m_REGION_INDEX
size_type m_tower_hash_max
IdDictFieldImplementation m_sampling_impl
JGTowerBase_ID(const std::string &name, const std::string &group)
const IdDictDictionary * m_dict
size_type m_SAMPLING_INDEX
int phi_max(const Identifier regId) const
min value of phi index (-999 == failure)
int phi(const Identifier id) const
return phi according to :
id_range reg_range() const
range over regions
id_iterator tower_begin() const
begin iterator over towers
IdentifierHash calo_region_hash(const Identifier id) const
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 initLevelsFromDict(const std::string &t_pre)
id_iterator region_begin() const
begin iterator over regions
size_type calo_region_hash_max() const
region hash table max size
std::vector< unsigned short > m_prev_phi_vec
size_type m_CALO_INDEX
IdentifierHash tower_hash(Identifier towerId) const
create hash id from tower id
std::vector< HashCalc > m_hash_calcs
size_type m_jgtower_region_index
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
virtual int initialize_base_from_dictionary(const IdDictMgr &dict_mgr, const std::string &t_pre)
initialization from the identifier dictionary
IdContext tower_context() const
access to IdContext's which define which levels of fields are contained in the id
MultiRange m_full_tower_range
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)
std::vector< unsigned short > m_next_eta_vec
std::vector< unsigned short > m_prev_eta_vec
IdContext region_context() const
access to IdContext's which define which levels of fields are contained in the id
Identifier tower_id(int pos_neg, int sampling, int region, int eta, int phi) const
build a tower identifier
MultiRange m_full_reg_range
id_iterator region_end() const
end iterator over regions
std::vector< const IdDictRegion * > m_vecOfDictRegions
List of IdDictRegion objects.
IdDictFieldImplementation m_eta_impl
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
void tower_id_checks(int pos_neg, int sampling, int region, int eta, int phi) const
std::ranges::subrange< id_iterator > id_range
Type for range over identifiers.
Identifier region_id(int pos_neg, int sampling, int region) const
build a region (of towers) identifier
IdDictFieldImplementation m_jgtower_impl
float etaGranularity(const Identifier regId) const
Return the eta granularity of a region, or NOT_VALID.
const std::vector< const IdDictRegion * > & dictRegions() const
IdDictFieldImplementation m_phi_impl
std::vector< Identifier > m_region_vec
float phi0(const Identifier regId) const
Return the minimum phi of region, or NOT_VALID.
IdDictFieldImplementation m_pnz_reg_impl
int eta(const Identifier id) const
return eta according to :
void region_id_checks(int pos_neg, int sampling, int region) const
IdDictFieldImplementation m_calo_impl
size_type m_DETZSIDE_INDEX
virtual ~JGTowerBase_ID()
size_type m_ETA_INDEX
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
A MultiRange combines several Ranges.
Definition MultiRange.h:17