ATLAS Offline Software
Loading...
Searching...
No Matches
HGTD_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
6// HGTD_ID.h, (c) ATLAS Detector software
8
9#ifndef HGTD_IDENTIFIER_HGTD_ID_H
10#define HGTD_IDENTIFIER_HGTD_ID_H
11
13#include "Identifier/Identifier.h"
17#include "Identifier/IdHelper.h"
20
21#include <string>
22#include <assert.h>
23#include <algorithm>
24
26
45
47{
48public:
49
51
52 typedef Identifier::size_type size_type;
53 typedef std::vector<Identifier>::const_iterator const_id_iterator;
56
58
59 HGTD_ID();
60 ~HGTD_ID();
62
64
65
67 int layer,
68 int phi_module,
69 int eta_module ) const;
70
73 Identifier wafer_id ( const Identifier& pixel_id ) const;
74
77
80 int layer,
81 int phi_module,
82 int eta_module,
83 int phi_index,
84 int eta_index) const;
85 Identifier pixel_id ( const Identifier& id,
86 int phi_index,
87 int eta_index) const;
89
91
95
97
98
106
109
111 int endcap (const Identifier& id) const;
112 int layer (const Identifier& id) const;
113 int phi_module (const Identifier& id) const;
114 int eta_module (const Identifier& id) const;
115 int phi_index (const Identifier& id) const;
116 int eta_index (const Identifier& id) const;
117
119 int layer_max (const Identifier& id) const;
120 int phi_module_max (const Identifier& id) const;
121 int eta_module_max (const Identifier& id) const;
122 int eta_module_min (const Identifier& id) const;
123 int phi_index_max (const Identifier& id) const;
124 int eta_index_max (const Identifier& id) const;
125
127
128
129 int get_prev_in_phi (const IdentifierHash& id, IdentifierHash& prev) const;
131 int get_next_in_phi (const IdentifierHash& id, IdentifierHash& next) const;
133 int get_prev_in_eta (const IdentifierHash& id, IdentifierHash& prev) const;
135 int get_next_in_eta (const IdentifierHash& id, IdentifierHash& next) const;
136
138 bool is_phi_module_max(const Identifier& id) const;
140
142
143 IdContext wafer_context () const;
144 IdContext pixel_context () const;
146
148
149
150 virtual int get_id (const IdentifierHash& hash_id,
151 Identifier& id,
152 const IdContext* context = 0) const;
153
155 virtual int get_hash (const Identifier& id,
156 IdentifierHash& hash_id,
157 const IdContext* context = 0) const;
159
160 // TODO: see if these commented out methods ported from PixelID class are needed
161
162 // /// Create a compact id from a value (e.g., from a persistent object).
163 // /// This repacks fields in case it's a special pixel channel id.
164 // Identifier pixel_id (Identifier::value_type val) const;
165
166 // /// Test if this is a valid shortened pixel channel id.
167 // bool is_shortened_pixel_id(Identifier32::value_type val) const;
168 // bool is_shortened_pixel_id(const Identifier32& id) const;
169 // bool is_shortened_pixel_id(const Identifier& id) const;
170
171 // /// Create a compact pixel id from a (fixed format) legacy
172 // /// pixel channel id. If compiled in 32-bit mode, this method
173 // /// does nothing.
174 // Identifier pixel_id_from_shortened(Identifier32::value_type val) const;
175
177 int base_bit () const;
178
180 Identifier::diff_type calc_offset(const Identifier& base,
181 const Identifier& target) const;
182
185 Identifier::diff_type offset) const;
186
188
189
192
194 void get_expanded_id (const Identifier& id,
195 ExpandedIdentifier& exp_id,
196 const IdContext* context = 0) const;
197
199 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr);
200
202 void test_wafer_packing () const;
203
204 // switch between identification schemes
206 void set_useNewIdentifierScheme(bool switchIntoNewIdentifier);
207 bool get_useNewIdentifierScheme() const;
208 std::string m_endcap_ID = "hgtd_endcap";
209 std::string m_layer_ID = "hgtd_layer";
210 std::string m_moduleInLayer_Or_Row = "hgtd_phi_module";
211 std::string m_moduleInRow = "hgtd_eta_module";
212 std::string m_padInModuleRow = "hgtd_phi_index";
213 std::string m_padInModuleColumn = "hgtd_eta_index";
215
216private:
217 enum {NOT_VALID_HASH = 64000,
218 MAX_BIT = Identifier::MAX_BIT,
219 BITS32 = Identifier::ALL_BITS };
220
221 typedef std::vector<Identifier> id_vec;
222 typedef id_vec::const_iterator id_vec_it;
223 typedef std::vector<unsigned short> hash_vec;
224 typedef hash_vec::const_iterator hash_vec_it;
225
226 void wafer_id_checks ( int endcap,
227 int layer,
228 int phi_module,
229 int eta_module ) const;
230 void pixel_id_checks ( int endcap,
231 int layer,
232 int phi_module,
233 int eta_module,
234 int phi_index,
235 int eta_index) const;
236
237 int initLevelsFromDict();
238
239 int init_hashes();
240
241 int init_neighbors();
242
252
258
260
265
274
275};
276
277//using the macros below we can assign an identifier (and a version)
278//This is required and checked at compile time when you try to record/retrieve
279CLASS_DEF(HGTD_ID, 79264207, 1)
280
281
282// Inline methods:
284
285//----------------------------------------------------------------------------
286inline Identifier
288 int layer,
289 int phi_module,
290 int eta_module ) const
291{
292
293 // Build identifier
294 Identifier result((Identifier::value_type)0);
295
296 // Pack fields independently
299 m_ec_impl.pack (endcap, result);
300 m_layer_impl.pack (layer, result);
303
304 // Do checks
305 if(m_do_checks) {
307 }
308
309 return result;
310}
311
312//----------------------------------------------------------------------------
313inline Identifier
315{
317 m_phi_index_impl.reset (result);
318 m_eta_index_impl.reset (result);
319 return (result);
320}
321
322//----------------------------------------------------------------------------
323inline Identifier
328
329//----------------------------------------------------------------------------
330inline Identifier
332 int layer,
333 int phi_module,
334 int eta_module,
335 int phi_index,
336 int eta_index) const
337{
338
339 // Build identifier
340 Identifier result((Identifier::value_type)0);
343 m_ec_impl.pack (endcap, result);
344 m_layer_impl.pack (layer, result);
349
350 if(m_do_checks) {
351
353 layer,
356 phi_index,
357 eta_index);
358 }
359
360 return result;
361}
362
365//----------------------------------------------------------------------------
366inline Identifier
368{
371 id[m_LAYER_INDEX],
376
377 if(m_do_checks) {
379 id[m_LAYER_INDEX],
384 }
385
386 return (result);
387}
388
389//----------------------------------------------------------------------------
390inline Identifier
392 int phi_index,
393 int eta_index) const
394{
396 m_phi_index_impl.reset (result);
397 m_eta_index_impl.reset (result);
400 return (result);
401}
402
403//----------------------------------------------------------------------------
405{
406 id_vec_it it = std::lower_bound(m_wafer_vec.begin(),
407 m_wafer_vec.end(),
408 wafer_id);
409 // Require that wafer_id matches the one in vector
410 if (it != m_wafer_vec.end() && wafer_id == (*it)) {
411 return (it - m_wafer_vec.begin());
412 }
414 return (result); // return hash in invalid state
415}
416
417//----------------------------------------------------------------------------
418inline Identifier::diff_type
419HGTD_ID::calc_offset(const Identifier& base, const Identifier& target) const
420{
421 Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit());
422 Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit());
423 return (tval - bval);
424}
425
426//----------------------------------------------------------------------------
427inline Identifier
429 Identifier::diff_type offset) const
430{
431 Identifier::value_type bval = base.get_compact() >> base_bit();
432 return Identifier((bval + offset) << base_bit());
433}
434
435//----------------------------------------------------------------------------
436inline int
438{
439 // TODO: determine if anything needs to change here (implementation ported from PixelID)
440 // TODO: e.g. m_eta_index_impl is still lowest field base, but where does the 32 come from? 32 bits?
441 // TODO: also understand what's happening
442 int base = static_cast<int>(m_eta_index_impl.shift()); // lowest field base
443 return (base > 32) ? 32 : base;
444 // max base is 32 so we can still read old strip id's and differences
445 // from non-SLHC releases.
446}
447
448//----------------------------------------------------------------------------
449inline IdContext
451{
453 return (IdContext(id, 0, m_ETA_MODULE_INDEX));
454}
455
456//----------------------------------------------------------------------------
457inline IdContext
459{
460 // For pixel only, the prefix is the first two levels
464}
465
466//----------------------------------------------------------------------------
467inline int
469{
470 return (m_ec_impl.unpack(id));
471}
472
473//----------------------------------------------------------------------------
474inline int
475HGTD_ID::layer (const Identifier& id) const
476{
477 return (m_layer_impl.unpack(id));
478}
479
480//----------------------------------------------------------------------------
481inline int
483{
484 return (m_phi_mod_impl.unpack(id));
485}
486
487//----------------------------------------------------------------------------
488inline int
490{
491 return (m_eta_mod_impl.unpack(id));
492}
493
494//----------------------------------------------------------------------------
495inline int
497{
498 return (m_phi_index_impl.unpack(id));
499}
500
501//----------------------------------------------------------------------------
502inline int
504{
505 return (m_eta_index_impl.unpack(id));
506}
507
508#endif // HGTD_IDENTIFIER_HGTD_ID_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
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
bool m_do_checks
Flag for subclasses to know whether or not to perform checks.
int hgtd_field_value() const
AtlasDetectorID(const std::string &name, const std::string &group)
int indet_field_value() const
Provide efficient access to individual field values, for subclass idhelpers.
This is an Identifier helper class for the HGTD subdetector.
Definition HGTD_ID.h:47
size_type m_HGTD_INDEX
Definition HGTD_ID.h:245
hash_vec m_next_phi_wafer_vec
Definition HGTD_ID.h:262
hash_vec::const_iterator hash_vec_it
Definition HGTD_ID.h:224
int init_hashes()
Definition HGTD_ID.cxx:277
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in phi (return == 0 for neighbor found)
Definition HGTD_ID.cxx:349
int eta_module(const Identifier &id) const
Definition HGTD_ID.h:489
int initLevelsFromDict()
Definition HGTD_ID.cxx:522
size_type m_ETA_MODULE_INDEX
Definition HGTD_ID.h:249
void pixel_id_checks(int endcap, int layer, int phi_module, int eta_module, int phi_index, int eta_index) const
Definition HGTD_ID.cxx:58
std::string m_padInModuleColumn
Definition HGTD_ID.h:213
size_type m_PHI_INDEX_INDEX
Definition HGTD_ID.h:250
IdDictFieldImplementation m_layer_impl
Definition HGTD_ID.h:269
@ NOT_VALID_HASH
Definition HGTD_ID.h:217
@ MAX_BIT
Definition HGTD_ID.h:218
@ BITS32
Definition HGTD_ID.h:219
hash_vec m_prev_eta_wafer_vec
Definition HGTD_ID.h:263
int eta_index(const Identifier &id) const
Definition HGTD_ID.h:503
std::string m_layer_ID
Definition HGTD_ID.h:209
Identifier wafer_id(int endcap, int layer, int phi_module, int eta_module) const
For a single crystal.
Definition HGTD_ID.h:287
void wafer_id_checks(int endcap, int layer, int phi_module, int eta_module) const
Definition HGTD_ID.cxx:39
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)
Definition HGTD_ID.cxx:772
id_vec m_wafer_vec
Definition HGTD_ID.h:259
void set_useNewIdentifierScheme(bool switchIntoNewIdentifier)
Definition HGTD_ID.cxx:511
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in eta (return == 0 for neighbor found)
Definition HGTD_ID.cxx:373
int phi_module_max(const Identifier &id) const
Definition HGTD_ID.cxx:99
size_type m_ENDCAP_INDEX
Definition HGTD_ID.h:246
Identifier pixel_id(int endcap, int layer, int phi_module, int eta_module, int phi_index, int eta_index) const
For an individual pixel.
Definition HGTD_ID.h:331
Identifier::diff_type calc_offset(const Identifier &base, const Identifier &target) const
Calculate a channel offset between the two identifiers.
Definition HGTD_ID.h:419
Identifier::size_type size_type
Definition HGTD_ID.h:52
size_type wafer_hash_max() const
Definition HGTD_ID.cxx:721
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in phi (return == 0 for neighbor found)
Definition HGTD_ID.cxx:337
int init_neighbors()
Definition HGTD_ID.cxx:385
MultiRange::const_identifier_factory const_expanded_id_iterator
Definition HGTD_ID.h:54
hash_vec m_next_eta_wafer_vec
Definition HGTD_ID.h:264
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition HGTD_ID.h:404
int phi_index(const Identifier &id) const
Definition HGTD_ID.h:496
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
Definition HGTD_ID.cxx:200
~HGTD_ID()
Definition HGTD_ID.cxx:35
MultiRange m_full_wafer_range
Definition HGTD_ID.h:254
size_type m_PHI_MODULE_INDEX
Definition HGTD_ID.h:248
IdContext pixel_context() const
Definition HGTD_ID.h:458
size_type m_LAYER_INDEX
Definition HGTD_ID.h:247
const_id_iterator wafer_end() const
Definition HGTD_ID.cxx:737
IdDictFieldImplementation m_phi_index_impl
Definition HGTD_ID.h:272
std::vector< unsigned short > hash_vec
Definition HGTD_ID.h:223
int eta_index_max(const Identifier &id) const
Definition HGTD_ID.cxx:175
IdContext wafer_context() const
Definition HGTD_ID.h:450
int phi_index_max(const Identifier &id) const
Definition HGTD_ID.cxx:156
id_vec::const_iterator id_vec_it
Definition HGTD_ID.h:222
size_type m_hgtd_region_index
Definition HGTD_ID.h:243
int eta_module_max(const Identifier &id) const
Definition HGTD_ID.cxx:118
const_id_iterator wafer_begin() const
Iterators over full set of ids. Wafer iterator is sorted.
Definition HGTD_ID.cxx:732
size_type m_ETA_INDEX_INDEX
Definition HGTD_ID.h:251
std::string m_moduleInLayer_Or_Row
Definition HGTD_ID.h:210
const IdDictDictionary * m_dict
Definition HGTD_ID.h:253
size_type pixel_hash_max() const
Definition HGTD_ID.cxx:727
int layer_max(const Identifier &id) const
Max/Min values for each field (error returns -999)
Definition HGTD_ID.cxx:80
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in eta (return == 0 for neighbor found)
Definition HGTD_ID.cxx:361
const_expanded_id_iterator pixel_end() const
Definition HGTD_ID.cxx:747
size_type m_INDET_INDEX
Definition HGTD_ID.h:244
int layer(const Identifier &id) const
Definition HGTD_ID.h:475
IdDictFieldImplementation m_phi_mod_impl
Definition HGTD_ID.h:270
std::vector< Identifier > id_vec
Definition HGTD_ID.h:221
Identifier pixel_id_offset(const Identifier &base, Identifier::diff_type offset) const
Create an identifier with a given base and channel offset.
Definition HGTD_ID.h:428
void test_wafer_packing() const
Tests of packing.
Definition HGTD_ID.cxx:833
IdDictFieldImplementation m_eta_index_impl
Definition HGTD_ID.h:273
bool get_useNewIdentifierScheme() const
Definition HGTD_ID.cxx:516
int endcap(const Identifier &id) const
Values of different levels (failure returns 0)
Definition HGTD_ID.h:468
void get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context=0) const
Create expanded id from compact id (return == 0 for OK)
Definition HGTD_ID.cxx:753
size_type m_wafer_hash_max
Definition HGTD_ID.h:256
const_expanded_id_iterator pixel_begin() const
For pixel ids, only expanded id iterators are available.
Definition HGTD_ID.cxx:742
std::vector< Identifier >::const_iterator const_id_iterator
Definition HGTD_ID.h:53
IdDictFieldImplementation m_hgtd_impl
Definition HGTD_ID.h:267
MultiRange m_full_pixel_range
Definition HGTD_ID.h:255
IdDictFieldImplementation m_indet_impl
Definition HGTD_ID.h:266
bool m_useNewIdentifierScheme
Definition HGTD_ID.h:205
std::string m_padInModuleRow
Definition HGTD_ID.h:212
IdDictFieldImplementation m_ec_impl
Definition HGTD_ID.h:268
int base_bit() const
Return the lowest bit position used in the channel id.
Definition HGTD_ID.h:437
hash_vec m_prev_phi_wafer_vec
Definition HGTD_ID.h:261
std::string m_moduleInRow
Definition HGTD_ID.h:211
IdDictFieldImplementation m_eta_mod_impl
Definition HGTD_ID.h:271
int eta_module_min(const Identifier &id) const
Definition HGTD_ID.cxx:137
bool is_phi_module_max(const Identifier &id) const
To check for when phi wrap around may be needed.
Definition HGTD_ID.cxx:194
std::string m_endcap_ID
Definition HGTD_ID.h:208
size_type m_pixel_hash_max
Definition HGTD_ID.h:257
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)
Definition HGTD_ID.cxx:799
HGTD_ID()
Definition HGTD_ID.cxx:17
int phi_module(const Identifier &id) const
Definition HGTD_ID.h:482
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::string base
Definition hcg.cxx:81