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
00023
00024 const int maxROCsInX = 2;
00025
00026 const int maxROCsInY = 8;
00027
00028 const int DColsPerROC = 26;
00029
00030 const int ROCSizeInX = 80;
00031 const int ROCSizeInY = 52;
00032
00033 const int defaultDetSizeInX = 160;
00034 const int defaultDetSizeInY = 416;
00035
00036
00037 const bool TP_CHECK_LIMITS = true;
00038 }
00039
00040 class PixelIndices {
00041
00042 public:
00043
00044
00045
00046 PixelIndices(const int colsInDet, const int rowsInDet ) :
00047 theColsInDet(colsInDet), theRowsInDet (rowsInDet) {
00048
00049 theChipsInX = theRowsInDet / ROCSizeInX;
00050 theChipsInY = theColsInDet / ROCSizeInY;
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
00083
00084
00085
00086
00087
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;
00095 colROC = -1;
00096 return -1;
00097 }
00098 }
00099
00100
00101 int colEvenOdd = pix%2;
00102
00103 colROC = dcol * 2 + colEvenOdd;
00104 rowROC = abs( int(pix/2) - 80);
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;
00111 colROC = -1;
00112 return -1;
00113 }
00114 }
00115 return 0;
00116 }
00117
00118
00119
00120
00121
00122
00123
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
00136 if(rocId>=0 && rocId<8) {
00137 row = 159-rowROC;
00138
00139 col = (8-rocId)*ROCSizeInY - colROC - 1;
00140 } else if(rocId>=8 && rocId<16) {
00141 row = rowROC;
00142
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
00160
00161
00162
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
00175 int chipX = row / ROCSizeInX;
00176 int chipY = col / ROCSizeInY;
00177
00178
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
00185 rowROC = (row%ROCSizeInX);
00186 colROC = (col%ROCSizeInY);
00187
00188 if(rocId<8) {
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
00204
00205
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;
00216 else if(chipX==1) rocId = 7 - chipY;
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
00228
00229 inline static int DColumn(const int colROC) {
00230
00231 int dColumnId = (colROC)/2;
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
00242
00243 inline static int DColumnInModule(const int dcol, const int chipIndex) {
00244 int dcolInMod = dcol + chipIndex * 26;
00245 return dcolInMod;
00246 }
00247
00248
00249
00250 inline static int pixelToChannelROC(const int rowROC, const int colROC) {
00251 return (rowROC<<6) | colROC;
00252 }
00253 inline static std::pair<int,int> channelToPixelROC(const int chan) {
00254 int rowROC = (chan >> 6) & 0x7F;
00255 int colROC = chan & 0x3F;
00256 return std::pair<int,int>(rowROC,colROC);
00257 }
00258
00259
00260
00261 private:
00262
00263 int theColsInDet;
00264 int theRowsInDet;
00265 int theChipsInX;
00266 int theChipsInY;
00267 };
00268
00269 #endif
00270
00271
00272
00273