CMS 3D CMS Logo

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