ATLAS Offline Software
Loading...
Searching...
No Matches
MuonIdHelper.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 DETECTORDESCRIPTION_MUONIDHELPER_H
6#define DETECTORDESCRIPTION_MUONIDHELPER_H
7
13#include <set>
14#include <map>
15#include <string>
16#include <vector>
17
19
20
21// ******************************************************************************
22// class MuonIdHelper
23// ******************************************************************************
24//
25// Description
26// -----------
27// This is a base class for the Muon Identifier and Range factory classes.
28// ATLAS note ATL-MUON-2001-014 provides a complete description of the
29// hierarchical identifier scheme. MuonIdHelper provides an interface to the
30// common station "prefix" of the identifier, as described below.
31//
32// Field Value Notes
33// ==============================================================================
34// StationName [0..n] maps to "BIL", "EMS", "T1F", etc.
35// there can be holes in the list of indices
36// StationEta integer increases with eta (0 at eta=0)
37// StationPhi non-zero integer increases with phi
38// Technology [0..5] maps to "MDT", "CSC", "RPC", "TGC", "STGC", "MM"
39// ==============================================================================
40//
41// Inheritance
42// -----------
43// Inherits from DetectorDescription/AtlasDetectorID.
44// It is inherited by the following technology-specific concrete classes.
45//
46// MdtIdHelper factory of MDT-specific Identifiers and Ranges
47// CscIdHelper factory of CSC-specific Identifiers and Ranges
48// RpcIdHelper factory of RPC-specific Identifiers and Ranges
49// TgcIdHelper factory of TGC-specific Identifiers and Ranges
50
51// for nSW
52// sTgcIdHelper factory of sTGC-specific Identifiers and Ranges
53// MmIdHelper factory of MicroMegas-specific Identifiers and Ranges
54
55//
56// Methods for External Use
57// ------------------------
58// int stationNameIndex(const std::string name) (returns stationName index)
59// int technologyIndex(const std::string name) (returns technology index)
60// std::string stationNameString(const int index) (returns stationName string)
61// std::string technologyString(const int index) (returns technology string)
62//
63// Author
64// ------
65// Steven Goldfarb <Steven.Goldfarb@cern.ch>
66//
67// Compact Id implementation by
68// Ketevi A. Assamagan <ketevi@bnl.gov>
69// CERN, February 20th, 2003
70//
71
72// for nSW
73// Nektarios Chr. Benekos <nectarios.benekos@cern.ch>
74// CERN, Feb. 2013
75// ******************************************************************************
76
78public:
79 // Constructor
80
81 MuonIdHelper(const std::string& logName, const std::string& group);
82
83 // Destructor
84
85 virtual ~MuonIdHelper() = default;
86
87 // Build identifier
88
89 Identifier muon() const;
90
91
92 // Extract station parts
93
94 int stationName(const Identifier& id) const;
95 int stationEta(const Identifier& id) const;
96 int stationPhi(const Identifier& id) const;
97 int technology(const Identifier& id) const;
98
99 // Methods used by Moore
100
101 int stationRegion(const Identifier& id) const;
102
103 bool isBarrel(const Identifier& id) const;
104 bool isEndcap(const Identifier& id) const;
105 bool isForward(const Identifier& id) const;
106 bool isSmall(const Identifier& id) const;
107 bool isBarrel(const int stationNameIndex) const;
108 bool isEndcap(const int stationNameIndex) const;
109 bool isForward(const int stationNameIndex) const;
110 bool isSmall(const int stationNameIndex) const;
111
112 // Access to name and technology maps
113
114 int stationNameIndex(const std::string& name) const;
115 int technologyIndex(const std::string& name) const;
116 const std::string& stationNameString(const Identifier& id) const;
117 const std::string& stationNameString(const int index) const;
118 const std::string& technologyString(const int index) const;
119 int nStationNames() const;
120
121
122 // Check whether helper is fully initialized
123 bool isInitialized() const;
124
126
127public:
128 typedef Identifier::size_type size_type;
130 typedef std::vector<Identifier>::const_iterator const_id_iterator;
131
133 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr) override;
134
147
149 virtual int gasGap(const Identifier& id) const = 0;
150 virtual int channel(const Identifier& id) const = 0;
151 virtual bool measuresPhi(const Identifier& id) const = 0;
152 virtual int get_module_hash(const Identifier& id, IdentifierHash& hash_id) const;
153 virtual int get_detectorElement_hash(const Identifier& id, IdentifierHash& hash_id) const;
154 virtual int get_channel_hash(const Identifier& id, IdentifierHash& hash_id) const;
155
157 virtual int get_id(const IdentifierHash& hash_id, Identifier& id, const IdContext* context = 0) const override;
158
160 virtual int get_hash(const Identifier& id, IdentifierHash& hash_id, const IdContext* context = 0) const override;
161
163 int get_expanded_id(const Identifier& id, ExpandedIdentifier& exp_id, const IdContext* context) const;
164
167 int get_id(const ExpandedIdentifier& old_id, Identifier& new_id) const;
169 const MultiRange& multiRange() const;
170
175
177 const std::vector<Identifier>& idVector() const;
178
184
190
196
199 int get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const;
200 int get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const;
201 int get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const;
202 int get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const;
203
205 void test_module_packing() const;
206 void test_id(const Identifier& id, const IdContext& context) const;
207
208 int stationNameIndexMax() const;
209 int technologyNameIndexMax() const;
210
211 static const std::string BAD_NAME;
212
213protected:
214 static constexpr int NOT_VALID_HASH = 64000;
215
216 typedef std::vector<Identifier> id_vec;
217 typedef id_vec::const_iterator id_vec_it;
218 typedef std::vector<unsigned short> hash_vec;
219 typedef hash_vec::const_iterator hash_vec_it;
220
221 int initLevelsFromDict();
222 int init_hashes();
223 virtual int init_detectorElement_hashes();
225 int init_neighbors();
226
227 // Create expanded id from compact id (return == 0 for OK)
228 int get_expanded_id_calc(const Identifier& compact_id, ExpandedIdentifier& id, const IdContext* context) const;
229
230 // Create compact id from expanded or hash id (return == 0 for OK)
231 int get_compact_id(const ExpandedIdentifier& id, Identifier& compact_id, const IdContext* context) const;
232 // Create hash from compact
233 virtual int get_hash_calc(const Identifier& compact_id, IdentifierHash& hash_id, const IdContext* context) const;
234
239 virtual bool isStNameInTech(const std::string& stationName) const = 0;
240
241 std::set<int> m_stationInTech{};
242
245 size_t m_GROUP_INDEX{6500};
253 const IdDictDictionary* m_dict{nullptr};
254
259
264
269
274
280
282
283protected:
284 // Check values down to station level
285
286 bool validStation(int stationName, int technology) const;
287 bool validStation(int stationName) const;
288 bool validTechnology(int technology) const;
289
290 // Append station ID fields
291
292 void addStationID(Identifier& id, int stationName, int stationEta, int stationPhi, int technology) const;
293
294 static void addStationID(ExpandedIdentifier& id, int stationName, int stationEta, int stationPhi, int technology) ;
295
296 inline void resetAndSet(const IdDictFieldImplementation & dict, const int new_val, Identifier& id ) const {
297 dict.reset(id);
298 dict.pack(new_val,id);
299 }
300private:
301 // Copy constructor - do not use!
302 MuonIdHelper(const MuonIdHelper& other) = delete;
304
305 // vectors for stationNames and technologies
306
308 std::map<std::string, int> m_stationNameToIdxMap;
310 std::map<int, std::string> m_stationIdxToNameMap;
311
312 int m_stationIndexMax{-INT_MAX};
314 std::map<std::string, int> m_technologyNameToIdxMap;
316 std::map<int, std::string> m_technologyIdxToNameMap;
317 int m_technologyIndexMax{-INT_MAX};
318
319 // little helpers to speed things up
320 std::set<int> m_isBarrel;
321 std::set<int> m_isSmall;
322 std::set<int> m_isForward;
323
324 // Constants
325
327
328protected:
329 bool m_init{false};
330};
331
332// For backwards compatibility
333
335
336// Access to the ID
337
338#endif // DETECTORDESCRIPTION_MUONIDHELPER_H
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
MuonIdHelper MuonID
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.
A MultiRange combines several Ranges.
Definition MultiRange.h:17
std::vector< Identifier >::const_iterator const_id_iterator
int stationNameIndex(const std::string &name) const
virtual int get_channel_hash(const Identifier &id, IdentifierHash &hash_id) const
int stationEta(const Identifier &id) const
std::set< int > m_isForward
const std::string & technologyString(const int index) const
const_id_iterator module_end() const
IdDictFieldImplementation m_phi_impl
size_t m_GROUP_INDEX
IdDictFieldImplementation m_tec_impl
int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
Create expanded id from compact id (return == 0 for OK)
MultiRange m_muon_range
const_id_iterator module_begin() const
Iterators over full set of ids.
virtual int get_detectorElement_hash(const Identifier &id, IdentifierHash &hash_id) const
const std::string & stationNameString(const Identifier &id) const
void test_id(const Identifier &id, const IdContext &context) const
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
size_type m_PHI_INDEX
std::map< int, std::string > m_technologyIdxToNameMap
Mapping int -> string.
const MultiRange & multiRange() const
multirange
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override
Create compact id from hash id (return == 0 for OK)
size_type m_CHANNEL_INDEX
virtual int get_hash_calc(const Identifier &compact_id, IdentifierHash &hash_id, const IdContext *context) const
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
void test_module_packing() const
Tests of packing.
hash_vec m_next_phi_module_vec
int technologyIndex(const std::string &name) const
size_type m_station_region_index
std::vector< unsigned short > hash_vec
IdDictFieldImplementation m_sta_impl
hash_vec m_prev_eta_module_vec
const_id_iterator channel_end() const
size_type m_NAME_INDEX
static const std::string BAD_NAME
std::map< int, std::string > m_stationIdxToNameMap
Mapping int -> string.
MultiRange m_full_module_range
MultiRange m_muon_channel_range
id_vec m_channel_vec
IdDictFieldImplementation m_eta_impl
bool validTechnology(int technology) const
void addStationID(Identifier &id, int stationName, int stationEta, int stationPhi, int technology) const
int get_compact_id(const ExpandedIdentifier &id, Identifier &compact_id, const IdContext *context) const
Identifier muon() const
bool isEndcap(const Identifier &id) const
MuonIdHelper(const MuonIdHelper &other)=delete
virtual ~MuonIdHelper()=default
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const
MultiRange::const_identifier_factory const_expanded_id_iterator
size_type module_hash_max() const
the maximum hash value
const std::vector< Identifier > & idVector() const
the id's
bool isForward(const Identifier &id) const
MultiRange m_full_detectorElement_range
size_type m_ETA_INDEX
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
const IdDictDictionary * m_dict
int nStationNames() const
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
MultiRange m_muon_detectorElement_range
std::vector< Identifier > id_vec
IdContext module_context() const
id for module
int stationNameIndexMax() const
int stationRegion(const Identifier &id) const
IdContext technology_context() const
access to IdContext's which define which levels or fields are contained in the Muon id
int stationPhi(const Identifier &id) const
size_type m_DETECTORELEMENT_INDEX
int technology(const Identifier &id) const
int stationName(const Identifier &id) const
MuonIdHelper & operator=(const MuonIdHelper &right)
int init_channel_hashes()
virtual bool measuresPhi(const Identifier &id) const =0
int initLevelsFromDict()
size_type channel_hash_max() const
const_id_iterator channel_begin() const
Iterators over full set of ids.
size_type m_module_hash_max
bool isBarrel(const Identifier &id) const
bool isSmall(const Identifier &id) const
int m_technologyIndexMax
IdContext detectorElement_context() const
id for detector element
hash_vec m_next_eta_module_vec
id_vec m_detectorElement_vec
virtual int init_detectorElement_hashes()
virtual int gasGap(const Identifier &id) const =0
get the hashes
hash_vec::const_iterator hash_vec_it
int technologyNameIndexMax() const
hash_vec m_prev_phi_module_vec
size_type detectorElement_hash_max() const
virtual bool isStNameInTech(const std::string &stationName) const =0
The valid element checks converted the identifier to a stationName string in order to assess whether ...
IdDictFieldImplementation m_muon_impl
void resetAndSet(const IdDictFieldImplementation &dict, const int new_val, Identifier &id) const
std::set< int > m_isBarrel
size_type m_MODULE_INDEX
virtual int channel(const Identifier &id) const =0
bool validStation(int stationName, int technology) const
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const override
Create hash id from compact id (return == 0 for OK)
size_type m_detectorElement_hash_max
const_id_iterator detectorElement_end() const
static constexpr int NOT_VALID_HASH
Identifier::size_type size_type
std::map< std::string, int > m_stationNameToIdxMap
Mapping string -> int.
MultiRange m_full_channel_range
IdContext channel_context() const
id for channel
std::set< int > m_stationInTech
size_type m_channel_hash_max
std::set< int > m_isSmall
bool isInitialized() const
MuonIdHelper(const std::string &logName, const std::string &group)
id_vec::const_iterator id_vec_it
int get_expanded_id_calc(const Identifier &compact_id, ExpandedIdentifier &id, const IdContext *context) const
size_type m_MUON_INDEX
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
id_vec m_module_vec
size_type m_TECHNOLOGY_INDEX
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
Access to hashes for neighbors in phi and eta (return == 0 for neighbor found)
std::map< std::string, int > m_technologyNameToIdxMap
Mapping string -> int.
Definition index.py:1