CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondFormats/SiPixelObjects/interface/PixelIndices.h

Go to the documentation of this file.
00001 #ifndef TP_PIXELINDICES_H
00002 #define TP_PIXELINDICES_H
00003 
00004 #include <iostream>
00005 
00021 namespace {
00022   // A few constants just for error checking
00023   // The maximum number of ROCs in the X (row) direction per sensor.
00024   const int maxROCsInX = 2;  //  
00025   // The maximum number of ROCs in the Y (column) direction per sensor.
00026   const int maxROCsInY = 8;  //
00027   // The nominal number of double columns per ROC is 26. 
00028   const int DColsPerROC = 26; 
00029   // Default ROC size 
00030   const int ROCSizeInX = 80;  // ROC row size in pixels 
00031   const int ROCSizeInY = 52;  // ROC col size in pixels 
00032   // Default DET barrel size 
00033   const int defaultDetSizeInX = 160;  // Det barrel row size in pixels 
00034   const int defaultDetSizeInY = 416;  // Det barrel col size in pixels 
00035   
00036   // Check the limits
00037   const bool TP_CHECK_LIMITS = true;
00038 }
00039 
00040 class PixelIndices {
00041 
00042  public:
00043   
00044   //*********************************************************************
00045   // Constructor with the ROC size fixed to the default.
00046    PixelIndices(const int colsInDet,  const int rowsInDet ) : 
00047                 theColsInDet(colsInDet), theRowsInDet (rowsInDet) {
00048  
00049     theChipsInX = theRowsInDet / ROCSizeInX; // number of ROCs in X
00050     theChipsInY = theColsInDet / ROCSizeInY;    // number of ROCs in Y
00051 
00052     if(TP_CHECK_LIMITS) {
00053       if(theChipsInX<1 || theChipsInX>maxROCsInX) 
00054         std::cout << " PixelIndices: Error in ROCsInX " 
00055              << theChipsInX <<" "<<theRowsInDet<<" "<<ROCSizeInX<<std::endl;
00056       if(theChipsInY<1 || theChipsInY>maxROCsInY) 
00057         std::cout << " PixelIndices: Error in ROCsInY " 
00058              << theChipsInY <<" "<<theColsInDet<<" "<<ROCSizeInY<<std::endl;
00059     }
00060   } 
00061   //************************************************************************
00062   ~PixelIndices() {}
00063   //***********************************************************************
00064  
00065   inline int numberOfROCsInX(void) {return theChipsInX;}
00066   inline int numberOfROCsInY(void) {return theChipsInY;}
00067 
00068   //***********************************************************************
00069 
00070  void print(void) const {
00071 
00072     std::cout << " Pixel det with " << theChipsInX << " chips in x and "
00073          << theChipsInY << " in y " << std::endl; 
00074     std::cout << " Pixel rows " << theRowsInDet << " and columns " 
00075          << theColsInDet << std::endl;  
00076     std::cout << " Rows in one chip " << ROCSizeInX << " and columns " 
00077          << ROCSizeInY << std::endl;  
00078     std::cout << " Double columns per ROC " << DColsPerROC << std::endl;
00079   }
00080 
00081   //********************************************************************
00082   // Convert dcol & pix indices to ROC col and row
00083   // Decoding from "Weber" pixel addresses to rows for PSI46
00084   // dcol = 0 - 25
00085   // pix = 2 - 161, zigzag pattern.
00086   // colAdd = 0-51   ! col&row start from 0
00087   // rowAdd = 0-79
00088   inline static int convertDcolToCol(const int dcol, const int pix, 
00089                                      int & colROC, int & rowROC) {
00090 
00091       if(TP_CHECK_LIMITS) { 
00092         if(dcol<0||dcol>=DColsPerROC||pix<2||pix>161) {
00093           std::cout<<"PixelIndices: wrong dcol or pix "<<dcol<<" "<<pix<<std::endl;
00094           rowROC = -1;     // dummy row Address
00095           colROC = -1;     // dummy col Address
00096           return -1; // Signal error
00097         }
00098       }
00099 
00100       // First find if we are in the first or 2nd col of a dcol.
00101       int colEvenOdd = pix%2;  // module(2), 0-1st sol, 1-2nd col.
00102       // Transform
00103       colROC = dcol * 2 + colEvenOdd; // col address, starts from 0
00104       rowROC = abs( int(pix/2) - 80); // row addres, starts from 0
00105 
00106       if(TP_CHECK_LIMITS) {
00107         if(colROC<0||colROC>=ROCSizeInY||rowROC<0||rowROC>=ROCSizeInX ) {
00108           std::cout<<"PixelIndices: wrong col or row "<<colROC<<" "<<rowROC<<" "
00109               <<dcol<<" "<<pix<<std::endl;
00110           rowROC = -1;    // dummy row Address
00111           colROC = -1;    // dummy col Address
00112           return -1;
00113         }
00114       }
00115       return 0;
00116     }
00117 
00118  //********************************************************************
00119  // colROC, rowROC are coordinates in the ROC frame, for ROC=rocId
00120  // (Start from 0).
00121  // cols, row are coordinates in the module frame, start from 0.
00122  // row is X, col is Y.
00123  // At the moment this works only for modules read with a single TBM.
00124   int transformToModule(const int colROC,const int rowROC,
00125                         const int rocId,
00126                         int & col,int & row ) const {
00127 
00128        if(TP_CHECK_LIMITS) {
00129         if(colROC<0 || colROC>=ROCSizeInY || rowROC<0 ||rowROC>=ROCSizeInX) {
00130           std::cout<<"PixelIndices: wrong index "<<colROC<<" "<<rowROC<<std::endl;
00131           return -1;
00132         }
00133       }
00134 
00135       // The transformation depends on the ROC-ID
00136       if(rocId>=0 && rocId<8) {
00137         row = 159-rowROC;
00138         //col = rocId*52 + colROC;
00139         col = (8-rocId)*ROCSizeInY - colROC - 1;
00140       } else if(rocId>=8 && rocId<16) {
00141         row = rowROC;
00142         //col = (16-rocId)*52 - colROC - 1;
00143         col = (rocId-8)*ROCSizeInY + colROC;
00144       } else {
00145         std::cout<<"PixelIndices: wrong ROC ID "<<rocId<<std::endl;
00146         return -1;
00147       }
00148       if(TP_CHECK_LIMITS) {
00149         if(col<0 || col>=(ROCSizeInY*theChipsInY) || row<0 || 
00150                              row>=(ROCSizeInX*theChipsInX)) {
00151         std::cout<<"PixelIndices: wrong index "<<col<<" "<<row<<std::endl;
00152         return -1;
00153         }
00154       }
00155 
00156       return 0;
00157   }
00158   //**************************************************************************
00159   // Transform from the module indixes to the ROC indices.
00160   // col, row - indices in the Module
00161   // rocId - roc index
00162   // colROC, rowROC - indices in the ROC frame.
00163   int transformToROC(const int col,const int row,
00164                      int & rocId, int & colROC, int & rowROC ) const {
00165 
00166       if(TP_CHECK_LIMITS) {
00167         if(col<0 || col>=(ROCSizeInY*theChipsInY) || row<0 || 
00168                              row>=(ROCSizeInX*theChipsInX)) {
00169           std::cout<<"PixelIndices: wrong index 3 "<<std::endl;
00170           return -1;
00171         }
00172       }
00173 
00174       // Get the 2d ROC coordinate
00175       int chipX = row / ROCSizeInX; // row index of the chip 0-1
00176       int chipY = col / ROCSizeInY; // col index of the chip 0-7
00177 
00178       // Get the ROC id from the 2D index
00179       rocId = rocIndex(chipX,chipY); 
00180       if(TP_CHECK_LIMITS && (rocId<0 || rocId>=16) ) {
00181         std::cout<<"PixelIndices: wrong roc index "<<rocId<<std::endl;
00182         return -1;
00183       }
00184       // get the local ROC coordinates
00185       rowROC = (row%ROCSizeInX); // row in chip
00186       colROC = (col%ROCSizeInY); // col in chip
00187 
00188       if(rocId<8) { // For lower 8 ROCs the coordinates are reversed
00189         colROC = 51 - colROC;
00190         rowROC = 79 - rowROC;
00191       }
00192 
00193       if(TP_CHECK_LIMITS) {
00194         if(colROC<0||colROC>=ROCSizeInY||rowROC<0||rowROC>=ROCSizeInX) {
00195           std::cout<<"PixelIndices: wrong index "<<colROC<<" "<<rowROC<<std::endl;
00196           return -1;
00197         }
00198       }
00199 
00200       return 0;
00201   }
00202   //***********************************************************************
00203   // Calculate a single number ROC index from the 2 ROC indices (coordinates)
00204   // chipX and chipY.
00205   // Goes from 0 to 15.
00206   inline static int rocIndex(const int chipX, const int chipY) {
00207 
00208     int rocId = -1;
00209     if(TP_CHECK_LIMITS) {
00210       if(chipX<0 || chipX>=2 ||chipY<0 || chipY>=8) {
00211         std::cout<<"PixelChipIndices: wrong index "<<chipX<<" "<<chipY<<std::endl;
00212         return -1;
00213       }
00214     }
00215     if(chipX==0) rocId = chipY + 8;  // should be 8-15
00216     else if(chipX==1) rocId = 7 - chipY; // should be 0-7
00217 
00218     if(TP_CHECK_LIMITS) {
00219       if(rocId < 0 || rocId >= (maxROCsInX*maxROCsInY) ) {
00220         std::cout << "PixelIndices: Error in ROC index " << rocId << std::endl;
00221         return -1;
00222       }
00223     }
00224     return rocId;
00225   }
00226   //**************************************************************************
00227   // Calculate the dcol in ROC from the col in ROC frame.
00228   // dcols go from 0 to 25.
00229   inline static int DColumn(const int colROC) {
00230 
00231     int dColumnId = (colROC)/2; // double column 0-25
00232     if(TP_CHECK_LIMITS) {
00233       if(dColumnId<0 || dColumnId>=26) {
00234         std::cout<<"PixelIndices: wrong dcol index  "<<dColumnId<<" "<<colROC<<std::endl;
00235         return -1;
00236       }
00237     }
00238     return dColumnId;
00239   }
00240   //*************************************************************************
00241   // Calcuulate the global dcol index within a module
00242   // Usefull only forin efficiency calculations.  
00243   inline static int DColumnInModule(const int dcol, const int chipIndex) {
00244     int dcolInMod = dcol + chipIndex * 26;
00245     return dcolInMod;
00246   }
00247 
00248   // This is routines to generate ROC channel number
00249   // Only limited use to store ROC pixel indices for calibration  
00250   inline static int pixelToChannelROC(const int rowROC, const int colROC) {
00251     return (rowROC<<6) | colROC;  // reserve 6 bit for col ROC index 0-52
00252   }
00253   inline static std::pair<int,int> channelToPixelROC(const int chan) {
00254     int rowROC = (chan >> 6) & 0x7F; // reserve 7 bits for row ROC index 0-79 
00255     int colROC = chan & 0x3F;
00256     return std::pair<int,int>(rowROC,colROC);
00257   }
00258   
00259 
00260   //***********************************************************************
00261  private:
00262 
00263     int theColsInDet;      // Columns per Det
00264     int theRowsInDet;      // Rows per Det
00265     int theChipsInX;       // Chips in det in X (column direction)
00266     int theChipsInY;       // Chips in det in Y (row direction)
00267 };
00268 
00269 #endif
00270 
00271 
00272 
00273