ATLAS Offline Software
SCT_ChipUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 /* Dear emacs, this is -*-c++-*- */
5 #ifndef SCT_CHIPUTILS_H
6 #define SCT_CHIPUTILS_H
7 
10 
11 #include <stdexcept>
12 
13 // Utilities to help with SCT chip IDs
14 namespace SCT {
15  constexpr unsigned int N_CHIPS_PER_SIDE = 6;
16  constexpr unsigned int N_SIDES = 2;
17  constexpr unsigned int N_STRIPS_PER_CHIP = 128;
19 
26  inline constexpr unsigned int getChip(unsigned int side, bool swap, unsigned int strip) {
27  // Get strip number
28  assert( strip <=N_STRIPS_PER_SIDE);
29 
30  // Conversion from strip to chip (specific for present SCT)
31  unsigned int chip{static_cast<unsigned int>(strip)/N_STRIPS_PER_CHIP}; // One ABCD chip reads 128 strips
32  // Relation between chip and offline strip is determined by the swapPhiReadoutDirection method.
33  // If swap is false
34  // offline strip: 0 767
35  // chip on side 0: 0 1 2 3 4 5
36  // chip on side 1: 11 10 9 8 7 6
37  // If swap is true
38  // offline strip: 0 767
39  // chip on side 0: 5 4 3 2 1 0
40  // chip on side 1: 6 7 8 9 10 11
41  if (side==0) {
42  chip = swap ? (N_CHIPS_PER_SIDE -1) - chip : chip;
43  } else {
44  chip = swap ? (N_CHIPS_PER_SIDE*N_SIDES-1) - chip : N_CHIPS_PER_SIDE + chip;
45  }
46  return chip;
47  }
48 
55  inline unsigned int getChip(const SCT_ID &sct_id, const InDetDD::SiDetectorElement &siElement, const Identifier& stripId) {
56  // Get strip number
57  const int strip{sct_id.strip(stripId)};
58  if (strip<0 or static_cast<unsigned int>(strip)>=N_STRIPS_PER_SIDE) {
59  throw std::range_error("Invalid SCT strip");
60  }
61 
62  return getChip(static_cast<unsigned int>(sct_id.side(stripId)),
63  siElement.swapPhiReadoutDirection(),
64  strip);
65  }
66 
71  inline constexpr unsigned int getGeometricalChipID(unsigned int strip) {
72  assert( strip < N_CHIPS_PER_SIDE * N_STRIPS_PER_CHIP );
73  return strip/N_STRIPS_PER_CHIP;
74  }
75 
81  inline unsigned int getGeometricalChipID(const SCT_ID &sct_id, const Identifier& stripId) {
82  return getGeometricalChipID(static_cast<unsigned int>(sct_id.strip(stripId)));
83  }
84 
91  inline constexpr unsigned int getGeometricalFromPhysicalChipID(unsigned int side, bool swap, unsigned int physical_chip_id) {
92  // side 0 : 0 -> 0 5 -> 5
93  // side 0 swap : 0 -> 5 5 -> 0
94  // side 1 : 6 -> 0 11 -> 5
95  // side 1 swap : 6 -> 5 11 -> 0
96  assert( (side==0 && physical_chip_id<6) || (side ==1 && physical_chip_id<12));
97  return side==0
98  ? ( swap ? N_CHIPS_PER_SIDE - 1 - physical_chip_id : physical_chip_id)
99  : ( swap ? 2*N_CHIPS_PER_SIDE - 1 - physical_chip_id : physical_chip_id - N_CHIPS_PER_SIDE);
100  }
101 
108  inline unsigned int getGeometricalFromPhysicalChipID(const SCT_ID &sct_id, const InDetDD::SiDetectorElement &siElement, unsigned int physical_chip_id) {
109  return getGeometricalFromPhysicalChipID(static_cast<unsigned int>(sct_id.side(siElement.identify())),
110  siElement.swapPhiReadoutDirection(),
111  physical_chip_id);
112  }
113 
120  inline constexpr unsigned int getPhysicalFromGeometricalChipID(unsigned int side, bool swap, unsigned int geometrical_chip_id) {
121  // side 0 : 0 -> 0 5 -> 5
122  // side 0 swap : 0 -> 5 5 -> 0
123  // side 1 : 0 -> 6 5 -> 11
124  // side 1 swap : 0 -> 11 5 -> 6
125  assert( geometrical_chip_id<6 && side<2);
126  return side==0
127  ? ( swap ? N_CHIPS_PER_SIDE - 1 - geometrical_chip_id : geometrical_chip_id)
128  : ( swap ? 2*N_CHIPS_PER_SIDE - 1 - geometrical_chip_id : geometrical_chip_id + N_CHIPS_PER_SIDE);
129  }
130 
137  inline unsigned int getPhysicalFromGeometricalChipID(const SCT_ID &sct_id, const InDetDD::SiDetectorElement &siElement, unsigned int geometrical_chip_id) {
138  return getPhysicalFromGeometricalChipID(static_cast<unsigned int>(sct_id.side(siElement.identify())),
139  siElement.swapPhiReadoutDirection(),
140  geometrical_chip_id);
141  }
142 
149  inline constexpr unsigned int getGeometricalFromPhysicalChipFlags(unsigned int side, bool swap, unsigned int physical_chip_flags) {
150  assert( side<2 );
151  // side 0 0..5 -> 0..5 or 5..0
152  // side 1 6..11 -> 0..5 or 5..0
153  unsigned int chip_flags = ( side==0 ? physical_chip_flags : physical_chip_flags>>N_CHIPS_PER_SIDE);
154  if (swap) {
155  unsigned int chip_flags_out=0;
156  // bit 0 -> 5
157  // bit 5 -> 0
158  for (unsigned int chip_i=SCT::N_CHIPS_PER_SIDE; chip_i-->0;) {
159  chip_flags_out <<=1;
160  chip_flags_out |= (chip_flags & 1);
161  chip_flags >>=1;
162  }
163  chip_flags = chip_flags_out;
164  }
165  return chip_flags;
166  }
167 
174  inline unsigned int getGeometricalFromPhysicalChipFlags(const SCT_ID &sct_id, const InDetDD::SiDetectorElement &siElement, unsigned int physical_chip_flags) {
175  return getGeometricalFromPhysicalChipFlags(static_cast<unsigned int>(sct_id.side(siElement.identify())),
176  siElement.swapPhiReadoutDirection(),
177  physical_chip_flags);
178  }
179 }
180 #endif
SCT::N_STRIPS_PER_CHIP
constexpr unsigned int N_STRIPS_PER_CHIP
Definition: SCT_ChipUtils.h:17
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
SCT::getChip
constexpr unsigned int getChip(unsigned int side, bool swap, unsigned int strip)
Get the physical chip ID for the given strip.
Definition: SCT_ChipUtils.h:26
SCT::N_SIDES
constexpr unsigned int N_SIDES
Definition: SCT_ChipUtils.h:16
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SCT::getGeometricalFromPhysicalChipID
constexpr unsigned int getGeometricalFromPhysicalChipID(unsigned int side, bool swap, unsigned int physical_chip_id)
Get the geometrical chip ID from a physica chip ID.
Definition: SCT_ChipUtils.h:91
SCT::getPhysicalFromGeometricalChipID
constexpr unsigned int getPhysicalFromGeometricalChipID(unsigned int side, bool swap, unsigned int geometrical_chip_id)
Get the physical chip ID from a geometrical chip ID.
Definition: SCT_ChipUtils.h:120
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
InDetDD::SiDetectorElement::swapPhiReadoutDirection
bool swapPhiReadoutDirection() const
Determine if readout direction between online and offline needs swapping.
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
SCT
Definition: SCT_ChipUtils.h:14
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SCT::N_STRIPS_PER_SIDE
constexpr unsigned int N_STRIPS_PER_SIDE
Definition: SCT_ChipUtils.h:18
SiDetectorElement.h
SCT_ID
Definition: SCT_ID.h:68
SCT_ID::strip
int strip(const Identifier &id) const
Definition: SCT_ID.h:764
SCT::getGeometricalChipID
constexpr unsigned int getGeometricalChipID(unsigned int strip)
Get the geometrical chip ID for the given strip.
Definition: SCT_ChipUtils.h:71
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
SCT::getGeometricalFromPhysicalChipFlags
constexpr unsigned int getGeometricalFromPhysicalChipFlags(unsigned int side, bool swap, unsigned int physical_chip_flags)
Convert a word in which each bit represents the status of a certain physical chip to a word in which ...
Definition: SCT_ChipUtils.h:149
InDetDD::SolidStateDetectorElementBase::identify
virtual Identifier identify() const override final
identifier of this detector element (inline)
SCT::N_CHIPS_PER_SIDE
constexpr unsigned int N_CHIPS_PER_SIDE
Definition: SCT_ChipUtils.h:15