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 <vector>
23#include <algorithm> //std::lower_bound
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
269 static constexpr std::array<std::string_view, nImplementations> m_implNames{
270 "indet", "hgtd", "ec", "layer",
271 "phi_mod", "eta_mod", "phi_index",
272 "eta_index"
273 };
274 //
275 std::array<IdDictFieldImplementation, nImplementations> m_impl;
276
277};
278
279//using the macros below we can assign an identifier (and a version)
280//This is required and checked at compile time when you try to record/retrieve
281CLASS_DEF(HGTD_ID, 79264207, 1)
282
283
284// Inline methods:
286
287//----------------------------------------------------------------------------
288inline Identifier
290 int layer,
291 int phi_module,
292 int eta_module ) const
293{
294
295 // Build identifier
296 Identifier result((Identifier::value_type)0);
297
298 // Pack fields independently
299 m_impl[kIndet].pack (indet_field_value(), result);
300 m_impl[kHgtd].pack (hgtd_field_value(), result);
301 m_impl[kEc].pack (endcap, result);
302 m_impl[kLayer].pack (layer, result);
303 m_impl[kPhiMod].pack (phi_module, result);
304 m_impl[kEtaMod].pack (eta_module, result);
305
306 // Do checks
307 if(m_do_checks) {
309 }
310
311 return result;
312}
313
314//----------------------------------------------------------------------------
315inline Identifier
317{
318 Identifier result(pixel_id);
319 m_impl[kPhiIndex].reset (result);
320 m_impl[kEtaIndex].reset (result);
321 return (result);
322}
323
324//----------------------------------------------------------------------------
325inline Identifier
330
331//----------------------------------------------------------------------------
332inline Identifier
334 int layer,
335 int phi_module,
336 int eta_module,
337 int phi_index,
338 int eta_index) const
339{
340
341 // Build identifier
342 Identifier result((Identifier::value_type)0);
343 m_impl[kIndet].pack (indet_field_value(), result);
344 m_impl[kHgtd].pack (hgtd_field_value(), result);
345 m_impl[kEc].pack (endcap, result);
346 m_impl[kLayer].pack (layer, result);
347 m_impl[kPhiMod].pack (phi_module, result);
348 m_impl[kEtaMod].pack (eta_module, result);
349 m_impl[kPhiIndex].pack (phi_index, result);
350 m_impl[kEtaIndex].pack (eta_index, result);
351
352 if(m_do_checks) {
353
355 layer,
358 phi_index,
359 eta_index);
360 }
361
362 return result;
363}
364
367//----------------------------------------------------------------------------
368inline Identifier
370{
371 Identifier result;
372 result = pixel_id(id[m_ENDCAP_INDEX],
373 id[m_LAYER_INDEX],
378
379 if(m_do_checks) {
381 id[m_LAYER_INDEX],
386 }
387
388 return (result);
389}
390
391//----------------------------------------------------------------------------
392inline Identifier
394 int phi_index,
395 int eta_index) const
396{
397 Identifier result(wafer_id);
398 m_impl[kPhiIndex].reset (result);
399 m_impl[kEtaIndex].reset (result);
400 m_impl[kPhiIndex].pack (phi_index, result);
401 m_impl[kEtaIndex].pack (eta_index, result);
402 return (result);
403}
404
405//----------------------------------------------------------------------------
407{
408 id_vec_it it = std::lower_bound(m_wafer_vec.begin(),
409 m_wafer_vec.end(),
410 wafer_id);
411 // Require that wafer_id matches the one in vector
412 if (it != m_wafer_vec.end() && wafer_id == (*it)) {
413 return (it - m_wafer_vec.begin());
414 }
415 IdentifierHash result;
416 return (result); // return hash in invalid state
417}
418
419//----------------------------------------------------------------------------
420inline Identifier::diff_type
421HGTD_ID::calc_offset(const Identifier& base, const Identifier& target) const
422{
423 Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit());
424 Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit());
425 return (tval - bval);
426}
427
428//----------------------------------------------------------------------------
429inline Identifier
431 Identifier::diff_type offset) const
432{
433 Identifier::value_type bval = base.get_compact() >> base_bit();
434 return Identifier((bval + offset) << base_bit());
435}
436
437//----------------------------------------------------------------------------
438inline int
440{
441 // TODO: determine if anything needs to change here (implementation ported from PixelID)
442 // TODO: e.g. m_eta_index_impl is still lowest field base, but where does the 32 come from? 32 bits?
443 // TODO: also understand what's happening
444 int base = static_cast<int>(m_impl[kEtaIndex].shift()); // lowest field base
445 return (base > 32) ? 32 : base;
446 // max base is 32 so we can still read old strip id's and differences
447 // from non-SLHC releases.
448}
449
450//----------------------------------------------------------------------------
451inline IdContext
453{
455 return (IdContext(id, 0, m_ETA_MODULE_INDEX));
456}
457
458//----------------------------------------------------------------------------
459inline IdContext
461{
462 // For pixel only, the prefix is the first two levels
466}
467
468//----------------------------------------------------------------------------
469inline int
471{
472 return (m_impl[kEc].unpack(id));
473}
474
475//----------------------------------------------------------------------------
476inline int
477HGTD_ID::layer (const Identifier& id) const
478{
479 return (m_impl[kLayer].unpack(id));
480}
481
482//----------------------------------------------------------------------------
483inline int
485{
486 return (m_impl[kPhiMod].unpack(id));
487}
488
489//----------------------------------------------------------------------------
490inline int
492{
493 return (m_impl[kEtaMod].unpack(id));
494}
495
496//----------------------------------------------------------------------------
497inline int
499{
500 return (m_impl[kPhiIndex].unpack(id));
501}
502
503//----------------------------------------------------------------------------
504inline int
506{
507 return (m_impl[kEtaIndex].unpack(id));
508}
509
510#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:279
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:351
int eta_module(const Identifier &id) const
Definition HGTD_ID.h:491
int initLevelsFromDict()
Definition HGTD_ID.cxx:524
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:60
std::string m_padInModuleColumn
Definition HGTD_ID.h:213
size_type m_PHI_INDEX_INDEX
Definition HGTD_ID.h:250
@ 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:505
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:289
void wafer_id_checks(int endcap, int layer, int phi_module, int eta_module) const
Definition HGTD_ID.cxx:41
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:715
id_vec m_wafer_vec
Definition HGTD_ID.h:259
void set_useNewIdentifierScheme(bool switchIntoNewIdentifier)
Definition HGTD_ID.cxx:513
std::array< IdDictFieldImplementation, nImplementations > m_impl
Definition HGTD_ID.h:275
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:375
int phi_module_max(const Identifier &id) const
Definition HGTD_ID.cxx:101
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:333
Identifier::diff_type calc_offset(const Identifier &base, const Identifier &target) const
Calculate a channel offset between the two identifiers.
Definition HGTD_ID.h:421
Identifier::size_type size_type
Definition HGTD_ID.h:52
size_type wafer_hash_max() const
Definition HGTD_ID.cxx:664
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:339
int init_neighbors()
Definition HGTD_ID.cxx:387
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:406
int phi_index(const Identifier &id) const
Definition HGTD_ID.h:498
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
Definition HGTD_ID.cxx:202
~HGTD_ID()
Definition HGTD_ID.cxx:37
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:460
size_type m_LAYER_INDEX
Definition HGTD_ID.h:247
const_id_iterator wafer_end() const
Definition HGTD_ID.cxx:680
static constexpr std::array< std::string_view, nImplementations > m_implNames
Definition HGTD_ID.h:269
std::vector< unsigned short > hash_vec
Definition HGTD_ID.h:223
int eta_index_max(const Identifier &id) const
Definition HGTD_ID.cxx:177
IdContext wafer_context() const
Definition HGTD_ID.h:452
int phi_index_max(const Identifier &id) const
Definition HGTD_ID.cxx:158
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:120
const_id_iterator wafer_begin() const
Iterators over full set of ids. Wafer iterator is sorted.
Definition HGTD_ID.cxx:675
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:670
int layer_max(const Identifier &id) const
Max/Min values for each field (error returns -999)
Definition HGTD_ID.cxx:82
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:363
const_expanded_id_iterator pixel_end() const
Definition HGTD_ID.cxx:690
size_type m_INDET_INDEX
Definition HGTD_ID.h:244
int layer(const Identifier &id) const
Definition HGTD_ID.h:477
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:430
void test_wafer_packing() const
Tests of packing.
Definition HGTD_ID.cxx:776
bool get_useNewIdentifierScheme() const
Definition HGTD_ID.cxx:518
int endcap(const Identifier &id) const
Values of different levels (failure returns 0)
Definition HGTD_ID.h:470
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:696
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:685
std::vector< Identifier >::const_iterator const_id_iterator
Definition HGTD_ID.h:53
MultiRange m_full_pixel_range
Definition HGTD_ID.h:255
bool m_useNewIdentifierScheme
Definition HGTD_ID.h:205
std::string m_padInModuleRow
Definition HGTD_ID.h:212
int base_bit() const
Return the lowest bit position used in the channel id.
Definition HGTD_ID.h:439
hash_vec m_prev_phi_wafer_vec
Definition HGTD_ID.h:261
std::string m_moduleInRow
Definition HGTD_ID.h:211
int eta_module_min(const Identifier &id) const
Definition HGTD_ID.cxx:139
bool is_phi_module_max(const Identifier &id) const
To check for when phi wrap around may be needed.
Definition HGTD_ID.cxx:196
std::string m_endcap_ID
Definition HGTD_ID.h:208
Implementations
Definition HGTD_ID.h:266
@ kEtaIndex
Definition HGTD_ID.h:267
@ nImplementations
Definition HGTD_ID.h:268
@ kPhiMod
Definition HGTD_ID.h:267
@ kEtaMod
Definition HGTD_ID.h:267
@ kHgtd
Definition HGTD_ID.h:266
@ kIndet
Definition HGTD_ID.h:266
@ kLayer
Definition HGTD_ID.h:266
@ kPhiIndex
Definition HGTD_ID.h:267
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:742
HGTD_ID()
Definition HGTD_ID.cxx:19
int phi_module(const Identifier &id) const
Definition HGTD_ID.h:484
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.
A MultiRange combines several Ranges.
Definition MultiRange.h:17
std::string base
Definition hcg.cxx:81