ATLAS Offline Software
PixelModuleHelper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 #ifndef INDET_PIXELMODULEHELPER_H
5 #define INDET_PIXELMODULEHELPER_H
6 
8 #include <cassert>
9 #include <array>
10 #include <stdexcept>
11 
12 namespace InDet {
13 
14  namespace MaskUtils {
15  template<unsigned int bit, unsigned int end>
16  static consteval unsigned int createMask() {
17  // assert(bit<end);
18  // assert(end<31u);
19  if constexpr(bit>31u) {
20  return 0u;
21  }
22  else if constexpr(bit>=end) {
23  return 0u;
24  }
25  else {
26  return (1u<<bit) | createMask<bit+1u,end>();
27  }
28  }
29  }
30 
34  public:
35 
36  // hierarchy chosen such that the row has the least impact on sorting order
37  // such that core column addresses of two adjacent core columns enclose all pixel addresses (column, row) of the
38  // first core column of this pair.
39  static constexpr unsigned int COLGROUP_DEFECT_BIT_MASK = (1u<<31);
40  static constexpr unsigned int CHIP_MASK = MaskUtils::createMask<24,28>(); // 16 chips max
41  static constexpr unsigned int COL_MASK = MaskUtils::createMask<12,24>(); // 4096 cols max
42  static constexpr unsigned int ROW_MASK = MaskUtils::createMask<0,12>(); // 4096 rows max
43  static constexpr unsigned int CHIP_SHIFT = 24;
44  static constexpr unsigned int COL_SHIFT = 12;
45  static constexpr unsigned int ROW_SHIFT = 0;
46 
47  static constexpr unsigned int N_COLS_PER_GROUP = 8;
48  static constexpr unsigned int COL_MASK_FOR_GROUP = MaskUtils::createMask<12,3+12>(); //8 columns per group
49 
51  : m_pixelModuleDesign( dynamic_cast<const InDetDD::PixelModuleDesign *>(&design))
52  {
53  if (m_pixelModuleDesign->rowsPerCircuit()==400 /* @TODO find a better way to identify when to swap columns and rows*/ ) {
54  // the front-ends of ITk ring triplet modules are rotated differently
55  // wrt. the offline coordinate system compared to quads and
56  // barrel triplets. Once these modules are identified, the translation
57  // works in exactly the same way, but columns and rows need to be swapped,
65  }
66  else {
74  }
75 
76  }
77  operator bool () const { return m_pixelModuleDesign != nullptr; }
78 
79  unsigned int columns() const { return m_columns; }
80  unsigned int rows() const { return m_rows; }
81  unsigned int columnsPerCircuit() const { return m_columnsPerCircuit; }
82  unsigned int rowsPerCircuit() const { return m_rowsPerCircuit; }
83  unsigned int circuitsPerColumn() const { return m_circuitsPerColumn; }
84  unsigned int circuitsPerRow() const { return m_circuitsPerRow; }
86 
92  unsigned int hardwareCoordinates(unsigned int row, unsigned int column) const {
93  unsigned int chip =0;
94  if (swapOfflineRowsColumns()) {
95  unsigned int tmp=row;
96  row=column;
97  column=tmp;
98  }
99  if (circuitsPerColumn()>1) {
100  assert( circuitsPerColumn() == 2);
101  chip += (row/rowsPerCircuit()) * circuitsPerRow();
102  row = row % rowsPerCircuit();
103  if (chip>0) {
104  row = rowsPerCircuit() - row -1;
105  column = columns() - column -1;
106  }
107  }
108  if (circuitsPerRow()>1) {
109  chip += column/columnsPerCircuit();
111  }
112  assert( (chip & (CHIP_MASK >> CHIP_SHIFT)) == chip);
113  assert( (column & (COL_MASK >> COL_SHIFT)) == column);
114  assert( (row & (ROW_MASK >> ROW_SHIFT)) == row);
115 
116  return (chip << CHIP_SHIFT) | (column << COL_SHIFT) | (row << ROW_SHIFT);
117  }
118 
127  unsigned int columnGroupDefect(unsigned int row, unsigned int column) const {
129  }
130 
131  unsigned int nPixels() const {
133  }
134  unsigned int nColumns() const {
135  return m_pixelModuleDesign->columns();
136  }
137  unsigned int nRows() const {
138  return m_pixelModuleDesign->rows();
139  }
140  static constexpr unsigned int getChip(unsigned int hardware_coordinates) {
141  return (hardware_coordinates & CHIP_MASK) >> CHIP_SHIFT;
142  }
143  static constexpr unsigned int getRow(unsigned int hardware_coordinates) {
144  return (hardware_coordinates & ROW_MASK) >> ROW_SHIFT;
145  }
146  static constexpr unsigned int getColumn(unsigned int hardware_coordinates) {
147  return (hardware_coordinates & COL_MASK) >> COL_SHIFT;
148  }
149 
152  static constexpr bool isColumnGroupDefect(unsigned int key) {
153  return key & COLGROUP_DEFECT_BIT_MASK;
154  }
155 
158  static constexpr bool inSameColumnGroup(unsigned int key_ref, unsigned int key_test) {
159  constexpr unsigned int mask_out_rows_and_cols_per_group = (CHIP_MASK|(COL_MASK & (~COL_MASK_FOR_GROUP)));
160  return (key_ref & mask_out_rows_and_cols_per_group)
161  == (key_test & mask_out_rows_and_cols_per_group);
162  }
163 
166  constexpr static bool isSameDefect( unsigned int key_ref, unsigned int key_test) {
167  return (key_ref & (CHIP_MASK | ROW_MASK | COL_MASK)) == key_test;
168  }
169 
184  constexpr static bool isSameDefectWithGroups( unsigned int key_ref, unsigned int key_test) {
185  return isSameDefect(key_ref, key_test) || (isColumnGroupDefect(key_ref) && inSameColumnGroup(key_ref, key_test));
186  }
187 
192  std::array<unsigned int,4> offlineRange(unsigned int key) const {
193  if (isColumnGroupDefect(key)) {
194  if (getRow(key) !=0) {
195  throw std::runtime_error("invalid key");
196  };
197 
198  unsigned int chip=getChip(key);
199  unsigned int row=getRow(key);
200  unsigned int row_end=row + rowsPerCircuit()-1;
201  unsigned int column=getColumn(key);
202  unsigned int column_end= column + N_COLS_PER_GROUP-1;
203 
204  unsigned int chip_row = chip / circuitsPerRow();
205  unsigned int chip_column = chip % circuitsPerRow();
206 
207  column += chip_column * columnsPerCircuit();
208  column_end += chip_column * columnsPerCircuit();
209  if (chip_row>=1) {
210  column = columns() - column -1;
211  column_end = columns() - column_end -1;
212 
213  row = rowsPerCircuit() - row -1 + chip_row * rowsPerCircuit();
214  row_end = rowsPerCircuit() - row_end -1 + chip_row * rowsPerCircuit();
215  }
216  if (swapOfflineRowsColumns()) {
217  return std::array<unsigned int,4>{ std::min(column, column_end), std::max(column,column_end)+1,
218  std::min(row, row_end), std::max(row, row_end)+1 };
219  }
220  else {
221  return std::array<unsigned int,4>{ std::min(row, row_end), std::max(row, row_end)+1,
222  std::min(column, column_end), std::max(column,column_end)+1 };
223  }
224  }
225  else {
226  unsigned int chip=getChip(key);
227  unsigned int row=getRow(key);
228  unsigned int column=getColumn(key);
229 
230  unsigned int chip_row = chip / circuitsPerRow();
231  unsigned int chip_column = chip % circuitsPerRow();
232 
233  column += chip_column * columnsPerCircuit();
234  if (chip_row>=1) {
235  column = columns() - column -1;
236 
237  row = rowsPerCircuit() - row -1 + chip_row * rowsPerCircuit();
238  }
239  if (swapOfflineRowsColumns()) {
240  return std::array<unsigned int,4 >{ column, column + 1,
241  row, row +1 };
242  }
243  else {
244  return std::array<unsigned int,4>{ row, row + 1,
245  column, column +1 };
246  }
247  }
248  }
249 
250  private:
252  unsigned short m_rows = 0;
253  unsigned short m_columns = 0;
254  unsigned short m_rowsPerCircuit = 0;
255  unsigned short m_columnsPerCircuit = 0;
256  unsigned char m_circuitsPerRow = 0;
257  unsigned char m_circuitsPerColumn = 0;
259  };
260 }
261 #endif
InDet::PixelModuleHelper::inSameColumnGroup
static constexpr bool inSameColumnGroup(unsigned int key_ref, unsigned int key_test)
Test whether the two packed hardware coorindates refer to the same column group.
Definition: PixelModuleHelper.h:158
query_example.row
row
Definition: query_example.py:24
InDet::PixelModuleHelper::isSameDefectWithGroups
constexpr static bool isSameDefectWithGroups(unsigned int key_ref, unsigned int key_test)
Convenience function to test whether the given packed hardware coordinates refer to overlapping defec...
Definition: PixelModuleHelper.h:184
InDetDD::PixelModuleDesign
Definition: PixelModuleDesign.h:48
InDetDD::PixelModuleDesign::columns
int columns() const
Number of cell columns per module:
Definition: PixelModuleDesign.h:340
InDet::PixelModuleHelper::m_columnsPerCircuit
unsigned short m_columnsPerCircuit
Definition: PixelModuleHelper.h:255
InDet::PixelModuleHelper
Helper class to convert between offline column, row and hardware chip, column, row coordinates.
Definition: PixelModuleHelper.h:33
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
InDet::PixelModuleHelper::COLGROUP_DEFECT_BIT_MASK
static constexpr unsigned int COLGROUP_DEFECT_BIT_MASK
Definition: PixelModuleHelper.h:39
InDetDD::PixelModuleDesign::rows
int rows() const
Number of cell rows per module:
Definition: PixelModuleDesign.h:345
InDet::PixelModuleHelper::offlineRange
std::array< unsigned int, 4 > offlineRange(unsigned int key) const
Convenience function to return oflline column and row ranges matching the defect-area of the given ke...
Definition: PixelModuleHelper.h:192
InDet::PixelModuleHelper::nPixels
unsigned int nPixels() const
Definition: PixelModuleHelper.h:131
DeMoUpdate.column
dictionary column
Definition: DeMoUpdate.py:1110
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
InDet::PixelModuleHelper::swapOfflineRowsColumns
bool swapOfflineRowsColumns() const
Definition: PixelModuleHelper.h:85
InDet::PixelModuleHelper::m_pixelModuleDesign
const InDetDD::PixelModuleDesign * m_pixelModuleDesign
Definition: PixelModuleHelper.h:251
InDet::PixelModuleHelper::ROW_MASK
static constexpr unsigned int ROW_MASK
Definition: PixelModuleHelper.h:42
InDet::PixelModuleHelper::getColumn
static constexpr unsigned int getColumn(unsigned int hardware_coordinates)
Definition: PixelModuleHelper.h:146
InDet::PixelModuleHelper::N_COLS_PER_GROUP
static constexpr unsigned int N_COLS_PER_GROUP
Definition: PixelModuleHelper.h:47
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
InDet::PixelModuleHelper::m_rowsPerCircuit
unsigned short m_rowsPerCircuit
Definition: PixelModuleHelper.h:254
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
InDet::PixelModuleHelper::getRow
static constexpr unsigned int getRow(unsigned int hardware_coordinates)
Definition: PixelModuleHelper.h:143
InDet::PixelModuleHelper::m_circuitsPerRow
unsigned char m_circuitsPerRow
Definition: PixelModuleHelper.h:256
InDetDD::PixelModuleDesign::numberOfCircuitsPerColumn
int numberOfCircuitsPerColumn() const
Number of circuits per column:
Definition: PixelModuleDesign.h:320
InDet::PixelModuleHelper::ROW_SHIFT
static constexpr unsigned int ROW_SHIFT
Definition: PixelModuleHelper.h:45
InDet::PixelModuleHelper::CHIP_SHIFT
static constexpr unsigned int CHIP_SHIFT
Definition: PixelModuleHelper.h:43
InDet::PixelModuleHelper::m_circuitsPerColumn
unsigned char m_circuitsPerColumn
Definition: PixelModuleHelper.h:257
InDet::PixelModuleHelper::hardwareCoordinates
unsigned int hardwareCoordinates(unsigned int row, unsigned int column) const
compute "hardware" coordinates from offline coordinates.
Definition: PixelModuleHelper.h:92
InDet::PixelModuleHelper::nColumns
unsigned int nColumns() const
Definition: PixelModuleHelper.h:134
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
InDet::PixelModuleHelper::columnGroupDefect
unsigned int columnGroupDefect(unsigned int row, unsigned int column) const
Create a "column group" defect for the given offline coordinates.
Definition: PixelModuleHelper.h:127
InDet::PixelModuleHelper::getChip
static constexpr unsigned int getChip(unsigned int hardware_coordinates)
Definition: PixelModuleHelper.h:140
InDet::PixelModuleHelper::COL_MASK
static constexpr unsigned int COL_MASK
Definition: PixelModuleHelper.h:41
InDetDD::PixelModuleDesign::numberOfCircuitsPerRow
int numberOfCircuitsPerRow() const
Number of circuits per row:
Definition: PixelModuleDesign.h:325
InDet::PixelModuleHelper::isColumnGroupDefect
static constexpr bool isColumnGroupDefect(unsigned int key)
Test whether the column group flag is set in the packed hardware coordinate tripplet.
Definition: PixelModuleHelper.h:152
InDet::PixelModuleHelper::m_swapOfflineRowsColumns
bool m_swapOfflineRowsColumns
Definition: PixelModuleHelper.h:258
InDet::PixelModuleHelper::m_rows
unsigned short m_rows
Definition: PixelModuleHelper.h:252
InDet::PixelModuleHelper::rows
unsigned int rows() const
Definition: PixelModuleHelper.h:80
InDet::PixelModuleHelper::m_columns
unsigned short m_columns
Definition: PixelModuleHelper.h:253
InDet::PixelModuleHelper::columnsPerCircuit
unsigned int columnsPerCircuit() const
Definition: PixelModuleHelper.h:81
InDet::PixelModuleHelper::CHIP_MASK
static constexpr unsigned int CHIP_MASK
Definition: PixelModuleHelper.h:40
InDetDD::PixelModuleDesign::rowsPerCircuit
int rowsPerCircuit() const
Number of cell rows per circuit:
Definition: PixelModuleDesign.h:335
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
PixelModuleDesign.h
InDet::PixelModuleHelper::rowsPerCircuit
unsigned int rowsPerCircuit() const
Definition: PixelModuleHelper.h:82
InDet::PixelModuleHelper::COL_MASK_FOR_GROUP
static constexpr unsigned int COL_MASK_FOR_GROUP
Definition: PixelModuleHelper.h:48
InDet::PixelModuleHelper::PixelModuleHelper
PixelModuleHelper(const InDetDD::SiDetectorDesign &design)
Definition: PixelModuleHelper.h:50
InDet::PixelModuleHelper::isSameDefect
constexpr static bool isSameDefect(unsigned int key_ref, unsigned int key_test)
Test whether the given packed hardware coordinates refer to the same pixel.
Definition: PixelModuleHelper.h:166
InDet::PixelModuleHelper::circuitsPerRow
unsigned int circuitsPerRow() const
Definition: PixelModuleHelper.h:84
InDet::PixelModuleHelper::circuitsPerColumn
unsigned int circuitsPerColumn() const
Definition: PixelModuleHelper.h:83
InDetDD::SiDetectorDesign
Definition: SiDetectorDesign.h:50
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
InDetDD::PixelModuleDesign::columnsPerCircuit
int columnsPerCircuit() const
Number of cell columns per circuit:
Definition: PixelModuleDesign.h:330
InDet::PixelModuleHelper::nRows
unsigned int nRows() const
Definition: PixelModuleHelper.h:137
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
InDet::PixelModuleHelper::columns
unsigned int columns() const
Definition: PixelModuleHelper.h:79
InDet::PixelModuleHelper::COL_SHIFT
static constexpr unsigned int COL_SHIFT
Definition: PixelModuleHelper.h:44