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