ATLAS Offline Software
CaloIDHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
14 #include "IdDict/IdDictMgr.h"
15 #include "IdDict/IdDictRegion.h"
16 #include "Identifier/Range.h"
17 #include "GaudiKernel/MsgStream.h"
18 
19 
20 
26  : m_end_index(99999)
27 {
28 }
29 
30 
43 int CaloIDHelper::HashGroup::init (const std::string& name,
44  const std::set<Identifier>& ids,
45  size_type end_index,
46  IMessageSvc* msgSvc,
47  const MultiRange* full_range)
48 {
49  m_end_index = end_index;
50  if (full_range && full_range->cardinality() != ids.size()) {
51  MsgStream log (msgSvc, "CaloIDHelper");
52  log << MSG::ERROR << name << " set size " << ids.size()
53  << " not equal to hash max " << full_range->cardinality() << endmsg;
54  return 1;
55  }
56  m_id_vec.assign (ids.begin(), ids.end());
57  return 0;
58 }
59 
60 
69  IdentifierHash& hash_id) const
70 {
71  std::vector<Identifier>::const_iterator it = std::lower_bound(m_id_vec.begin(),m_id_vec.end(),id);
72  if ( it != m_id_vec.end() ){
73  hash_id = it - m_id_vec.begin();
74  return 0;
75  }
76  return 1;
77 }
78 
79 
84 {
86  return IdContext (id, 0, m_end_index);
87 }
88 
89 
90 //*************************************************************************
91 
92 
99 CaloIDHelper::CaloIDHelper (const std::string& name,
100  const std::string& group)
102  m_name (name),
103  m_dict(nullptr)
104 {
105 }
106 
107 
122  Identifier& id,
123  const IdContext* context ) const
124 {
125  int result = 1;
126  id.clear();
127 
128  size_t begin = (context) ? context->begin_index(): 0;
129  size_t end = (context) ? context->end_index() : 0;
130 
131  if (0 == begin) {
132  const HashGroup* hg = nullptr;
133  if (m_channels.end_index() == end) hg = &m_channels;
134  else if (m_regions.end_index() == end) hg = &m_regions;
135 
136  if (hg) {
137  if (hash_id < hg->hash_max()) {
138  id = hg->id (hash_id);
139  result = 0;
140  }
141  }
142  }
143 
144  return(result);
145 }
146 
147 
163 int CaloIDHelper::get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context ) const
164 {
165  hash_id = IdentifierHash();
166 
167  size_t begin = (context) ? context->begin_index(): 0;
168  size_t end = (context) ? context->end_index() : 0;
169 
170  if (0 == begin) {
171  const HashGroup* hg = nullptr;
172  if (m_channels.end_index() == end) hg = &m_channels;
173  else if (m_regions.end_index() == end) hg = &m_regions;
174 
175  if (hg)
176  return hg->get_hash (id, hash_id);
177  }
178 
179  return 1;
180 }
181 
182 
188 {
189  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
190  return m_vecOfDictRegions[regHash]->deta();
191 }
192 
193 
199 {
200  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
201  return 2. * M_PI / m_vecOfDictRegions[regHash]->dphi();
202 }
203 
204 
209 float CaloIDHelper::eta0(const IdentifierHash regHash) const
210 {
211  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
212  return (m_vecOfDictRegions[regHash]->eta0());
213 }
214 
215 
220 float CaloIDHelper::phi0(const IdentifierHash regHash) const
221 {
222  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
223  return (m_vecOfDictRegions[regHash]->phi0());
224 }
225 
226 
233 int
235  const std::string& dict_name)
236 {
237  // init base object
238  if(AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return (1);
239 
240  // Register version of dictionary
241  if (register_dict_tag(dict_mgr, dict_name)) return(1);
242 
243  m_dict = dict_mgr.find_dictionary (dict_name);
244  if(!m_dict) {
245  MsgStream log(m_msgSvc, "CaloIDHelper" );
246  log << MSG::ERROR << " cannot access " << dict_name << "dictionary"
247  << endmsg;
248  return 1;
249  }
250  return 0;
251 }
252 
253 
260 int
262 {
263  m_vecOfDictRegions.clear();
264  m_vecOfDictRegions.reserve (regions().hash_max());
265  IdContext region_cntxt = region_context();
266  ExpandedIdentifier expRegId;
267  for (Identifier id : regions().range()) {
268  if(!get_expanded_id(id, expRegId, &region_cntxt)) {
269  m_vecOfDictRegions.push_back (m_dict->find_region(expRegId,group_name));
270  }
271  }
272  // cppcheck-suppress assertWithSideEffect
273  assert (m_vecOfDictRegions.size() == regions().hash_max());
274  return 0;
275 }
276 
277 
IdDictDictionary::find_region
IdDictRegion * find_region(const std::string &region_name) const
Definition: IdDictDictionary.cxx:101
IdDictMgr.h
CaloIDHelper::m_name
std::string m_name
Name of this helper.
Definition: CaloIDHelper.h:330
CaloIDHelper::NOT_VALID
@ NOT_VALID
Definition: CaloIDHelper.h:36
AtlasDetectorID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition: AtlasDetectorID.cxx:255
get_generator_info.result
result
Definition: get_generator_info.py:21
CaloIDHelper::fill_vec_of_dict_regions
int fill_vec_of_dict_regions(const std::string &group_name="")
Initialize the list of detector regions.
Definition: CaloIDHelper.cxx:261
IdDictDictionary.h
CaloIDHelper::HashGroup::init
int init(T &parent, const std::string &type, const MultiRange &full_range, Identifier(T::*idfunc)(const ExpandedIdentifier &) const, size_type end_index)
Initialize.
CaloIDHelper::HashGroup::end_index
size_type end_index() const
Return the ending index of the context for this group.
IdContext::end_index
size_type end_index() const
Definition: IdContext.h:46
CaloIDHelper::region_context
IdContext region_context() const
Return the context for regions.
Range.h
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CaloIDHelper::HashGroup::id
Identifier id(IdentifierHash hashId) const
Return the identifier for a given hash code (no checking).
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
CaloIDHelper::get_id
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const
Convert a hash code to an Identifier for either channels or regions, depending on the context.
Definition: CaloIDHelper.cxx:121
AtlasDetectorID::m_msgSvc
IMessageSvc * m_msgSvc
pointer to the message service
Definition: AtlasDetectorID.h:369
CaloIDHelper::HashGroup::get_hash
int get_hash(Identifier id, IdentifierHash &hash_id) const
Look up the hash code corresponding to an Identifier.
Definition: CaloIDHelper.cxx:68
CaloIDHelper::CaloIDHelper
CaloIDHelper(const std::string &name, const std::string &group)
Constructor.
Definition: CaloIDHelper.cxx:99
CaloIDHelper::regions
const HashGroup & regions() const
Return the HashGroup for regions.
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
CaloIDHelper::size_type
Identifier::size_type size_type
Definition: CaloIDHelper.h:39
CaloIDHelper::m_vecOfDictRegions
std::vector< const IdDictRegion * > m_vecOfDictRegions
List of IdDictRegion objects.
Definition: CaloIDHelper.h:342
IdDictMgr
Definition: IdDictMgr.h:15
IdContext::begin_index
size_type begin_index() const
Definition: IdContext.h:45
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:124
CaloIDHelper::etaGranularity
float etaGranularity(const IdentifierHash regHash) const
Return the eta granularity of a region, or NOT_VALID.
Definition: CaloIDHelper.cxx:187
CaloIDHelper::m_regions
HashGroup m_regions
Group of region Identifiers.
Definition: CaloIDHelper.h:336
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
CaloIDHelper::HashGroup::HashGroup
HashGroup()
Constructor.
Definition: CaloIDHelper.cxx:25
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
mc.group_name
group_name
Definition: mc.PhPy8EG_A14NNPDF23_NNLOPS_example.py:33
AtlasDetectorID::group
const std::string & group() const
Group name for this helper.
Definition: AtlasDetectorID.cxx:32
CaloIDHelper::initialize_base_from_dictionary
int initialize_base_from_dictionary(const IdDictMgr &dict_mgr, const std::string &dict_name)
Do basic initialization of the helper.
Definition: CaloIDHelper.cxx:234
AtlasDetectorID::register_dict_tag
int register_dict_tag(const IdDictMgr &dict_mgr, const std::string &dict_name)
Register the file and tag names for a particular IdDict dictionary.
Definition: AtlasDetectorID.cxx:201
MultiRange
A MultiRange combines several Ranges.
Definition: MultiRange.h:17
CaloIDHelper::eta0
float eta0(const IdentifierHash regHash) const
Return the minimum eta of region, or NOT_VALID.
Definition: CaloIDHelper.cxx:209
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
CaloIDHelper::name
const std::string & name() const
Return the name for this helper.
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
CaloIDHelper::get_hash
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const
Convert an Identifier to a hash code for either channels or regions, depending on the context.
Definition: CaloIDHelper.cxx:163
CaloIDHelper::m_dict
const IdDictDictionary * m_dict
The dictionary for this helper.
Definition: CaloIDHelper.h:339
CaloIDHelper::msgSvc
IMessageSvc * msgSvc()
Return the message service for this helper (may be null).
CaloIDHelper::phi0
float phi0(const IdentifierHash regHash) const
Return the minimum phi of region, or NOT_VALID.
Definition: CaloIDHelper.cxx:220
CaloIDHelper::m_channels
HashGroup m_channels
Group of channel (cell) Identifiers.
Definition: CaloIDHelper.h:333
CaloIDHelper.h
Base class to factor out code common among Calo ID helpers.
CaloIDHelper::HashGroup::context
IdContext context() const
Return the context for this group.
Definition: CaloIDHelper.cxx:83
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
IdDictRegion.h
CaloIDHelper::phiGranularity
float phiGranularity(const IdentifierHash regHash) const
Return the phi granularity of a region, or NOT_VALID.
Definition: CaloIDHelper.cxx:198
CaloIDHelper::get_expanded_id
virtual int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const =0
Create an expanded Identifier from an Identifier.
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition: MultiRange.cxx:82
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloIDHelper::HashGroup
Manage a list of identifiers.
Definition: CaloIDHelper.h:60
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
AtlasDetectorID
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Definition: AtlasDetectorID.h:52
Identifier
Definition: IdentifierFieldParser.cxx:14