ATLAS Offline Software
Loading...
Searching...
No Matches
CaloIDHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
10
14#include "IdDict/IdDictMgr.h"
15#include "IdDict/IdDictRegion.h"
16#include "Identifier/Range.h"
17#include "GaudiKernel/MsgStream.h"
18
19
20
29
30
41int CaloIDHelper::HashGroup::init (const std::string& name,
42 const std::set<Identifier>& ids,
44 const MultiRange* full_range)
45{
47 if (full_range && full_range->cardinality() != ids.size()) {
48 MsgStream log(Athena::getMessageSvc(), name);
49 log << MSG::ERROR << "set size " << ids.size()
50 << " not equal to hash max " << full_range->cardinality() << endmsg;
51 return 1;
52 }
53 m_id_vec.assign (ids.begin(), ids.end());
54 return 0;
55}
56
57
66 IdentifierHash& hash_id) const
67{
68 std::vector<Identifier>::const_iterator it = std::lower_bound(m_id_vec.begin(),m_id_vec.end(),id);
69 if ( it != m_id_vec.end() ){
70 hash_id = it - m_id_vec.begin();
71 return 0;
72 }
73 return 1;
74}
75
76
85
86
87//*************************************************************************
88
89
96CaloIDHelper::CaloIDHelper (const std::string& name,
97 const std::string& group)
99 m_name (name),
100 m_dict(nullptr)
101{
102}
103
104
119 Identifier& id,
120 const IdContext* context ) const
121{
122 int result = 1;
123 id.clear();
124
125 size_t begin = (context) ? context->begin_index(): 0;
126 size_t end = (context) ? context->end_index() : 0;
127
128 if (0 == begin) {
129 const HashGroup* hg = nullptr;
130 if (m_channels.end_index() == end) hg = &m_channels;
131 else if (m_regions.end_index() == end) hg = &m_regions;
132
133 if (hg) {
134 if (hash_id < hg->hash_max()) {
135 id = hg->id (hash_id);
136 result = 0;
137 }
138 }
139 }
140
141 return(result);
142}
143
144
160int CaloIDHelper::get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context ) const
161{
162 hash_id = IdentifierHash();
163
164 size_t begin = (context) ? context->begin_index(): 0;
165 size_t end = (context) ? context->end_index() : 0;
166
167 if (0 == begin) {
168 const HashGroup* hg = nullptr;
169 if (m_channels.end_index() == end) hg = &m_channels;
170 else if (m_regions.end_index() == end) hg = &m_regions;
171
172 if (hg)
173 return hg->get_hash (id, hash_id);
174 }
175
176 return 1;
177}
178
179
185{
186 if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
187 return m_vecOfDictRegions.at(regHash)->deta();
188}
189
190
196{
197 if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
198 return 2. * M_PI / m_vecOfDictRegions.at(regHash)->dphi();
199}
200
201
206float CaloIDHelper::eta0(const IdentifierHash regHash) const
207{
208 if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
209 return (m_vecOfDictRegions.at(regHash)->eta0());
210}
211
212
217float CaloIDHelper::phi0(const IdentifierHash regHash) const
218{
219 if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
220 return (m_vecOfDictRegions.at(regHash)->phi0());
221}
222
223
230int
232 const std::string& dict_name)
233{
234 // init base object
235 if(AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return (1);
236
237 // Register version of dictionary
238 if (register_dict_tag(dict_mgr, dict_name)) return(1);
239
240 m_dict = dict_mgr.find_dictionary (dict_name);
241 if(!m_dict) {
242 ATH_MSG_ERROR("cannot access " << dict_name << "dictionary");
243 return 1;
244 }
245 return 0;
246}
247
248
255int
256CaloIDHelper::fill_vec_of_dict_regions (const std::string& group_name /*= ""*/)
257{
258 m_vecOfDictRegions.clear();
259 m_vecOfDictRegions.reserve (regions().hash_max());
260 IdContext region_cntxt = region_context();
261 ExpandedIdentifier expRegId;
262 for (Identifier id : regions().range()) {
263 if(!get_expanded_id(id, expRegId, &region_cntxt)) {
264 m_vecOfDictRegions.push_back (m_dict->find_region(expRegId,group_name));
265 }
266 }
267 // cppcheck-suppress assertWithSideEffect
268 assert (m_vecOfDictRegions.size() == regions().hash_max());
269 return 0;
270}
271
272
#define M_PI
#define endmsg
#define ATH_MSG_ERROR(x)
Base class to factor out code common among Calo ID helpers.
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
int register_dict_tag(const IdDictMgr &dict_mgr, const std::string &dict_name)
Register the file and tag names for a particular IdDict dictionary.
const std::string & group() const
Group name for this helper.
AtlasDetectorID(const std::string &name, const std::string &group)
Manage a list of identifiers.
IdContext context() const
Return the context for this group.
Identifier id(IdentifierHash hashId) const
Return the identifier for a given hash code (no checking).
const std::vector< Identifier > & ids() const
Return a vector of all Identifiers for this group.
size_type m_end_index
Ending index for this group's context.
size_type end_index() const
Return the ending index of the context for this group.
std::vector< Identifier > m_id_vec
List of Identifiers for this group.
int init(T &parent, const std::string &type, const MultiRange &full_range, Identifier(T::*idfunc)(const ExpandedIdentifier &) const, size_type end_index)
Initialize.
int get_hash(Identifier id, IdentifierHash &hash_id) const
Look up the hash code corresponding to an Identifier.
float phi0(const IdentifierHash regHash) const
Return the minimum phi of region, or NOT_VALID.
const HashGroup & regions() const
Return the HashGroup for regions.
float eta0(const IdentifierHash regHash) const
Return the minimum eta of region, or NOT_VALID.
float etaGranularity(const IdentifierHash regHash) const
Return the eta granularity of a region, or NOT_VALID.
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.
virtual int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const =0
Create an expanded Identifier from an Identifier.
int initialize_base_from_dictionary(const IdDictMgr &dict_mgr, const std::string &dict_name)
Do basic initialization of the helper.
IdContext region_context() const
Return the context for regions.
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.
std::vector< const IdDictRegion * > m_vecOfDictRegions
List of IdDictRegion objects.
HashGroup m_regions
Group of region Identifiers.
CaloIDHelper(const std::string &name, const std::string &group)
Constructor.
Identifier::size_type size_type
const IdDictDictionary * m_dict
The dictionary for this helper.
int fill_vec_of_dict_regions(const std::string &group_name="")
Initialize the list of detector regions.
float phiGranularity(const IdentifierHash regHash) const
Return the phi granularity of a region, or NOT_VALID.
HashGroup m_channels
Group of channel (cell) Identifiers.
std::string m_name
Name of this helper.
const std::string & name() const
Return the name for this helper.
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.
This is a "hash" representation of an Identifier.
A MultiRange combines several Ranges.
Definition MultiRange.h:17
size_type cardinality() const
Computes a possible cardinality from all ranges.
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)