ATLAS Offline Software
Loading...
Searching...
No Matches
PixelID.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5#ifndef INDETIDENTIFIER_PIXELID_H
6#define INDETIDENTIFIER_PIXELID_H
18
20#include "Identifier/Identifier.h"
24#include "Identifier/IdHelper.h"
27
28#include <string>
29#include <cassert>
30#include <algorithm>
31#include <string_view>
32#include <array>
33
34
36
67
69{
70public:
72
73 typedef Identifier::size_type size_type;
74 typedef std::vector<Identifier>::const_iterator const_id_iterator;
77
78 PixelID();
79
84
86
87
89 int layer_disk,
90 int phi_module,
91 int eta_module) const;
93 int layer_disk,
94 int phi_module,
95 int eta_module,
96 bool checks) const;
97
101
104
107 int layer_disk,
108 int phi_module,
109 int eta_module,
110 int phi_index,
111 int eta_index) const;
113 int layer_disk,
114 int phi_module,
115 int eta_module,
116 int phi_index,
117 int eta_index,
118 bool checks) const;
120 int phi_index,
121 int eta_index) const;
123
125
129
131
132
140
141
143
144
146
148 bool is_barrel(const Identifier& id) const;
149
151 bool is_dbm(const Identifier& id) const; //DBM
152
154 bool is_blayer(const Identifier& id) const;
155
157 int barrel_ec(const Identifier& id) const;
158 int layer_disk(const Identifier& id) const;
159 int phi_module(const Identifier& id) const;
160 int eta_module(const Identifier& id) const;
161 int phi_index(const Identifier& id) const;
162 int eta_index(const Identifier& id) const;
163
165 int layer_disk_max(const Identifier& id) const;
166 int phi_module_max(const Identifier& id) const;
167 int eta_module_max(const Identifier& id) const;
168 int eta_module_min(const Identifier& id) const;
169 int phi_index_max(const Identifier& id) const;
170 int eta_index_max(const Identifier& id) const;
172
174
175
176 int get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const;
178 int get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const;
180 int get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const;
182 int get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const;
183
185 bool is_phi_module_max(const Identifier& id) const;
187 bool is_eta_module_min(const Identifier& id) const;
189 bool is_eta_module_max(const Identifier& id) const;
191
192
194
195 IdContext wafer_context() const;
196 IdContext pixel_context() const;
198
200
201
202 virtual int get_id(const IdentifierHash& hash_id,
203 Identifier& id,
204 const IdContext* context = 0) const override final;
205
207 virtual int get_hash(const Identifier& id,
208 IdentifierHash& hash_id,
209 const IdContext* context = 0) const override final;
211
215
220
225
227 int base_bit() const;
228
231 const Identifier& target) const;
232
235 Identifier::diff_type offset) const;
236
238
239
243
246 ExpandedIdentifier& exp_id,
247 const IdContext* context = 0) const;
248
250 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr) override;
251
255
257 enum {
259 MAX_BIT = Identifier::MAX_BIT,
260 BITS32 = Identifier::ALL_BITS
261 };
262
263 typedef std::vector<Identifier> id_vec;
264 typedef id_vec::const_iterator id_vec_it;
265 typedef std::vector<unsigned short> hash_vec;
266 typedef hash_vec::const_iterator hash_vec_it;
267
268 void wafer_id_checks(int barrel_ec,
269 int layer_disk,
270 int phi_module,
271 int eta_module) const;
272 void pixel_id_checks(int barrel_ec,
273 int layer_disk,
274 int phi_module,
275 int eta_module,
276 int phi_index,
277 int eta_index) const;
278
279 int initLevelsFromDict();
280
281 int init_hashes();
282
283 int init_neighbors();
284
287
310
311
315 static constexpr std::array<std::string_view, nImplementations> m_implNames{
316 "indet", "pixel", "bec", "bec_shift", "lay_disk", "lay_disk_shift",
317 "phi_mod", "phi_mod_shift", "eta_mod", "eta_mod_shift", "phi_index",
318 "eta_index", "bec_eta_mod"
319 };
320 std::array<IdDictFieldImplementation, nImplementations> m_impl;
322};
323
324
325
326//using the macros below we can assign an identifier (and a version)
327//This is required and checked at compile time when you try to record/retrieve
328CLASS_DEF(PixelID, 2516, 1)
329
330//----------------------------------------------------------------------------
331inline Identifier
333 int layer_disk,
334 int phi_module,
335 int eta_module,
336 bool checks) const {
337 // Build identifier
339
340 // Pack fields independently
341 m_impl[kBec].pack(barrel_ec, result);
345
346 // Do checks
347 if (checks) {
349 }
350
351 return result;
352}
353
354inline Identifier
361
362//----------------------------------------------------------------------------
363inline Identifier
366
367 m_impl[kPhiIndex].reset(result);
368 m_impl[kEtaIndex].reset(result);
369 return(result);
370}
371
372//----------------------------------------------------------------------------
376
377//----------------------------------------------------------------------------
379 id_vec_it it = std::lower_bound(m_wafer_vec.begin(),
380 m_wafer_vec.end(),
381 wafer_id);
382
383 // Require that wafer_id matches the one in vector
384 if (it != m_wafer_vec.end() && wafer_id == (*it)) {
385 return(it - m_wafer_vec.begin());
386 }
388 return(result); // return hash in invalid state
389}
390
391//----------------------------------------------------------------------------
392inline Identifier
394 int layer_disk,
395 int phi_module,
396 int eta_module,
397 int phi_index,
398 int eta_index,
399 bool checks) const {
400 // Build identifier
402
403 m_impl[kBec].pack(barrel_ec, result);
409
410 if (checks) {
415 phi_index,
416 eta_index);
417 }
418
419 return result;
420}
421
422inline Identifier
424 int layer_disk,
425 int phi_module,
426 int eta_module,
427 int phi_index,
428 int eta_index) const {
431}
432
435//----------------------------------------------------------------------------
436inline Identifier
438 bool checks) const {
440
447
448 if (checks) {
455 }
456
457 return(result);
458}
459
460inline Identifier
462 return pixel_id(id, do_checks());
463}
464
465//----------------------------------------------------------------------------
466inline Identifier
468 int phi_index,
469 int eta_index) const {
471
472 m_impl[kPhiIndex].reset(result);
473 m_impl[kEtaIndex].reset(result);
476 return(result);
477}
478
479//----------------------------------------------------------------------------
480inline Identifier
481PixelID::pixel_id(Identifier::value_type val) const {
482 // a pixel channel id has bit 31 set, and low 8 bits > 0.
483 // This could also have been shifted up by 32 bits.
484
485 // first test to see if this is a 32-bit value promoted to 64-bit
486 // (low word != 0, high word == 0).
487 if ((val << 32) && !(val >> 32)) {
488 // test to see if this is a genuine 64-bit pixel channel id;
489 // these would not have the low 8-bits nonzero.
490 // (This will break if pixel channel id's fill more than 56 bits!)
491 Identifier32::value_type valshort = static_cast<Identifier32::value_type>(val);
492 if (is_shortened_pixel_id(valshort)) {
493 return pixel_id_from_shortened(valshort);
494 }
495 } else if (!(val << 32) && (val >> 32)) {
496 // low word 0, high word != 0
497 Identifier32::value_type valshort = static_cast<Identifier32::value_type>(val >> 32);
498 if (is_shortened_pixel_id(valshort)) {
499 return pixel_id_from_shortened(valshort);
500 }
501 }
502 return Identifier(val); // genuine 64-bit pixel channel id
503}
504
505//----------------------------------------------------------------------------
506inline bool
508 return (val >> 31) && (val & 0xff);
509}
510
511//----------------------------------------------------------------------------
512inline bool
514 return is_shortened_pixel_id(id.get_compact());
515}
516
517//----------------------------------------------------------------------------
518inline bool
520 Identifier::value_type val = id.get_compact();
522 // first test if value is contained in one half or the other
523 if ((val << 32) && !(val >> 32)) {
524 // low word contains value, high word empty
525 valshort = static_cast<Identifier32::value_type>(val);
526 } else if (!(val << 32) && (val >> 32)) {
527 // high word contains value, low word empty
528 valshort = static_cast<Identifier32::value_type>(val >> 32);
529 } else {
530 return false;
531 }
532 return is_shortened_pixel_id(valshort);
533}
534
535//----------------------------------------------------------------------------
536inline Identifier
538 int bec_val[4] = {
539 -2, 0, 2, -999
540 }; // CHECK decodings
541 int bec = bec_val[(val >> 29) & 0x03];
542
543 if (bec < -2) return Identifier();
544
545 return pixel_id(bec,
546 /* lay_disk */ ((val >> 27) & 0x03),
547 /* phi_mod */ ((val >> 21) & 0x3f),
548 /* eta_mod */ (((val >> 17) & 0x0f) + m_ETA_MODULE_OFFSET),
549 /* phi_index */ ((val >> 8) & 0x1ff),
550 /* eta_index */ ((val) & 0xff) - 1);
551}
552
553//----------------------------------------------------------------------------
554inline Identifier::diff_type
555PixelID::calc_offset(const Identifier& base, const Identifier& target) const {
556 Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit());
557 Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit());
558 return(tval - bval);
559}
560
561//----------------------------------------------------------------------------
562inline Identifier
564 Identifier::diff_type offset) const {
565 Identifier::value_type bval = base.get_compact() >> base_bit();
566 return Identifier((bval + offset) << base_bit());
567}
568
569//----------------------------------------------------------------------------
570inline int
572 int base = static_cast<int>(m_impl[kEtaIndex].shift()); // lowest field base
573
574 return (base > 32) ? 32 : base;
575 // max base is 32 so we can still read old strip id's and differences
576 // from non-SLHC releases.
577}
578
579//----------------------------------------------------------------------------
580inline bool
582 // Normal unshifted id
583 return(m_barrel_field.match(m_impl[kBec].unpack(id)));
584}
585
586//----------------------------------------------------------------------------
587inline bool
588PixelID::is_dbm(const Identifier& id) const {
589 // Normal unshifted id
590 return(m_dbm_field.match(m_impl[kBec].unpack(id)));
591}
592
593//----------------------------------------------------------------------------
594inline int
596 // Normal unshifted id
597 return(m_impl[kBec].unpack(id));
598}
599
600//----------------------------------------------------------------------------
601inline int
603 // Normal unshifted id
604 return(m_impl[kLayDisk].unpack(id));
605}
606
607//----------------------------------------------------------------------------
608inline bool
610 // Check if it is pixel id
611 if (is_barrel(id)) {
612 return(0 == layer_disk(id));
613 } else {
614 return(false);
615 }
616}
617
618//----------------------------------------------------------------------------
619inline int
621 // Normal unshifted id
622 return(m_impl[kPhiMod].unpack(id));
623}
624
625//----------------------------------------------------------------------------
626inline int
628 // Normal unshifted id
629 return(m_impl[kEtaMod].unpack(id));
630}
631
632//----------------------------------------------------------------------------
633inline int
635 return(m_impl[kPhiIndex].unpack(id));
636}
637
638//----------------------------------------------------------------------------
639inline int
641 return(m_impl[kEtaIndex].unpack(id));
642}
643
644#endif // INDETIDENTIFIER_PIXELID_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
#define protected
HelperType
enum class for eventual final derived types of this class
virtual bool do_checks(void) const override
Checks are performed by default in debug compilation and NOT in optimized compilation.
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
unsigned int value_type
This is a "hash" representation of an Identifier.
A MultiRange combines several Ranges.
Definition MultiRange.h:17
This is an Identifier helper class for the Pixel subdetector.
Definition PixelID.h:69
bool is_phi_module_max(const Identifier &id) const
To check for when phi wrap around may be needed.
Definition PixelID.cxx:182
bool is_dbm(const Identifier &id) const
Test for dbm - WARNING: id MUST be pixel id, otherwise answer is not accurate. Use SiliconID for gene...
Definition PixelID.h:588
const_id_iterator wafer_begin() const
Iterators over full set of ids. Wafer iterator is sorted.
Definition PixelID.cxx:713
int eta_index(const Identifier &id) const
Definition PixelID.h:640
Implementations
Definition PixelID.h:312
@ kIndet
Definition PixelID.h:312
@ kLayDiskShift
Definition PixelID.h:312
@ kBecShift
Definition PixelID.h:312
@ nImplementations
Definition PixelID.h:314
@ kPhiMod
Definition PixelID.h:313
@ kEtaIndex
Definition PixelID.h:313
@ kPixel
Definition PixelID.h:312
@ kEtaMod
Definition PixelID.h:313
@ kBecEtaMod
Definition PixelID.h:313
@ kLayDisk
Definition PixelID.h:312
@ kEtaModShift
Definition PixelID.h:313
@ kPhiModShift
Definition PixelID.h:313
@ kPhiIndex
Definition PixelID.h:313
int layer_disk(const Identifier &id) const
Definition PixelID.h:602
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition PixelID.cxx:187
int eta_module_max(const Identifier &id) const
Definition PixelID.cxx:81
id_vec m_wafer_vec
Definition PixelID.h:305
size_type m_ETA_MODULE_INDEX
Definition PixelID.h:294
Identifier m_pixel_id
Definition PixelID.h:298
Range::field m_dbm_field
Definition PixelID.h:321
MultiRange m_full_wafer_range
Definition PixelID.h:300
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition PixelID.h:355
PixelID()
Definition PixelID.cxx:26
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition PixelID.h:595
size_type m_LAYER_DISK_INDEX
Definition PixelID.h:292
std::vector< Identifier > id_vec
Definition PixelID.h:263
const_expanded_id_iterator pixel_end() const
Definition PixelID.cxx:725
const IdDictDictionary * m_dict
Definition PixelID.h:299
bool is_shortened_pixel_id(Identifier32::value_type val) const
Test if this is a valid shortened pixel channel id.
Definition PixelID.h:507
bool is_eta_module_max(const Identifier &id) const
For the barrel.
Definition PixelID.cxx:121
static constexpr std::array< std::string_view, nImplementations > m_implNames
Definition PixelID.h:315
void pixel_id_checks(int barrel_ec, int layer_disk, int phi_module, int eta_module, int phi_index, int eta_index) const
Definition PixelID.cxx:48
Identifier pixel_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int phi_index, int eta_index) const
For an individual pixel.
Definition PixelID.h:423
hash_vec m_prev_phi_wafer_vec
Definition PixelID.h:306
int base_bit() const
Return the lowest bit position used in the channel id.
Definition PixelID.h:571
size_type m_pixel_region_index
Definition PixelID.h:288
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition PixelID.h:378
size_type wafer_hash_max() const
Definition PixelID.cxx:704
int init_neighbors()
Definition PixelID.cxx:440
int eta_module(const Identifier &id) const
Definition PixelID.h:627
size_type m_BARREL_EC_INDEX
Definition PixelID.h:291
int phi_index(const Identifier &id) const
Definition PixelID.h:634
hash_vec::const_iterator hash_vec_it
Definition PixelID.h:266
const_id_iterator wafer_end() const
Definition PixelID.cxx:717
int init_hashes()
Definition PixelID.cxx:333
ExpandedIdentifier m_baseExpandedIdentifier
Definition PixelID.h:286
hash_vec m_next_phi_wafer_vec
Definition PixelID.h:307
Identifier::diff_type calc_offset(const Identifier &base, const Identifier &target) const
Calculate a channel offset between the two identifiers.
Definition PixelID.h:555
int eta_index_max(const Identifier &id) const
Definition PixelID.cxx:164
Identifier::size_type size_type
Definition PixelID.h:73
std::vector< unsigned short > hash_vec
Definition PixelID.h:265
Identifier pixel_id_offset(const Identifier &base, Identifier::diff_type offset) const
Create an identifier with a given base and channel offset.
Definition PixelID.h:563
int layer_disk_max(const Identifier &id) const
Max/Min values for each field (error returns -999)
Definition PixelID.cxx:63
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 PixelID.cxx:730
size_type m_pixel_hash_max
Definition PixelID.h:303
Range::field m_barrel_field
Definition PixelID.h:304
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in eta (return == 0 for neighbor found)
Definition PixelID.cxx:428
@ NOT_VALID_HASH
Definition PixelID.h:258
@ BITS32
Definition PixelID.h:260
@ MAX_BIT
Definition PixelID.h:259
int initLevelsFromDict()
Definition PixelID.cxx:571
size_type m_PHI_INDEX_INDEX
Definition PixelID.h:295
MultiRange::const_identifier_factory const_expanded_id_iterator
Definition PixelID.h:75
std::array< IdDictFieldImplementation, nImplementations > m_impl
Definition PixelID.h:320
bool is_blayer(const Identifier &id) const
Test for b-layer - WARNING: id MUST be pixel id, otherwise answer is not accurate....
Definition PixelID.h:609
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const override final
Create hash id from compact id (return == 0 for OK)
Definition PixelID.cxx:772
IdContext pixel_context() const
Definition PixelID.cxx:891
int phi_index_max(const Identifier &id) const
Definition PixelID.cxx:145
size_type m_PIXEL_INDEX
Definition PixelID.h:290
Identifier pixel_id_from_shortened(Identifier32::value_type val) const
Create a compact pixel id from a (fixed format) legacy pixel channel id.
Definition PixelID.h:537
size_type m_INDET_INDEX
Definition PixelID.h:289
const_expanded_id_iterator pixel_begin() const
For pixel ids, only expanded id iterators are available.
Definition PixelID.cxx:721
size_type m_PHI_MODULE_INDEX
Definition PixelID.h:293
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in eta (return == 0 for neighbor found)
Definition PixelID.cxx:415
id_vec::const_iterator id_vec_it
Definition PixelID.h:264
void wafer_id_checks(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
Definition PixelID.cxx:34
size_type m_wafer_hash_max
Definition PixelID.h:302
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in phi (return == 0 for neighbor found)
Definition PixelID.cxx:389
Identifier m_baseIdentifier
Definition PixelID.h:285
IdContext wafer_context() const
Definition PixelID.cxx:883
std::vector< Identifier >::const_iterator const_id_iterator
Definition PixelID.h:74
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in phi (return == 0 for neighbor found)
Definition PixelID.cxx:402
hash_vec m_prev_eta_wafer_vec
Definition PixelID.h:308
void test_wafer_packing() const
Tests of packing.
Definition PixelID.cxx:802
size_type m_ETA_INDEX_INDEX
Definition PixelID.h:296
int eta_module_min(const Identifier &id) const
Definition PixelID.cxx:98
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override final
Create compact id from hash id (return == 0 for OK)
Definition PixelID.cxx:747
int m_ETA_MODULE_OFFSET
Definition PixelID.h:297
hash_vec m_next_eta_wafer_vec
Definition PixelID.h:309
int phi_module(const Identifier &id) const
Definition PixelID.h:620
bool is_barrel(const Identifier &id) const
Test for barrel - WARNING: id MUST be pixel id, otherwise answer is not accurate. Use SiliconID for g...
Definition PixelID.h:581
bool is_eta_module_min(const Identifier &id) const
For the barrel.
Definition PixelID.cxx:116
MultiRange m_full_pixel_range
Definition PixelID.h:301
virtual AtlasDetectorID::HelperType helper() const override
This is a PixelID helper.
Definition PixelID.h:81
size_type pixel_hash_max() const
Definition PixelID.cxx:709
int phi_module_max(const Identifier &id) const
Definition PixelID.cxx:125
std::string base
Definition hcg.cxx:81