CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelIndices.h
Go to the documentation of this file.
1 #ifndef TP_PIXELINDICES_H
2 #define TP_PIXELINDICES_H
3 
4 #include <iostream>
5 
21 namespace {
22  // A few constants just for error checking
23  // The maximum number of ROCs in the X (row) direction per sensor.
24  const int maxROCsInX = 2; //
25  // The maximum number of ROCs in the Y (column) direction per sensor.
26  const int maxROCsInY = 8; //
27  // The nominal number of double columns per ROC is 26.
28  const int DColsPerROC = 26;
29  // Default ROC size
30  const int ROCSizeInX = 80; // ROC row size in pixels
31  const int ROCSizeInY = 52; // ROC col size in pixels
32  // Default DET barrel size
33  const int defaultDetSizeInX = 160; // Det barrel row size in pixels
34  const int defaultDetSizeInY = 416; // Det barrel col size in pixels
35 
36  // Check the limits
37  const bool TP_CHECK_LIMITS = true;
38 } // namespace
39 
40 class PixelIndices {
41 public:
42  //*********************************************************************
43  // Constructor with the ROC size fixed to the default.
44  PixelIndices(const int colsInDet, const int rowsInDet) : theColsInDet(colsInDet), theRowsInDet(rowsInDet) {
45  theChipsInX = theRowsInDet / ROCSizeInX; // number of ROCs in X
46  theChipsInY = theColsInDet / ROCSizeInY; // number of ROCs in Y
47 
48  if (TP_CHECK_LIMITS) {
49  if (theChipsInX < 1 || theChipsInX > maxROCsInX)
50  std::cout << " PixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " " << ROCSizeInX
51  << std::endl;
52  if (theChipsInY < 1 || theChipsInY > maxROCsInY)
53  std::cout << " PixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " " << ROCSizeInY
54  << std::endl;
55  }
56  }
57  //************************************************************************
59  //***********************************************************************
60 
61  inline int numberOfROCsInX(void) { return theChipsInX; }
62  inline int numberOfROCsInY(void) { return theChipsInY; }
63 
64  //***********************************************************************
65 
66  void print(void) const {
67  std::cout << " Pixel det with " << theChipsInX << " chips in x and " << theChipsInY << " in y " << std::endl;
68  std::cout << " Pixel rows " << theRowsInDet << " and columns " << theColsInDet << std::endl;
69  std::cout << " Rows in one chip " << ROCSizeInX << " and columns " << ROCSizeInY << std::endl;
70  std::cout << " Double columns per ROC " << DColsPerROC << std::endl;
71  }
72 
73  //********************************************************************
74  // Convert dcol & pix indices to ROC col and row
75  // Decoding from "Weber" pixel addresses to rows for PSI46
76  // dcol = 0 - 25
77  // pix = 2 - 161, zigzag pattern.
78  // colAdd = 0-51 ! col&row start from 0
79  // rowAdd = 0-79
80  inline static int convertDcolToCol(const int dcol, const int pix, int& colROC, int& rowROC) {
81  if (TP_CHECK_LIMITS) {
82  if (dcol < 0 || dcol >= DColsPerROC || pix < 2 || pix > 161) {
83  std::cout << "PixelIndices: wrong dcol or pix " << dcol << " " << pix << std::endl;
84  rowROC = -1; // dummy row Address
85  colROC = -1; // dummy col Address
86  return -1; // Signal error
87  }
88  }
89 
90  // First find if we are in the first or 2nd col of a dcol.
91  int colEvenOdd = pix % 2; // module(2), 0-1st sol, 1-2nd col.
92  // Transform
93  colROC = dcol * 2 + colEvenOdd; // col address, starts from 0
94  rowROC = abs(int(pix / 2) - 80); // row addres, starts from 0
95 
96  if (TP_CHECK_LIMITS) {
97  if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
98  std::cout << "PixelIndices: wrong col or row " << colROC << " " << rowROC << " " << dcol << " " << pix
99  << std::endl;
100  rowROC = -1; // dummy row Address
101  colROC = -1; // dummy col Address
102  return -1;
103  }
104  }
105  return 0;
106  }
107 
108  //********************************************************************
109  // colROC, rowROC are coordinates in the ROC frame, for ROC=rocId
110  // (Start from 0).
111  // cols, row are coordinates in the module frame, start from 0.
112  // row is X, col is Y.
113  // At the moment this works only for modules read with a single TBM.
114  int transformToModule(const int colROC, const int rowROC, const int rocId, int& col, int& row) const {
115  if (TP_CHECK_LIMITS) {
116  if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
117  std::cout << "PixelIndices: wrong index " << colROC << " " << rowROC << std::endl;
118  return -1;
119  }
120  }
121 
122  // The transformation depends on the ROC-ID
123  if (rocId >= 0 && rocId < 8) {
124  row = 159 - rowROC;
125  //col = rocId*52 + colROC;
126  col = (8 - rocId) * ROCSizeInY - colROC - 1;
127  } else if (rocId >= 8 && rocId < 16) {
128  row = rowROC;
129  //col = (16-rocId)*52 - colROC - 1;
130  col = (rocId - 8) * ROCSizeInY + colROC;
131  } else {
132  std::cout << "PixelIndices: wrong ROC ID " << rocId << std::endl;
133  return -1;
134  }
135  if (TP_CHECK_LIMITS) {
136  if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
137  std::cout << "PixelIndices: wrong index " << col << " " << row << std::endl;
138  return -1;
139  }
140  }
141 
142  return 0;
143  }
144  //**************************************************************************
145  // Transform from the module indixes to the ROC indices.
146  // col, row - indices in the Module
147  // rocId - roc index
148  // colROC, rowROC - indices in the ROC frame.
149  int transformToROC(const int col, const int row, int& rocId, int& colROC, int& rowROC) const {
150  if (TP_CHECK_LIMITS) {
151  if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
152  std::cout << "PixelIndices: wrong index 3 " << std::endl;
153  return -1;
154  }
155  }
156 
157  // Get the 2d ROC coordinate
158  int chipX = row / ROCSizeInX; // row index of the chip 0-1
159  int chipY = col / ROCSizeInY; // col index of the chip 0-7
160 
161  // Get the ROC id from the 2D index
162  rocId = rocIndex(chipX, chipY);
163  if (TP_CHECK_LIMITS && (rocId < 0 || rocId >= 16)) {
164  std::cout << "PixelIndices: wrong roc index " << rocId << std::endl;
165  return -1;
166  }
167  // get the local ROC coordinates
168  rowROC = (row % ROCSizeInX); // row in chip
169  colROC = (col % ROCSizeInY); // col in chip
170 
171  if (rocId < 8) { // For lower 8 ROCs the coordinates are reversed
172  colROC = 51 - colROC;
173  rowROC = 79 - rowROC;
174  }
175 
176  if (TP_CHECK_LIMITS) {
177  if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
178  std::cout << "PixelIndices: wrong index " << colROC << " " << rowROC << std::endl;
179  return -1;
180  }
181  }
182 
183  return 0;
184  }
185  //***********************************************************************
186  // Calculate a single number ROC index from the 2 ROC indices (coordinates)
187  // chipX and chipY.
188  // Goes from 0 to 15.
189  inline static int rocIndex(const int chipX, const int chipY) {
190  int rocId = -1;
191  if (TP_CHECK_LIMITS) {
192  if (chipX < 0 || chipX >= 2 || chipY < 0 || chipY >= 8) {
193  std::cout << "PixelChipIndices: wrong index " << chipX << " " << chipY << std::endl;
194  return -1;
195  }
196  }
197  if (chipX == 0)
198  rocId = chipY + 8; // should be 8-15
199  else if (chipX == 1)
200  rocId = 7 - chipY; // should be 0-7
201 
202  if (TP_CHECK_LIMITS) {
203  if (rocId < 0 || rocId >= (maxROCsInX * maxROCsInY)) {
204  std::cout << "PixelIndices: Error in ROC index " << rocId << std::endl;
205  return -1;
206  }
207  }
208  return rocId;
209  }
210  //**************************************************************************
211  // Calculate the dcol in ROC from the col in ROC frame.
212  // dcols go from 0 to 25.
213  inline static int DColumn(const int colROC) {
214  int dColumnId = (colROC) / 2; // double column 0-25
215  if (TP_CHECK_LIMITS) {
216  if (dColumnId < 0 || dColumnId >= 26) {
217  std::cout << "PixelIndices: wrong dcol index " << dColumnId << " " << colROC << std::endl;
218  return -1;
219  }
220  }
221  return dColumnId;
222  }
223  //*************************************************************************
224  // Calcuulate the global dcol index within a module
225  // Usefull only forin efficiency calculations.
226  inline static int DColumnInModule(const int dcol, const int chipIndex) {
227  int dcolInMod = dcol + chipIndex * 26;
228  return dcolInMod;
229  }
230 
231  // This is routines to generate ROC channel number
232  // Only limited use to store ROC pixel indices for calibration
233  inline static int pixelToChannelROC(const int rowROC, const int colROC) {
234  return (rowROC << 6) | colROC; // reserve 6 bit for col ROC index 0-52
235  }
236  inline static std::pair<int, int> channelToPixelROC(const int chan) {
237  int rowROC = (chan >> 6) & 0x7F; // reserve 7 bits for row ROC index 0-79
238  int colROC = chan & 0x3F;
239  return std::pair<int, int>(rowROC, colROC);
240  }
241 
242  //***********************************************************************
243 private:
244  int theColsInDet; // Columns per Det
245  int theRowsInDet; // Rows per Det
246  int theChipsInX; // Chips in det in X (column direction)
247  int theChipsInY; // Chips in det in Y (row direction)
248 };
249 
250 #endif
static std::pair< int, int > channelToPixelROC(const int chan)
Definition: PixelIndices.h:236
int numberOfROCsInY(void)
Definition: PixelIndices.h:62
static int DColumn(const int colROC)
Definition: PixelIndices.h:213
tuple chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, &quot;NDC&quot;) lumi.SetBorderSize( 0 ) lumi...
int transformToROC(const int col, const int row, int &rocId, int &colROC, int &rowROC) const
Definition: PixelIndices.h:149
static int rocIndex(const int chipX, const int chipY)
Definition: PixelIndices.h:189
PixelIndices(const int colsInDet, const int rowsInDet)
Definition: PixelIndices.h:44
int numberOfROCsInX(void)
Definition: PixelIndices.h:61
static int pixelToChannelROC(const int rowROC, const int colROC)
Definition: PixelIndices.h:233
static int convertDcolToCol(const int dcol, const int pix, int &colROC, int &rowROC)
Definition: PixelIndices.h:80
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void print(void) const
Definition: PixelIndices.h:66
tuple cout
Definition: gather_cfg.py:144
int col
Definition: cuy.py:1009
static int DColumnInModule(const int dcol, const int chipIndex)
Definition: PixelIndices.h:226
int transformToModule(const int colROC, const int rowROC, const int rocId, int &col, int &row) const
Definition: PixelIndices.h:114