CMS 3D CMS Logo

CTPPSPixelIndices.h
Go to the documentation of this file.
1 #ifndef CTPPS_PIXELINDICES_H
2 #define CTPPS_PIXELINDICES_H
3 
4 #include <iostream>
24 /*
25 
26  sensor side = bump bonding side = wire bonding side
27 
28 
29  ^ sim y
30  |
31  |
32  |
33  0-----------------------------------
34  | | |
35  | 2 | 3 |
36  | | 0
37  --------------------------------------
38  0-----------------------------------
39  | | |
40  | 1 |-------4---------|--------------> sim x
41  | | 0
42  --------------------------------------
43  0----------------------------------- ^
44  | | | | det cols
45  | 0 | 5 | |
46  | | 0 |
47  -------------------------------------- |
48  |
49  <------------------------------------------ 0,0
50  det rows x
51  0 beam
52 
53 */
54 
55 namespace {
56 
57  // The maximum number of ROCs in the X (row) direction per sensor.
58  constexpr int maxROCsInX = 2; //
59  // The maximum number of ROCs in the Y (column) direction per sensor.
60  constexpr int maxROCsInY = 3; //
61  // The nominal number of double columns per ROC is 26.
62  constexpr int DColsPerROC = 26;
63  // Default ROC size
64  constexpr int ROCSizeInX = 80; // ROC row size in pixels
65  constexpr int ROCSizeInY = 52; // ROC col size in pixels
66  // Default DET barrel size
67  constexpr int defaultDetSizeInX = 160; // Det row size in pixels (2 ROCs)
68  constexpr int defaultDetSizeInY = 156; // Det col size in pixels (3 ROCs)
69 
70  // Check the limits
71  constexpr bool CTPPS_CHECK_LIMITS = true;
72 } // namespace
73 
75 public:
76  //*********************************************************************
77  // Constructor with the ROC size fixed to the default.
78 
79  CTPPSPixelIndices() : theColsInDet(defaultDetSizeInY), theRowsInDet(defaultDetSizeInX) {
80  theChipsInX = theRowsInDet / ROCSizeInX; // number of ROCs in X
81  theChipsInY = theColsInDet / ROCSizeInY; // number of ROCs in Y
82 
83  if (CTPPS_CHECK_LIMITS) {
84  if (theChipsInX < 1 || theChipsInX > maxROCsInX)
85  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " "
86  << ROCSizeInX;
87  if (theChipsInY < 1 || theChipsInY > maxROCsInY)
88  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " "
89  << ROCSizeInY;
90  }
91  }
92 
93  CTPPSPixelIndices(const int colsInDet, const int rowsInDet) : theColsInDet(colsInDet), theRowsInDet(rowsInDet) {
94  theChipsInX = theRowsInDet / ROCSizeInX; // number of ROCs in X
95  theChipsInY = theColsInDet / ROCSizeInY; // number of ROCs in Y
96 
97  if (CTPPS_CHECK_LIMITS) {
98  if (theChipsInX < 1 || theChipsInX > maxROCsInX)
99  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " "
100  << ROCSizeInX;
101  if (theChipsInY < 1 || theChipsInY > maxROCsInY)
102  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " "
103  << ROCSizeInY;
104  }
105  }
106 
108 
109  inline int numberOfROCsInX(void) { return theChipsInX; }
110  inline int numberOfROCsInY(void) { return theChipsInY; }
111 
112  void print(void) const {
113  edm::LogInfo("RPix") << " Pixel det with " << theChipsInX << " chips in x and " << theChipsInY << " in y ";
114  edm::LogInfo("RPix") << " Pixel rows " << theRowsInDet << " and columns " << theColsInDet;
115  edm::LogInfo("RPix") << " Rows in one chip " << ROCSizeInX << " and columns " << ROCSizeInY;
116  edm::LogInfo("RPix") << " Double columns per ROC " << DColsPerROC;
117  }
118 
119  //********************************************************************
120  // Convert dcol & pix indices to ROC col and row
121  // Decoding from "Weber" pixel addresses to rows for PSI46
122  // dcol = 0 - 25
123  // pix = 2 - 161, zigzag pattern.
124  // colAdd = 0-51 ! col&row start from 0
125  // rowAdd = 0-79
126  inline static int convertDcolToCol(const int dcol, const int pix, int& colROC, int& rowROC) {
127  if (CTPPS_CHECK_LIMITS) {
128  if (dcol < 0 || dcol >= DColsPerROC || pix < 2 || pix > 161) {
129  edm::LogError("RPix") << "CTPPSPixelIndices: wrong dcol or pix " << dcol << " " << pix;
130  rowROC = -1; // dummy row Address
131  colROC = -1; // dummy col Address
132  return -1; // Signal error
133  }
134  }
135 
136  // First find if we are in the first or 2nd col of a dcol.
137  int colEvenOdd = pix % 2; // module(2), 0-1st sol, 1-2nd col.
138  // Transform
139  colROC = dcol * 2 + colEvenOdd; // col address, starts from 0
140  rowROC = abs(int(pix / 2) - 80); // row addres, starts from 0
141 
142  if (CTPPS_CHECK_LIMITS) {
143  if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
144  edm::LogError("RPix") << "CTPPSPixelIndices: wrong col or row " << colROC << " " << rowROC << " " << dcol << " "
145  << pix;
146  rowROC = -1; // dummy row Address
147  colROC = -1; // dummy col Address
148  return -1;
149  }
150  }
151  return 0;
152  }
153 
154  //********************************************************************
155  // colROC, rowROC are coordinates in the ROC frame, for ROC=rocId
156  // (Start from 0).
157  // cols, row are coordinates in the module frame, start from 0.
158  // row is X, col is Y.
159  // At the moment this works only for modules read with a single TBM.
160  int transformToModule(const int colROC, const int rowROC, const int rocId, int& col, int& row) const {
161  if (CTPPS_CHECK_LIMITS) {
162  if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
163  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << colROC << " " << rowROC;
164  return -1;
165  }
166  }
167 
168  // The transformation depends on the ROC-ID
169  if (rocId >= 0 && rocId < 3) {
170  row = 159 - rowROC;
171 
172  col = (rocId + 1) * ROCSizeInY - colROC - 1;
173  } else if (rocId >= 3 && rocId < 6) {
174  row = rowROC;
175 
176  col = (5 - rocId) * ROCSizeInY + colROC;
177  } else {
178  edm::LogError("RPix") << "CTPPSPixelIndices: wrong ROC ID " << rocId;
179  return -1;
180  }
181  if (CTPPS_CHECK_LIMITS) {
182  if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
183  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << col << " " << row;
184  return -1;
185  }
186  }
187 
188  return 0;
189  }
190  //**************************************************************************
191  // Transform from the module indixes to the ROC indices.
192  // col, row - indices in the Module
193  // rocId - roc index
194  // colROC, rowROC - indices in the ROC frame.
195  int transformToROC(const int col, const int row, int& rocId, int& colROC, int& rowROC) const {
196  if (CTPPS_CHECK_LIMITS) {
197  if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
198  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index 3 ";
199  return -1;
200  }
201  }
202 
203  // Get the 2d ROC coordinate
204  int chipX = row / ROCSizeInX; // row index of the chip 0-1
205  int chipY = col / ROCSizeInY; // col index of the chip 0-2
206 
207  // Get the ROC id from the 2D index
208  rocId = rocIndex(chipX, chipY);
209  if (CTPPS_CHECK_LIMITS && (rocId < 0 || rocId >= 6)) {
210  edm::LogError("RPix") << "CTPPSPixelIndices: wrong roc index " << rocId;
211  return -1;
212  }
213  // get the local ROC coordinates
214  rowROC = (row % ROCSizeInX); // row in chip
215  colROC = (col % ROCSizeInY); // col in chip
216 
217  if (rocId < 3) {
218  colROC = 51 - colROC;
219  rowROC = 79 - rowROC;
220  }
221 
222  if (CTPPS_CHECK_LIMITS) {
223  if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
224  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << colROC << " " << rowROC;
225  return -1;
226  }
227  }
228 
229  return 0;
230  }
231 
232  // get ROC ID from module row and column
233 
234  int getROCId(const int col, const int row) const {
235  int rocId = -1;
236 
237  if (CTPPS_CHECK_LIMITS) {
238  if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
239  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index ";
240  return -1;
241  }
242  }
243 
244  // Get the 2d ROC coordinate
245  int chipX = row / ROCSizeInX; // row index of the chip 0-1
246  int chipY = col / ROCSizeInY; // col index of the chip 0-2
247 
248  // Get the ROC id from the 2D index
249  rocId = rocIndex(chipX, chipY);
250  if (CTPPS_CHECK_LIMITS && (rocId < 0 || rocId >= 6)) {
251  edm::LogError("RPix") << "CTPPSPixelIndices: wrong roc index " << rocId;
252  return -1;
253  }
254 
255  return rocId;
256  }
257 
258  // is pixel on the edge?
259  bool isOnEdge(const int col, const int row) const {
260  if (col == 0 || row == 0 || col == (defaultDetSizeInY - 1) || row == (defaultDetSizeInX - 1))
261  return true;
262  return false;
263  }
264 
265  //***********************************************************************
266  // Calculate a single number ROC index from the 2 ROC indices (coordinates)
267  // chipX and chipY.
268  // Goes from 0 to 5.
269  inline static int rocIndex(const int chipX, const int chipY) {
270  int rocId = -1;
271  if (CTPPS_CHECK_LIMITS) {
272  if (chipX < 0 || chipX >= 2 || chipY < 0 || chipY >= 3) {
273  edm::LogError("RPix") << "PixelChipIndices: wrong index " << chipX << " " << chipY;
274  return -1;
275  }
276  }
277  if (chipX == 0)
278  rocId = 5 - chipY; // should be 3-5
279  else if (chipX == 1)
280  rocId = chipY; // should be 0-2
281 
282  if (CTPPS_CHECK_LIMITS) {
283  if (rocId < 0 || rocId >= (maxROCsInX * maxROCsInY)) {
284  edm::LogError("RPix") << "CTPPSPixelIndices: Error in ROC index " << rocId;
285  return -1;
286  }
287  }
288  return rocId;
289  }
290  //**************************************************************************
291  // Calculate the dcol in ROC from the col in ROC frame.
292  // dcols go from 0 to 25.
293  inline static int DColumn(const int colROC) {
294  int dColumnId = (colROC) / 2; // double column 0-25
295  if (CTPPS_CHECK_LIMITS) {
296  if (dColumnId < 0 || dColumnId >= 26) {
297  edm::LogError("RPix") << "CTPPSPixelIndices: wrong dcol index " << dColumnId << " " << colROC;
298  return -1;
299  }
300  }
301  return dColumnId;
302  }
303  //*************************************************************************
304  // Calcuulate the global dcol index within a module
305  // Usefull only forin efficiency calculations.
306  inline static int DColumnInModule(const int dcol, const int chipIndex) {
307  int dcolInMod = dcol + chipIndex * 26;
308  return dcolInMod;
309  }
310 
311  // This is routines to generate ROC channel number
312  // Only limited use to store ROC pixel indices for calibration
313  inline static int pixelToChannelROC(const int rowROC, const int colROC) {
314  return (rowROC << 6) | colROC; // reserve 6 bit for col ROC index 0-52
315  }
316  inline static std::pair<int, int> channelToPixelROC(const int chan) {
317  int rowROC = (chan >> 6) & 0x7F; // reserve 7 bits for row ROC index 0-79
318  int colROC = chan & 0x3F;
319  return std::pair<int, int>(rowROC, colROC);
320  }
321 
322  inline int getDefaultRowDetSize() const { return defaultDetSizeInX; }
323  inline int getDefaultColDetSize() const { return defaultDetSizeInY; }
324 
325  //***********************************************************************
326 private:
327  int theColsInDet; // Columns per Det
328  int theRowsInDet; // Rows per Det
329  int theChipsInX; // Chips in det in X (column direction)
330  int theChipsInY; // Chips in det in Y (row direction)
331 };
332 
333 #endif
static int convertDcolToCol(const int dcol, const int pix, int &colROC, int &rowROC)
int getDefaultRowDetSize() const
CTPPSPixelIndices(const int colsInDet, const int rowsInDet)
static int pixelToChannelROC(const int rowROC, const int colROC)
static int rocIndex(const int chipX, const int chipY)
int getDefaultColDetSize() const
int getROCId(const int col, const int row) const
static std::pair< int, int > channelToPixelROC(const int chan)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int transformToModule(const int colROC, const int rowROC, const int rocId, int &col, int &row) const
static int DColumnInModule(const int dcol, const int chipIndex)
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
int transformToROC(const int col, const int row, int &rocId, int &colROC, int &rowROC) const
col
Definition: cuy.py:1010
void print(void) const
bool isOnEdge(const int col, const int row) const
static int DColumn(const int colROC)
#define constexpr