ATLAS Offline Software
Loading...
Searching...
No Matches
PixelID.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 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
32
34
65
67{
68public:
70
71 typedef Identifier::size_type size_type;
72 typedef std::vector<Identifier>::const_iterator const_id_iterator;
75
77
78 PixelID();
80
85
87
88
90 int layer_disk,
91 int phi_module,
92 int eta_module) const;
94 int layer_disk,
95 int phi_module,
96 int eta_module,
97 bool checks) const;
98
102
105
108 int layer_disk,
109 int phi_module,
110 int eta_module,
111 int phi_index,
112 int eta_index) const;
114 int layer_disk,
115 int phi_module,
116 int eta_module,
117 int phi_index,
118 int eta_index,
119 bool checks) const;
121 int phi_index,
122 int eta_index) const;
124
126
130
132
133
141
142
144
145
147
149 bool is_barrel(const Identifier& id) const;
150
152 bool is_dbm(const Identifier& id) const; //DBM
153
155 bool is_blayer(const Identifier& id) const;
156
158 int barrel_ec(const Identifier& id) const;
159 int layer_disk(const Identifier& id) const;
160 int phi_module(const Identifier& id) const;
161 int eta_module(const Identifier& id) const;
162 int phi_index(const Identifier& id) const;
163 int eta_index(const Identifier& id) const;
164
166 int layer_disk_max(const Identifier& id) const;
167 int phi_module_max(const Identifier& id) const;
168 int eta_module_max(const Identifier& id) const;
169 int eta_module_min(const Identifier& id) const;
170 int phi_index_max(const Identifier& id) const;
171 int eta_index_max(const Identifier& id) const;
173
175
176
177 int get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const;
179 int get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const;
181 int get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const;
183 int get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const;
184
186 bool is_phi_module_max(const Identifier& id) const;
188 bool is_eta_module_min(const Identifier& id) const;
190 bool is_eta_module_max(const Identifier& id) const;
192
193
195
196 IdContext wafer_context() const;
197 IdContext pixel_context() const;
199
201
202
203 virtual int get_id(const IdentifierHash& hash_id,
204 Identifier& id,
205 const IdContext* context = 0) const override final;
206
208 virtual int get_hash(const Identifier& id,
209 IdentifierHash& hash_id,
210 const IdContext* context = 0) const override final;
212
216
221
226
228 int base_bit() const;
229
232 const Identifier& target) const;
233
236 Identifier::diff_type offset) const;
237
239
240
244
247 ExpandedIdentifier& exp_id,
248 const IdContext* context = 0) const;
249
251 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr) override;
252
256
258 enum {
260 MAX_BIT = Identifier::MAX_BIT,
261 BITS32 = Identifier::ALL_BITS
262 };
263
264 typedef std::vector<Identifier> id_vec;
265 typedef id_vec::const_iterator id_vec_it;
266 typedef std::vector<unsigned short> hash_vec;
267 typedef hash_vec::const_iterator hash_vec_it;
268
269 void wafer_id_checks(int barrel_ec,
270 int layer_disk,
271 int phi_module,
272 int eta_module) const;
273 void pixel_id_checks(int barrel_ec,
274 int layer_disk,
275 int phi_module,
276 int eta_module,
277 int phi_index,
278 int eta_index) const;
279
280 int initLevelsFromDict();
281
282 int init_hashes();
283
284 int init_neighbors();
285
288
311
325
327};
328
329
330
331//using the macros below we can assign an identifier (and a version)
332//This is required and checked at compile time when you try to record/retrieve
333CLASS_DEF(PixelID, 2516, 1)
334
335//----------------------------------------------------------------------------
336inline Identifier
338 int layer_disk,
339 int phi_module,
340 int eta_module,
341 bool checks) const {
342 // Build identifier
344
345 // Pack fields independently
350
351 // Do checks
352 if (checks) {
354 }
355
356 return result;
357}
358
359inline Identifier
366
367//----------------------------------------------------------------------------
368inline Identifier
371
374 return(result);
375}
376
377//----------------------------------------------------------------------------
381
382//----------------------------------------------------------------------------
384 id_vec_it it = std::lower_bound(m_wafer_vec.begin(),
385 m_wafer_vec.end(),
386 wafer_id);
387
388 // Require that wafer_id matches the one in vector
389 if (it != m_wafer_vec.end() && wafer_id == (*it)) {
390 return(it - m_wafer_vec.begin());
391 }
393 return(result); // return hash in invalid state
394}
395
396//----------------------------------------------------------------------------
397inline Identifier
399 int layer_disk,
400 int phi_module,
401 int eta_module,
402 int phi_index,
403 int eta_index,
404 bool checks) const {
405 // Build identifier
407
414
415 if (checks) {
420 phi_index,
421 eta_index);
422 }
423
424 return result;
425}
426
427inline Identifier
429 int layer_disk,
430 int phi_module,
431 int eta_module,
432 int phi_index,
433 int eta_index) const {
436}
437
440//----------------------------------------------------------------------------
441inline Identifier
443 bool checks) const {
445
452
453 if (checks) {
460 }
461
462 return(result);
463}
464
465inline Identifier
467 return pixel_id(id, do_checks());
468}
469
470//----------------------------------------------------------------------------
471inline Identifier
473 int phi_index,
474 int eta_index) const {
476
481 return(result);
482}
483
484//----------------------------------------------------------------------------
485inline Identifier
486PixelID::pixel_id(Identifier::value_type val) const {
487 // a pixel channel id has bit 31 set, and low 8 bits > 0.
488 // This could also have been shifted up by 32 bits.
489
490 // first test to see if this is a 32-bit value promoted to 64-bit
491 // (low word != 0, high word == 0).
492 if ((val << 32) && !(val >> 32)) {
493 // test to see if this is a genuine 64-bit pixel channel id;
494 // these would not have the low 8-bits nonzero.
495 // (This will break if pixel channel id's fill more than 56 bits!)
496 Identifier32::value_type valshort = static_cast<Identifier32::value_type>(val);
497 if (is_shortened_pixel_id(valshort)) {
498 return pixel_id_from_shortened(valshort);
499 }
500 } else if (!(val << 32) && (val >> 32)) {
501 // low word 0, high word != 0
502 Identifier32::value_type valshort = static_cast<Identifier32::value_type>(val >> 32);
503 if (is_shortened_pixel_id(valshort)) {
504 return pixel_id_from_shortened(valshort);
505 }
506 }
507 return Identifier(val); // genuine 64-bit pixel channel id
508}
509
510//----------------------------------------------------------------------------
511inline bool
513 return (val >> 31) && (val & 0xff);
514}
515
516//----------------------------------------------------------------------------
517inline bool
519 return is_shortened_pixel_id(id.get_compact());
520}
521
522//----------------------------------------------------------------------------
523inline bool
525 Identifier::value_type val = id.get_compact();
527 // first test if value is contained in one half or the other
528 if ((val << 32) && !(val >> 32)) {
529 // low word contains value, high word empty
530 valshort = static_cast<Identifier32::value_type>(val);
531 } else if (!(val << 32) && (val >> 32)) {
532 // high word contains value, low word empty
533 valshort = static_cast<Identifier32::value_type>(val >> 32);
534 } else {
535 return false;
536 }
537 return is_shortened_pixel_id(valshort);
538}
539
540//----------------------------------------------------------------------------
541inline Identifier
543 int bec_val[4] = {
544 -2, 0, 2, -999
545 }; // CHECK decodings
546 int bec = bec_val[(val >> 29) & 0x03];
547
548 if (bec < -2) return Identifier();
549
550 return pixel_id(bec,
551 /* lay_disk */ ((val >> 27) & 0x03),
552 /* phi_mod */ ((val >> 21) & 0x3f),
553 /* eta_mod */ (((val >> 17) & 0x0f) + m_ETA_MODULE_OFFSET),
554 /* phi_index */ ((val >> 8) & 0x1ff),
555 /* eta_index */ ((val) & 0xff) - 1);
556}
557
558//----------------------------------------------------------------------------
559inline Identifier::diff_type
560PixelID::calc_offset(const Identifier& base, const Identifier& target) const {
561 Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit());
562 Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit());
563 return(tval - bval);
564}
565
566//----------------------------------------------------------------------------
567inline Identifier
569 Identifier::diff_type offset) const {
570 Identifier::value_type bval = base.get_compact() >> base_bit();
571 return Identifier((bval + offset) << base_bit());
572}
573
574//----------------------------------------------------------------------------
575inline int
577 int base = static_cast<int>(m_eta_index_impl.shift()); // lowest field base
578
579 return (base > 32) ? 32 : base;
580 // max base is 32 so we can still read old strip id's and differences
581 // from non-SLHC releases.
582}
583
584//----------------------------------------------------------------------------
585inline bool
587 // Normal unshifted id
588 return(m_barrel_field.match(m_bec_impl.unpack(id)));
589}
590
591//----------------------------------------------------------------------------
592inline bool
593PixelID::is_dbm(const Identifier& id) const {
594 // Normal unshifted id
595 return(m_dbm_field.match(m_bec_impl.unpack(id)));
596}
597
598//----------------------------------------------------------------------------
599inline int
601 // Normal unshifted id
602 return(m_bec_impl.unpack(id));
603}
604
605//----------------------------------------------------------------------------
606inline int
608 // Normal unshifted id
609 return(m_lay_disk_impl.unpack(id));
610}
611
612//----------------------------------------------------------------------------
613inline bool
615 // Check if it is pixel id
616 if (is_barrel(id)) {
617 return(0 == layer_disk(id));
618 } else {
619 return(false);
620 }
621}
622
623//----------------------------------------------------------------------------
624inline int
626 // Normal unshifted id
627 return(m_phi_mod_impl.unpack(id));
628}
629
630//----------------------------------------------------------------------------
631inline int
633 // Normal unshifted id
634 return(m_eta_mod_impl.unpack(id));
635}
636
637//----------------------------------------------------------------------------
638inline int
640 return(m_phi_index_impl.unpack(id));
641}
642
643//----------------------------------------------------------------------------
644inline int
646 return(m_eta_index_impl.unpack(id));
647}
648
649#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
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
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:67
bool is_phi_module_max(const Identifier &id) const
To check for when phi wrap around may be needed.
Definition PixelID.cxx:180
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:593
const_id_iterator wafer_begin() const
Iterators over full set of ids. Wafer iterator is sorted.
Definition PixelID.cxx:810
int eta_index(const Identifier &id) const
Definition PixelID.h:645
int layer_disk(const Identifier &id) const
Definition PixelID.h:607
IdDictFieldImplementation m_bec_eta_mod_impl
Definition PixelID.h:324
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition PixelID.cxx:185
int eta_module_max(const Identifier &id) const
Definition PixelID.cxx:79
id_vec m_wafer_vec
Definition PixelID.h:306
size_type m_ETA_MODULE_INDEX
Definition PixelID.h:295
Identifier m_pixel_id
Definition PixelID.h:299
IdDictFieldImplementation m_lay_disk_shift_impl
Definition PixelID.h:319
Range::field m_dbm_field
Definition PixelID.h:326
IdDictFieldImplementation m_eta_mod_impl
Definition PixelID.h:317
MultiRange m_full_wafer_range
Definition PixelID.h:301
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition PixelID.h:360
PixelID()
Definition PixelID.cxx:24
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition PixelID.h:600
size_type m_LAYER_DISK_INDEX
Definition PixelID.h:293
std::vector< Identifier > id_vec
Definition PixelID.h:264
IdDictFieldImplementation m_lay_disk_impl
Definition PixelID.h:315
const_expanded_id_iterator pixel_end() const
Definition PixelID.cxx:822
const IdDictDictionary * m_dict
Definition PixelID.h:300
bool is_shortened_pixel_id(Identifier32::value_type val) const
Test if this is a valid shortened pixel channel id.
Definition PixelID.h:512
bool is_eta_module_max(const Identifier &id) const
For the barrel.
Definition PixelID.cxx:119
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:46
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:428
hash_vec m_prev_phi_wafer_vec
Definition PixelID.h:307
int base_bit() const
Return the lowest bit position used in the channel id.
Definition PixelID.h:576
size_type m_pixel_region_index
Definition PixelID.h:289
IdDictFieldImplementation m_phi_mod_shift_impl
Definition PixelID.h:320
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition PixelID.h:383
size_type wafer_hash_max() const
Definition PixelID.cxx:801
int init_neighbors()
Definition PixelID.cxx:438
int eta_module(const Identifier &id) const
Definition PixelID.h:632
size_type m_BARREL_EC_INDEX
Definition PixelID.h:292
int phi_index(const Identifier &id) const
Definition PixelID.h:639
hash_vec::const_iterator hash_vec_it
Definition PixelID.h:267
IdDictFieldImplementation m_phi_mod_impl
Definition PixelID.h:316
const_id_iterator wafer_end() const
Definition PixelID.cxx:814
IdDictFieldImplementation m_phi_index_impl
Definition PixelID.h:322
int init_hashes()
Definition PixelID.cxx:331
ExpandedIdentifier m_baseExpandedIdentifier
Definition PixelID.h:287
hash_vec m_next_phi_wafer_vec
Definition PixelID.h:308
Identifier::diff_type calc_offset(const Identifier &base, const Identifier &target) const
Calculate a channel offset between the two identifiers.
Definition PixelID.h:560
int eta_index_max(const Identifier &id) const
Definition PixelID.cxx:162
Identifier::size_type size_type
Definition PixelID.h:71
std::vector< unsigned short > hash_vec
Definition PixelID.h:266
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:568
int layer_disk_max(const Identifier &id) const
Max/Min values for each field (error returns -999)
Definition PixelID.cxx:61
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:827
size_type m_pixel_hash_max
Definition PixelID.h:304
Range::field m_barrel_field
Definition PixelID.h:305
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in eta (return == 0 for neighbor found)
Definition PixelID.cxx:426
@ NOT_VALID_HASH
Definition PixelID.h:259
@ BITS32
Definition PixelID.h:261
@ MAX_BIT
Definition PixelID.h:260
int initLevelsFromDict()
Definition PixelID.cxx:569
size_type m_PHI_INDEX_INDEX
Definition PixelID.h:296
MultiRange::const_identifier_factory const_expanded_id_iterator
Definition PixelID.h:73
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:614
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:869
IdContext pixel_context() const
Definition PixelID.cxx:988
int phi_index_max(const Identifier &id) const
Definition PixelID.cxx:143
size_type m_PIXEL_INDEX
Definition PixelID.h:291
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:542
size_type m_INDET_INDEX
Definition PixelID.h:290
const_expanded_id_iterator pixel_begin() const
For pixel ids, only expanded id iterators are available.
Definition PixelID.cxx:818
size_type m_PHI_MODULE_INDEX
Definition PixelID.h:294
IdDictFieldImplementation m_eta_mod_shift_impl
Definition PixelID.h:321
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in eta (return == 0 for neighbor found)
Definition PixelID.cxx:413
id_vec::const_iterator id_vec_it
Definition PixelID.h:265
void wafer_id_checks(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
Definition PixelID.cxx:32
size_type m_wafer_hash_max
Definition PixelID.h:303
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in phi (return == 0 for neighbor found)
Definition PixelID.cxx:387
Identifier m_baseIdentifier
Definition PixelID.h:286
IdContext wafer_context() const
Definition PixelID.cxx:980
std::vector< Identifier >::const_iterator const_id_iterator
Definition PixelID.h:72
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in phi (return == 0 for neighbor found)
Definition PixelID.cxx:400
IdDictFieldImplementation m_bec_impl
Definition PixelID.h:314
hash_vec m_prev_eta_wafer_vec
Definition PixelID.h:309
void test_wafer_packing() const
Tests of packing.
Definition PixelID.cxx:899
size_type m_ETA_INDEX_INDEX
Definition PixelID.h:297
IdDictFieldImplementation m_pixel_impl
Definition PixelID.h:313
int eta_module_min(const Identifier &id) const
Definition PixelID.cxx:96
IdDictFieldImplementation m_indet_impl
Definition PixelID.h:312
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:844
IdDictFieldImplementation m_eta_index_impl
Definition PixelID.h:323
IdDictFieldImplementation m_bec_shift_impl
Definition PixelID.h:318
int m_ETA_MODULE_OFFSET
Definition PixelID.h:298
hash_vec m_next_eta_wafer_vec
Definition PixelID.h:310
int phi_module(const Identifier &id) const
Definition PixelID.h:625
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:586
bool is_eta_module_min(const Identifier &id) const
For the barrel.
Definition PixelID.cxx:114
MultiRange m_full_pixel_range
Definition PixelID.h:302
virtual AtlasDetectorID::HelperType helper() const override
THis is a PixelID helper.
Definition PixelID.h:82
size_type pixel_hash_max() const
Definition PixelID.cxx:806
int phi_module_max(const Identifier &id) const
Definition PixelID.cxx:123
std::string base
Definition hcg.cxx:81