ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_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
5#ifndef INDETIDENTIFIER_SCT_ID_H
6#define INDETIDENTIFIER_SCT_ID_H
18
19
21#include "Identifier/Identifier.h"
24#include "Identifier/IdHelper.h"
27
28#include <string>
29#include <cassert>
30#include <algorithm>
31#include <array>
32#include <functional>
33
34
36
37
67class SCT_ID final: public AtlasDetectorID
68{
69public:
71
72 typedef Identifier::size_type size_type;
73 typedef std::vector<Identifier>::const_iterator const_id_iterator;
76
78
79 SCT_ID();
80 virtual ~SCT_ID() = default;
82
87
88
89
91 int layer_disk,
92 int phi_module,
93 int eta_module) const;
94
96 int layer_disk,
97 int phi_module,
98 int eta_module,
99 bool checks) const;
100
103
106 int layer_disk,
107 int phi_module,
108 int eta_module,
109 int side) const;
110
112 int layer_disk,
113 int phi_module,
114 int eta_module,
115 int side,
116 bool checks) const;
117
120
122 Identifier wafer_id(const ExpandedIdentifier & expId) const;
123
126
129 int layer_disk,
130 int phi_module,
131 int eta_module,
132 int side,
133 int strip) const;
135 int layer_disk,
136 int phi_module,
137 int eta_module,
138 int side,
139 int strip,
140 bool check) const;
141
143 int layer_disk,
144 int phi_module,
145 int eta_module,
146 int side,
147 int row,
148 int strip) const;
150 int layer_disk,
151 int phi_module,
152 int eta_module,
153 int side,
154 int row,
155 int strip,
156 bool checks) const;
157
158
159
161 int strip) const;
162
164 int row, int strip) const;
165
166
168
169
171
175
177
178
186
187
189
190
192
194 bool is_barrel(const Identifier& id) const;
195
197 int barrel_ec(const Identifier& id) const;
198 int layer_disk(const Identifier& id) const;
199 int phi_module(const Identifier& id) const;
200 int eta_module(const Identifier& id) const;
201 int side(const Identifier& id) const;
202 int row(const Identifier& id) const;
203 int strip(const Identifier& id) const;
204
206 int layer_disk_max(const Identifier& id) const;
207 int phi_module_max(const Identifier& id) const;
208 int eta_module_max(const Identifier& id) const;
209 int eta_module_min(const Identifier& id) const;
210 int strip_max(const Identifier& id) const;
212
214
215
216 int get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const;
218 int get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const;
220 int get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const;
222 int get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const;
224 int get_other_side(const IdentifierHash& id, IdentifierHash& other) const;
225
237
238 // To check for when phi wrap around may be needed, use
239 bool is_phi_module_max(const Identifier& id) const;
241 bool is_eta_module_min(const Identifier& id) const;
243 bool is_eta_module_max(const Identifier& id) const;
244
245 //all neighbours: opposite and then eta direction first
246 std::array<IdentifierHash, 5>
247 neighbours_by_eta(const IdentifierHash & idh) const;
248
249 //all neighbours: opposite and then phi direction first
250 std::array<IdentifierHash, 5>
251 neighbours_by_phi(const IdentifierHash & idh) const;
252
256 const std::array<std::function< IdentifierHash(const IdentifierHash &)>, 5 >&
259
261
262 IdContext wafer_context() const;
263 IdContext strip_context() const;
265
267
268
269 virtual int get_id(const IdentifierHash& hash_id,
270 Identifier& id,
271 const IdContext* context = 0) const override final;
272
274 virtual int get_hash(const Identifier& id,
275 IdentifierHash& hash_id,
276 const IdContext* context = 0) const override final;
278
280 int base_bit() const;
281
284 const Identifier& target) const;
285
288 Identifier::diff_type offset) const;
289
291
292
295
298 ExpandedIdentifier& exp_id,
299 const IdContext* context = 0) const;
300
302 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr) override final;
303
305private:
311 std::array<std::function< IdentifierHash(const IdentifierHash & )>, 5> m_neighboursByEta;
312
313 void wafer_id_checks(int barrel_ec,
314 int layer_disk,
315 int phi_module,
316 int eta_module,
317 int side) const;
318
319 void strip_id_checks(int barrel_ec,
320 int layer_disk,
321 int phi_module,
322 int eta_module,
323 int side,
324 int strip) const;
325
326 void strip_id_checks(int barrel_ec,
327 int layer_disk,
328 int phi_module,
329 int eta_module,
330 int side,
331 int row,
332 int strip) const;
333
334 int getMaxField(const Identifier & id, const ExpandedIdIndices &fieldIndx) const;
335
336 void strip_id_checks(const ExpandedIdentifier & expId) const;
337
338
339 int initLevelsFromDict();
340
341 int init_hashes();
342
343 int init_neighbors();
344
346 nextInSequence(const IdentifierHash& id, const hash_vec& vectorOfHashes) const;
347
348 // Temporary method for adapting an identifier for the MultiRange
349 // check - MR is missing the InnerDetector level
351
353
354 std::array<size_t, NUM_INDICES> m_indices{0,1,2,3,4,5,6,7,999};
367
377};
378
379
380//using the macros below we can assign an identifier (and a version)
381//This is required and checked at compile time when you try to record/retrieve
382CLASS_DEF(SCT_ID, 2517, 1)
383
384//----------------------------------------------------------------------------
385inline Identifier
387 int layer_disk,
388 int phi_module,
389 int eta_module,
390 bool checks) const {
391 // Build identifier
392 Identifier result((Identifier::value_type) 0);
393
394 // Pack fields independently
401
402 // Do checks
403 if (checks) {
405 }
406
407 return result;
408}
409
410inline Identifier
417
418//----------------------------------------------------------------------------
419inline Identifier
422
423 // Reset the side and strip fields
424 m_side_impl.reset(result);
425 m_strip_impl.reset(result);
426 if(m_hasRows) m_row_impl.reset(result);
427 return(result);
428}
429
430//----------------------------------------------------------------------------
431inline Identifier
433 int layer_disk,
434 int phi_module,
435 int eta_module,
436 int side,
437 bool checks) const {
438 // Build identifier
439 Identifier result((Identifier::value_type) 0);
440
441 // Pack fields independently
448 m_side_impl.pack(side, result);
449
450 // Do checks
451 if (checks) {
453 }
454
455 return result;
456}
457
458inline Identifier
460 int layer_disk,
461 int phi_module,
462 int eta_module,
463 int side) const {
465 do_checks());
466}
467
468//----------------------------------------------------------------------------
469inline Identifier
472
473 // reset the strip field
474 m_strip_impl.reset(result);
475 if(m_hasRows) m_row_impl.reset(result);
476 return(result);
477}
478
479//----------------------------------------------------------------------------
480inline Identifier
484
485//----------------------------------------------------------------------------
486inline IdentifierHash
488 id_vec_it it = std::lower_bound(m_wafer_vec.begin(),
489 m_wafer_vec.end(),
490 wafer_id);
491
492 // Require that wafer_id matches the one in vector
493 if (it != m_wafer_vec.end() && wafer_id == (*it)) {
494 return(it - m_wafer_vec.begin());
495 }
497 return(result); // return hash in invalid state
498}
499
500//----------------------------------------------------------------------------
501inline Identifier
503 int layer_disk,
504 int phi_module,
505 int eta_module,
506 int side,
507 int strip,
508 bool checks) const {
509 // Build identifier
510 Identifier result((Identifier::value_type) 0);
511
512 // Pack fields independently
519 m_side_impl.pack(side, result);
521
522 // Do checks
523 if (checks) {
525 }
526 return result;
527}
528
529inline Identifier
531 int layer_disk,
532 int phi_module,
533 int eta_module,
534 int side,
535 int strip) const {
537 do_checks());
538}
539
540//----------------------------------------------------------------------------
541
542inline Identifier
544 int layer_disk,
545 int phi_module,
546 int eta_module,
547 int side,
548 int row,
549 int strip,
550 bool checks) const {
551 // Build identifier
552 Identifier result((Identifier::value_type) 0);
553
554
555 // Pack fields independently
562 m_side_impl.pack(side, result);
563 if (m_hasRows) {
564 m_row_impl.pack(row, result);
565 }
567
568
569 // Do checks
570 if (checks) {
573 }
574
575 return result;
576}
577
578inline Identifier
580 int layer_disk,
581 int phi_module,
582 int eta_module,
583 int side,
584 int row,
585 int strip) const {
587 side, row, strip, do_checks());
588}
589
590//----------------------------------------------------------------------------
591inline Identifier
593 // Build identifier
595
596 // Reset strip and then add in value
597 m_strip_impl.reset(result);
599
600 if (m_do_checks) {
605 side(result),
606 strip);
607 }
608 return result;
609}
610
611//----------------------------------------------------------------------------
612inline Identifier
614 // Build identifier
616
617 // Reset strip and then add in value
618 if (m_hasRows) {
619 m_row_impl.reset(result);
620 m_row_impl.pack(row, result);
621 }
622 m_strip_impl.reset(result);
624
625 if (m_do_checks) {
626 if (m_hasRows) {
631 side(result),
632 row,
633 strip);
634 } else {
639 side(result),
640 strip);
641 }
642 }
643 return result;
644}
645
646//----------------------------------------------------------------------------
647inline Identifier::diff_type
648SCT_ID::calc_offset(const Identifier& base, const Identifier& target) const {
649 Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit());
650 Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit());
651 return(tval - bval);
652}
653
654//----------------------------------------------------------------------------
655inline Identifier
657 Identifier::diff_type offset) const {
658 Identifier::value_type bval = base.get_compact() >> base_bit();
659 return Identifier((bval + offset) << base_bit());
660}
661
662//----------------------------------------------------------------------------
663inline int
665 int base = static_cast<int>(m_strip_impl.shift()); // lowest field base
666
667 return (base > 32) ? 32 : base;
668 // max base is 32 so we can still read old strip id's and differences
669 // from non-SLHC releases.
670}
671
672//----------------------------------------------------------------------------
673inline bool
675 // match bec field
676 return(m_barrel_field.match(m_bec_impl.unpack(id)));
677}
678
679//----------------------------------------------------------------------------
680inline int
682 return(m_bec_impl.unpack(id));
683}
684
685//----------------------------------------------------------------------------
686inline int
688 return(m_lay_disk_impl.unpack(id));
689}
690
691//----------------------------------------------------------------------------
692inline int
694 return(m_phi_mod_impl.unpack(id));
695}
696
697//----------------------------------------------------------------------------
698inline int
700 return(m_eta_mod_impl.unpack(id));
701}
702
703//----------------------------------------------------------------------------
704inline int
705SCT_ID::side(const Identifier& id) const {
706 return(m_side_impl.unpack(id));
707}
708
709//----------------------------------------------------------------------------
710inline int
711SCT_ID::row(const Identifier& id) const {
712 return(m_row_impl.unpack(id));
713}
714
715//----------------------------------------------------------------------------
716inline int
717SCT_ID::strip(const Identifier& id) const {
718 return(m_strip_impl.unpack(id));
719}
720
721inline IdentifierHash
722SCT_ID::nextInSequence(const IdentifierHash& id, const hash_vec& vectorOfHashes) const {
723 unsigned short index = id;
724 if (index < vectorOfHashes.size()) {
725 return vectorOfHashes[index];
726 }
727 return IdentifierHash{};
728}
729
730#endif // INDETIDENTIFIER_SCT_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.
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.
int sct_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 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
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
std::array< IdentifierHash, 5 > neighbours_by_phi(const IdentifierHash &idh) const
Definition SCT_ID.cxx:735
Identifier::size_type size_type
Definition SCT_ID.h:72
int phi_module_max(const Identifier &id) const
Definition SCT_ID.cxx:205
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override final
Initialization from the identifier dictionary.
Definition SCT_ID.cxx:216
hash_vec m_next_phi_wafer_vec
Definition SCT_ID.h:363
Identifier::diff_type calc_offset(const Identifier &base, const Identifier &target) const
Calculate a channel offset between the two identifiers.
Definition SCT_ID.h:648
IdentifierHash nextInSequence(const IdentifierHash &id, const hash_vec &vectorOfHashes) const
Definition SCT_ID.h:722
int getMaxField(const Identifier &id, const ExpandedIdIndices &fieldIndx) const
Definition SCT_ID.cxx:128
Identifier strip_id_offset(const Identifier &base, Identifier::diff_type offset) const
Create an identifier with a given base and channel offset.
Definition SCT_ID.h:656
int base_bit() const
Return the lowest bit position used in the channel id.
Definition SCT_ID.h:664
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 SCT_ID.cxx:693
std::array< size_t, NUM_INDICES > m_indices
Definition SCT_ID.h:354
virtual ~SCT_ID()=default
const std::array< std::function< IdentifierHash(const IdentifierHash &)>, 5 > & neighbour_calls_by_eta() const
return functions to give neighbours in order: opposite, eta minus, eta plus, phi minus,...
Definition SCT_ID.cxx:381
size_type wafer_hash_max() const
Definition SCT_ID.cxx:621
size_type m_strip_hash_max
Definition SCT_ID.h:359
size_type m_wafer_hash_max
Definition SCT_ID.h:358
const IdDictDictionary * m_dict
Definition SCT_ID.h:355
IdDictFieldImplementation m_eta_mod_impl
Definition SCT_ID.h:373
MultiRange::const_identifier_factory const_expanded_id_iterator
Definition SCT_ID.h:74
int layer_disk(const Identifier &id) const
Definition SCT_ID.h:687
int side(const Identifier &id) const
Definition SCT_ID.h:705
std::array< std::function< IdentifierHash(const IdentifierHash &)>, 5 > m_neighboursByEta
Definition SCT_ID.h:311
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 SCT_ID.cxx:672
const_id_iterator wafer_end() const
Definition SCT_ID.cxx:634
int initLevelsFromDict()
Definition SCT_ID.cxx:548
bool is_phi_module_max(const Identifier &id) const
Definition SCT_ID.cxx:210
IdContext strip_context() const
Definition SCT_ID.cxx:780
IdDictFieldImplementation m_row_impl
Definition SCT_ID.h:375
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition SCT_ID.h:487
bool is_eta_module_max(const Identifier &id) const
For the barrel.
Definition SCT_ID.cxx:199
id_vec m_wafer_vec
Definition SCT_ID.h:361
IdDictFieldImplementation m_side_impl
Definition SCT_ID.h:374
bool m_hasRows
Definition SCT_ID.h:366
std::vector< Identifier >::const_iterator const_id_iterator
Definition SCT_ID.h:73
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition SCT_ID.h:459
int strip_max(const Identifier &id) const
Definition SCT_ID.cxx:188
int row(const Identifier &id) const
Definition SCT_ID.h:711
std::array< IdentifierHash, 5 > neighbours_by_eta(const IdentifierHash &idh) const
Definition SCT_ID.cxx:724
int get_prev_in_eta(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in eta (return == 0 for neighbor found)
Definition SCT_ID.cxx:407
int layer_disk_max(const Identifier &id) const
Max/Min values for each field (-999 == failure)
Definition SCT_ID.cxx:153
id_vec::const_iterator id_vec_it
Definition SCT_ID.h:307
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 SCT_ID.cxx:648
int get_prev_in_phi(const IdentifierHash &id, IdentifierHash &prev) const
Previous wafer hash in phi (return == 0 for neighbor found)
Definition SCT_ID.cxx:387
Identifier idForCheck(const Identifier &id) const
const_expanded_id_iterator strip_end() const
Definition SCT_ID.cxx:642
int phi_module(const Identifier &id) const
Definition SCT_ID.h:693
Identifier module_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition SCT_ID.h:411
int strip(const Identifier &id) const
Definition SCT_ID.h:717
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition SCT_ID.h:681
size_type m_sct_region_index
Definition SCT_ID.h:352
Range::field m_barrel_field
Definition SCT_ID.h:360
int get_next_in_eta(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in eta (return == 0 for neighbor found)
Definition SCT_ID.cxx:417
void strip_id_checks(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side, int strip) const
Definition SCT_ID.cxx:66
IdDictFieldImplementation m_bec_impl
Definition SCT_ID.h:370
std::vector< Identifier > id_vec
Definition SCT_ID.h:306
int eta_module_max(const Identifier &id) const
Definition SCT_ID.cxx:183
IdDictFieldImplementation m_phi_mod_impl
Definition SCT_ID.h:372
IdDictFieldImplementation m_indet_impl
Definition SCT_ID.h:368
int eta_module(const Identifier &id) const
Definition SCT_ID.h:699
hash_vec::const_iterator hash_vec_it
Definition SCT_ID.h:309
IdDictFieldImplementation m_strip_impl
Definition SCT_ID.h:376
MultiRange m_full_strip_range
Definition SCT_ID.h:357
size_type strip_hash_max() const
Definition SCT_ID.cxx:626
int init_hashes()
Definition SCT_ID.cxx:304
int get_next_in_phi(const IdentifierHash &id, IdentifierHash &next) const
Next wafer hash in phi (return == 0 for neighbor found)
Definition SCT_ID.cxx:397
AtlasDetectorID::HelperType helper() const override final
This is an SCT_ID helper.
Definition SCT_ID.h:84
int init_neighbors()
Definition SCT_ID.cxx:450
IdContext wafer_context() const
Definition SCT_ID.cxx:772
int get_other_side(const IdentifierHash &id, IdentifierHash &other) const
Wafer hash on other side.
Definition SCT_ID.cxx:427
SCT_ID()
Definition SCT_ID.cxx:34
void wafer_id_checks(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
Definition SCT_ID.cxx:47
std::vector< IdentifierHash > hash_vec
Definition SCT_ID.h:308
hash_vec m_next_eta_wafer_vec
Definition SCT_ID.h:365
Identifier strip_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side, int strip) const
For an individual strip.
Definition SCT_ID.h:530
const_expanded_id_iterator strip_begin() const
For strip ids, only expanded id iterators are available.
Definition SCT_ID.cxx:638
IdDictFieldImplementation m_sct_impl
Definition SCT_ID.h:369
bool is_eta_module_min(const Identifier &id) const
For the barrel.
Definition SCT_ID.cxx:193
ExpandedIdIndices
Definition SCT_ID.h:310
@ INDET
Definition SCT_ID.h:310
@ STRIP
Definition SCT_ID.h:310
@ SIDE
Definition SCT_ID.h:310
@ BARREL_EC
Definition SCT_ID.h:310
@ ROW
Definition SCT_ID.h:310
@ PHI
Definition SCT_ID.h:310
@ NUM_INDICES
Definition SCT_ID.h:310
@ LAYER_DISK
Definition SCT_ID.h:310
@ ETA
Definition SCT_ID.h:310
const_id_iterator wafer_begin() const
Iterators over full set of ids. Wafer iterator is sorted.
Definition SCT_ID.cxx:630
bool is_barrel(const Identifier &id) const
Test for barrel - WARNING: id MUST be sct id, otherwise answer is not accurate. Use SiliconID for gen...
Definition SCT_ID.h:674
hash_vec m_prev_eta_wafer_vec
Definition SCT_ID.h:364
int eta_module_min(const Identifier &id) const
Definition SCT_ID.cxx:158
MultiRange m_full_wafer_range
Definition SCT_ID.h:356
hash_vec m_prev_phi_wafer_vec
Definition SCT_ID.h:362
IdDictFieldImplementation m_lay_disk_impl
Definition SCT_ID.h:371
std::string base
Definition hcg.cxx:81
Definition index.py:1
STL namespace.
#define private