File indexing completed on 2024-04-06 12:02:33
0001 #ifndef TP_PIXELINDICES_H
0002 #define TP_PIXELINDICES_H
0003
0004 #include <iostream>
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 namespace {
0022
0023
0024 const int maxROCsInX = 2;
0025
0026 const int maxROCsInY = 8;
0027
0028 const int DColsPerROC = 26;
0029
0030 const int ROCSizeInX = 80;
0031 const int ROCSizeInY = 52;
0032
0033 const int defaultDetSizeInX = 160;
0034 const int defaultDetSizeInY = 416;
0035
0036
0037 const bool TP_CHECK_LIMITS = true;
0038 }
0039
0040 class PixelIndices {
0041 public:
0042
0043
0044 PixelIndices(const int colsInDet, const int rowsInDet) : theColsInDet(colsInDet), theRowsInDet(rowsInDet) {
0045 theChipsInX = theRowsInDet / ROCSizeInX;
0046 theChipsInY = theColsInDet / ROCSizeInY;
0047
0048 if (TP_CHECK_LIMITS) {
0049 if (theChipsInX < 1 || theChipsInX > maxROCsInX)
0050 std::cout << " PixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " " << ROCSizeInX
0051 << std::endl;
0052 if (theChipsInY < 1 || theChipsInY > maxROCsInY)
0053 std::cout << " PixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " " << ROCSizeInY
0054 << std::endl;
0055 }
0056 }
0057
0058 ~PixelIndices() {}
0059
0060
0061 inline int numberOfROCsInX(void) { return theChipsInX; }
0062 inline int numberOfROCsInY(void) { return theChipsInY; }
0063
0064
0065
0066 void print(void) const {
0067 std::cout << " Pixel det with " << theChipsInX << " chips in x and " << theChipsInY << " in y " << std::endl;
0068 std::cout << " Pixel rows " << theRowsInDet << " and columns " << theColsInDet << std::endl;
0069 std::cout << " Rows in one chip " << ROCSizeInX << " and columns " << ROCSizeInY << std::endl;
0070 std::cout << " Double columns per ROC " << DColsPerROC << std::endl;
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080 inline static int convertDcolToCol(const int dcol, const int pix, int& colROC, int& rowROC) {
0081 if (TP_CHECK_LIMITS) {
0082 if (dcol < 0 || dcol >= DColsPerROC || pix < 2 || pix > 161) {
0083 std::cout << "PixelIndices: wrong dcol or pix " << dcol << " " << pix << std::endl;
0084 rowROC = -1;
0085 colROC = -1;
0086 return -1;
0087 }
0088 }
0089
0090
0091 int colEvenOdd = pix % 2;
0092
0093 colROC = dcol * 2 + colEvenOdd;
0094 rowROC = abs(int(pix / 2) - 80);
0095
0096 if (TP_CHECK_LIMITS) {
0097 if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
0098 std::cout << "PixelIndices: wrong col or row " << colROC << " " << rowROC << " " << dcol << " " << pix
0099 << std::endl;
0100 rowROC = -1;
0101 colROC = -1;
0102 return -1;
0103 }
0104 }
0105 return 0;
0106 }
0107
0108
0109
0110
0111
0112
0113
0114 int transformToModule(const int colROC, const int rowROC, const int rocId, int& col, int& row) const {
0115 if (TP_CHECK_LIMITS) {
0116 if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
0117 std::cout << "PixelIndices: wrong index " << colROC << " " << rowROC << std::endl;
0118 return -1;
0119 }
0120 }
0121
0122
0123 if (rocId >= 0 && rocId < 8) {
0124 row = 159 - rowROC;
0125
0126 col = (8 - rocId) * ROCSizeInY - colROC - 1;
0127 } else if (rocId >= 8 && rocId < 16) {
0128 row = rowROC;
0129
0130 col = (rocId - 8) * ROCSizeInY + colROC;
0131 } else {
0132 std::cout << "PixelIndices: wrong ROC ID " << rocId << std::endl;
0133 return -1;
0134 }
0135 if (TP_CHECK_LIMITS) {
0136 if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
0137 std::cout << "PixelIndices: wrong index " << col << " " << row << std::endl;
0138 return -1;
0139 }
0140 }
0141
0142 return 0;
0143 }
0144
0145
0146
0147
0148
0149 int transformToROC(const int col, const int row, int& rocId, int& colROC, int& rowROC) const {
0150 if (TP_CHECK_LIMITS) {
0151 if (col < 0 || col >= (ROCSizeInY * theChipsInY) || row < 0 || row >= (ROCSizeInX * theChipsInX)) {
0152 std::cout << "PixelIndices: wrong index 3 " << std::endl;
0153 return -1;
0154 }
0155 }
0156
0157
0158 int chipX = row / ROCSizeInX;
0159 int chipY = col / ROCSizeInY;
0160
0161
0162 rocId = rocIndex(chipX, chipY);
0163 if (TP_CHECK_LIMITS && (rocId < 0 || rocId >= 16)) {
0164 std::cout << "PixelIndices: wrong roc index " << rocId << std::endl;
0165 return -1;
0166 }
0167
0168 rowROC = (row % ROCSizeInX);
0169 colROC = (col % ROCSizeInY);
0170
0171 if (rocId < 8) {
0172 colROC = 51 - colROC;
0173 rowROC = 79 - rowROC;
0174 }
0175
0176 if (TP_CHECK_LIMITS) {
0177 if (colROC < 0 || colROC >= ROCSizeInY || rowROC < 0 || rowROC >= ROCSizeInX) {
0178 std::cout << "PixelIndices: wrong index " << colROC << " " << rowROC << std::endl;
0179 return -1;
0180 }
0181 }
0182
0183 return 0;
0184 }
0185
0186
0187
0188
0189 inline static int rocIndex(const int chipX, const int chipY) {
0190 int rocId = -1;
0191 if (TP_CHECK_LIMITS) {
0192 if (chipX < 0 || chipX >= 2 || chipY < 0 || chipY >= 8) {
0193 std::cout << "PixelChipIndices: wrong index " << chipX << " " << chipY << std::endl;
0194 return -1;
0195 }
0196 }
0197 if (chipX == 0)
0198 rocId = chipY + 8;
0199 else if (chipX == 1)
0200 rocId = 7 - chipY;
0201
0202 if (TP_CHECK_LIMITS) {
0203 if (rocId < 0 || rocId >= (maxROCsInX * maxROCsInY)) {
0204 std::cout << "PixelIndices: Error in ROC index " << rocId << std::endl;
0205 return -1;
0206 }
0207 }
0208 return rocId;
0209 }
0210
0211
0212
0213 inline static int DColumn(const int colROC) {
0214 int dColumnId = (colROC) / 2;
0215 if (TP_CHECK_LIMITS) {
0216 if (dColumnId < 0 || dColumnId >= 26) {
0217 std::cout << "PixelIndices: wrong dcol index " << dColumnId << " " << colROC << std::endl;
0218 return -1;
0219 }
0220 }
0221 return dColumnId;
0222 }
0223
0224
0225
0226 inline static int DColumnInModule(const int dcol, const int chipIndex) {
0227 int dcolInMod = dcol + chipIndex * 26;
0228 return dcolInMod;
0229 }
0230
0231
0232
0233 inline static int pixelToChannelROC(const int rowROC, const int colROC) {
0234 return (rowROC << 6) | colROC;
0235 }
0236 inline static std::pair<int, int> channelToPixelROC(const int chan) {
0237 int rowROC = (chan >> 6) & 0x7F;
0238 int colROC = chan & 0x3F;
0239 return std::pair<int, int>(rowROC, colROC);
0240 }
0241
0242
0243 private:
0244 int theColsInDet;
0245 int theRowsInDet;
0246 int theChipsInX;
0247 int theChipsInY;
0248 };
0249
0250 #endif