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 rpixValues {
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 rpixValues
73 
75 public:
76  //*********************************************************************
77  // Constructor with the ROC size fixed to the default.
78 
80  theChipsInX = theRowsInDet / rpixValues::ROCSizeInX; // number of ROCs in X
81  theChipsInY = theColsInDet / rpixValues::ROCSizeInY; // number of ROCs in Y
82 
84  if (theChipsInX < 1 || theChipsInX > rpixValues::maxROCsInX)
85  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " "
87  if (theChipsInY < 1 || theChipsInY > rpixValues::maxROCsInY)
88  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " "
90  }
91  }
92 
93  CTPPSPixelIndices(const int colsInDet, const int rowsInDet) : theColsInDet(colsInDet), theRowsInDet(rowsInDet) {
94  theChipsInX = theRowsInDet / rpixValues::ROCSizeInX; // number of ROCs in X
95  theChipsInY = theColsInDet / rpixValues::ROCSizeInY; // number of ROCs in Y
96 
98  if (theChipsInX < 1 || theChipsInX > rpixValues::maxROCsInX)
99  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " "
101  if (theChipsInY < 1 || theChipsInY > rpixValues::maxROCsInY)
102  edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " "
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 " << rpixValues::ROCSizeInX << " and columns " << rpixValues::ROCSizeInY;
116  edm::LogInfo("RPix") << " Double columns per ROC " << rpixValues::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) {
128  if (dcol < 0 || dcol >= rpixValues::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 
143  if (colROC < 0 || colROC >= rpixValues::ROCSizeInY || rowROC < 0 || rowROC >= rpixValues::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 {
162  if (colROC < 0 || colROC >= rpixValues::ROCSizeInY || rowROC < 0 || rowROC >= rpixValues::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) * rpixValues::ROCSizeInY - colROC - 1;
173  } else if (rocId >= 3 && rocId < 6) {
174  row = rowROC;
175 
176  col = (5 - rocId) * rpixValues::ROCSizeInY + colROC;
177  } else {
178  edm::LogError("RPix") << "CTPPSPixelIndices: wrong ROC ID " << rocId;
179  return -1;
180  }
182  if (col < 0 || col >= (rpixValues::ROCSizeInY * theChipsInY) || row < 0 ||
183  row >= (rpixValues::ROCSizeInX * theChipsInX)) {
184  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << col << " " << row;
185  return -1;
186  }
187  }
188 
189  return 0;
190  }
191  //**************************************************************************
192  // Transform from the module indixes to the ROC indices.
193  // col, row - indices in the Module
194  // rocId - roc index
195  // colROC, rowROC - indices in the ROC frame.
196  int transformToROC(const int col, const int row, int& rocId, int& colROC, int& rowROC) const {
198  if (col < 0 || col >= (rpixValues::ROCSizeInY * theChipsInY) || row < 0 ||
199  row >= (rpixValues::ROCSizeInX * theChipsInX)) {
200  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index 3 ";
201  return -1;
202  }
203  }
204 
205  // Get the 2d ROC coordinate
206  int chipX = row / rpixValues::ROCSizeInX; // row index of the chip 0-1
207  int chipY = col / rpixValues::ROCSizeInY; // col index of the chip 0-2
208 
209  // Get the ROC id from the 2D index
210  rocId = rocIndex(chipX, chipY);
211  if (rpixValues::CTPPS_CHECK_LIMITS && (rocId < 0 || rocId >= 6)) {
212  edm::LogError("RPix") << "CTPPSPixelIndices: wrong roc index " << rocId;
213  return -1;
214  }
215  // get the local ROC coordinates
216  rowROC = (row % rpixValues::ROCSizeInX); // row in chip
217  colROC = (col % rpixValues::ROCSizeInY); // col in chip
218 
219  if (rocId < 3) {
220  colROC = 51 - colROC;
221  rowROC = 79 - rowROC;
222  }
223 
225  if (colROC < 0 || colROC >= rpixValues::ROCSizeInY || rowROC < 0 || rowROC >= rpixValues::ROCSizeInX) {
226  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << colROC << " " << rowROC;
227  return -1;
228  }
229  }
230 
231  return 0;
232  }
233 
234  // get ROC ID from module row and column
235 
236  int getROCId(const int col, const int row) const {
237  int rocId = -1;
238 
240  if (col < 0 || col >= (rpixValues::ROCSizeInY * theChipsInY) || row < 0 ||
241  row >= (rpixValues::ROCSizeInX * theChipsInX)) {
242  edm::LogError("RPix") << "CTPPSPixelIndices: wrong index ";
243  return -1;
244  }
245  }
246 
247  // Get the 2d ROC coordinate
248  int chipX = row / rpixValues::ROCSizeInX; // row index of the chip 0-1
249  int chipY = col / rpixValues::ROCSizeInY; // col index of the chip 0-2
250 
251  // Get the ROC id from the 2D index
252  rocId = rocIndex(chipX, chipY);
253  if (rpixValues::CTPPS_CHECK_LIMITS && (rocId < 0 || rocId >= 6)) {
254  edm::LogError("RPix") << "CTPPSPixelIndices: wrong roc index " << rocId;
255  return -1;
256  }
257 
258  return rocId;
259  }
260 
261  // is pixel on the edge?
262  bool isOnEdge(const int col, const int row) const {
263  if (col == 0 || row == 0 || col == (rpixValues::defaultDetSizeInY - 1) ||
264  row == (rpixValues::defaultDetSizeInX - 1))
265  return true;
266  return false;
267  }
268 
269  //***********************************************************************
270  // Calculate a single number ROC index from the 2 ROC indices (coordinates)
271  // chipX and chipY.
272  // Goes from 0 to 5.
273  inline static int rocIndex(const int chipX, const int chipY) {
274  int rocId = -1;
276  if (chipX < 0 || chipX >= 2 || chipY < 0 || chipY >= 3) {
277  edm::LogError("RPix") << "PixelChipIndices: wrong index " << chipX << " " << chipY;
278  return -1;
279  }
280  }
281  if (chipX == 0)
282  rocId = 5 - chipY; // should be 3-5
283  else if (chipX == 1)
284  rocId = chipY; // should be 0-2
285 
287  if (rocId < 0 || rocId >= (rpixValues::maxROCsInX * rpixValues::maxROCsInY)) {
288  edm::LogError("RPix") << "CTPPSPixelIndices: Error in ROC index " << rocId;
289  return -1;
290  }
291  }
292  return rocId;
293  }
294  //**************************************************************************
295  // Calculate the dcol in ROC from the col in ROC frame.
296  // dcols go from 0 to 25.
297  inline static int DColumn(const int colROC) {
298  int dColumnId = (colROC) / 2; // double column 0-25
300  if (dColumnId < 0 || dColumnId >= 26) {
301  edm::LogError("RPix") << "CTPPSPixelIndices: wrong dcol index " << dColumnId << " " << colROC;
302  return -1;
303  }
304  }
305  return dColumnId;
306  }
307  //*************************************************************************
308  // Calcuulate the global dcol index within a module
309  // Usefull only forin efficiency calculations.
310  inline static int DColumnInModule(const int dcol, const int chipIndex) {
311  int dcolInMod = dcol + chipIndex * 26;
312  return dcolInMod;
313  }
314 
315  // This is routines to generate ROC channel number
316  // Only limited use to store ROC pixel indices for calibration
317  inline static int pixelToChannelROC(const int rowROC, const int colROC) {
318  return (rowROC << 6) | colROC; // reserve 6 bit for col ROC index 0-52
319  }
320  inline static std::pair<int, int> channelToPixelROC(const int chan) {
321  int rowROC = (chan >> 6) & 0x7F; // reserve 7 bits for row ROC index 0-79
322  int colROC = chan & 0x3F;
323  return std::pair<int, int>(rowROC, colROC);
324  }
325 
328 
329  //***********************************************************************
330 private:
331  int theColsInDet; // Columns per Det
332  int theRowsInDet; // Rows per Det
333  int theChipsInX; // Chips in det in X (column direction)
334  int theChipsInY; // Chips in det in Y (row direction)
335 };
336 
337 #endif
static int convertDcolToCol(const int dcol, const int pix, int &colROC, int &rowROC)
bool isOnEdge(const int col, const int row) const
void print(void) const
CTPPSPixelIndices(const int colsInDet, const int rowsInDet)
Log< level::Error, false > LogError
static int pixelToChannelROC(const int rowROC, const int colROC)
constexpr int maxROCsInY
static int rocIndex(const int chipX, const int chipY)
constexpr int maxROCsInX
static std::pair< int, int > channelToPixelROC(const int chan)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int getDefaultRowDetSize() const
int transformToROC(const int col, const int row, int &rocId, int &colROC, int &rowROC) const
Log< level::Info, false > LogInfo
constexpr int defaultDetSizeInX
static int DColumnInModule(const int dcol, const int chipIndex)
constexpr int defaultDetSizeInY
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
int getROCId(const int col, const int row) const
constexpr bool CTPPS_CHECK_LIMITS
int transformToModule(const int colROC, const int rowROC, const int rocId, int &col, int &row) const
col
Definition: cuy.py:1009
constexpr int DColsPerROC
int getDefaultColDetSize() const
static int DColumn(const int colROC)
constexpr int ROCSizeInX
constexpr int ROCSizeInY