File indexing completed on 2024-04-06 12:02:28
0001 #ifndef CTPPS_PIXELINDICES_H
0002 #define CTPPS_PIXELINDICES_H
0003
0004 #include <iostream>
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 namespace rpixValues {
0056
0057
0058 constexpr int maxROCsInX = 2;
0059
0060 constexpr int maxROCsInY = 3;
0061
0062 constexpr int DColsPerROC = 26;
0063
0064 constexpr int ROCSizeInX = 80;
0065 constexpr int ROCSizeInY = 52;
0066
0067 constexpr int defaultDetSizeInX = 160;
0068 constexpr int defaultDetSizeInY = 156;
0069
0070
0071 constexpr bool CTPPS_CHECK_LIMITS = true;
0072 }
0073
0074 class CTPPSPixelIndices {
0075 public:
0076
0077
0078
0079 CTPPSPixelIndices() : theColsInDet(rpixValues::defaultDetSizeInY), theRowsInDet(rpixValues::defaultDetSizeInX) {
0080 theChipsInX = theRowsInDet / rpixValues::ROCSizeInX;
0081 theChipsInY = theColsInDet / rpixValues::ROCSizeInY;
0082
0083 if (rpixValues::CTPPS_CHECK_LIMITS) {
0084 if (theChipsInX < 1 || theChipsInX > rpixValues::maxROCsInX)
0085 edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " "
0086 << rpixValues::ROCSizeInX;
0087 if (theChipsInY < 1 || theChipsInY > rpixValues::maxROCsInY)
0088 edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " "
0089 << rpixValues::ROCSizeInY;
0090 }
0091 }
0092
0093 CTPPSPixelIndices(const int colsInDet, const int rowsInDet) : theColsInDet(colsInDet), theRowsInDet(rowsInDet) {
0094 theChipsInX = theRowsInDet / rpixValues::ROCSizeInX;
0095 theChipsInY = theColsInDet / rpixValues::ROCSizeInY;
0096
0097 if (rpixValues::CTPPS_CHECK_LIMITS) {
0098 if (theChipsInX < 1 || theChipsInX > rpixValues::maxROCsInX)
0099 edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInX " << theChipsInX << " " << theRowsInDet << " "
0100 << rpixValues::ROCSizeInX;
0101 if (theChipsInY < 1 || theChipsInY > rpixValues::maxROCsInY)
0102 edm::LogError("RPix") << " CTPPSPixelIndices: Error in ROCsInY " << theChipsInY << " " << theColsInDet << " "
0103 << rpixValues::ROCSizeInY;
0104 }
0105 }
0106
0107 ~CTPPSPixelIndices() {}
0108
0109 inline int numberOfROCsInX(void) { return theChipsInX; }
0110 inline int numberOfROCsInY(void) { return theChipsInY; }
0111
0112 void print(void) const {
0113 edm::LogInfo("RPix") << " Pixel det with " << theChipsInX << " chips in x and " << theChipsInY << " in y ";
0114 edm::LogInfo("RPix") << " Pixel rows " << theRowsInDet << " and columns " << theColsInDet;
0115 edm::LogInfo("RPix") << " Rows in one chip " << rpixValues::ROCSizeInX << " and columns " << rpixValues::ROCSizeInY;
0116 edm::LogInfo("RPix") << " Double columns per ROC " << rpixValues::DColsPerROC;
0117 }
0118
0119
0120
0121
0122
0123
0124
0125
0126 inline static int convertDcolToCol(const int dcol, const int pix, int& colROC, int& rowROC) {
0127 if (rpixValues::CTPPS_CHECK_LIMITS) {
0128 if (dcol < 0 || dcol >= rpixValues::DColsPerROC || pix < 2 || pix > 161) {
0129 edm::LogError("RPix") << "CTPPSPixelIndices: wrong dcol or pix " << dcol << " " << pix;
0130 rowROC = -1;
0131 colROC = -1;
0132 return -1;
0133 }
0134 }
0135
0136
0137 int colEvenOdd = pix % 2;
0138
0139 colROC = dcol * 2 + colEvenOdd;
0140 rowROC = abs(int(pix / 2) - 80);
0141
0142 if (rpixValues::CTPPS_CHECK_LIMITS) {
0143 if (colROC < 0 || colROC >= rpixValues::ROCSizeInY || rowROC < 0 || rowROC >= rpixValues::ROCSizeInX) {
0144 edm::LogError("RPix") << "CTPPSPixelIndices: wrong col or row " << colROC << " " << rowROC << " " << dcol << " "
0145 << pix;
0146 rowROC = -1;
0147 colROC = -1;
0148 return -1;
0149 }
0150 }
0151 return 0;
0152 }
0153
0154
0155
0156
0157
0158
0159
0160 int transformToModule(const int colROC, const int rowROC, const int rocId, int& col, int& row) const {
0161 if (rpixValues::CTPPS_CHECK_LIMITS) {
0162 if (colROC < 0 || colROC >= rpixValues::ROCSizeInY || rowROC < 0 || rowROC >= rpixValues::ROCSizeInX) {
0163 edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << colROC << " " << rowROC;
0164 return -1;
0165 }
0166 }
0167
0168
0169 if (rocId >= 0 && rocId < 3) {
0170 row = 159 - rowROC;
0171
0172 col = (rocId + 1) * rpixValues::ROCSizeInY - colROC - 1;
0173 } else if (rocId >= 3 && rocId < 6) {
0174 row = rowROC;
0175
0176 col = (5 - rocId) * rpixValues::ROCSizeInY + colROC;
0177 } else {
0178 edm::LogError("RPix") << "CTPPSPixelIndices: wrong ROC ID " << rocId;
0179 return -1;
0180 }
0181 if (rpixValues::CTPPS_CHECK_LIMITS) {
0182 if (col < 0 || col >= (rpixValues::ROCSizeInY * theChipsInY) || row < 0 ||
0183 row >= (rpixValues::ROCSizeInX * theChipsInX)) {
0184 edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << col << " " << row;
0185 return -1;
0186 }
0187 }
0188
0189 return 0;
0190 }
0191
0192
0193
0194
0195
0196 int transformToROC(const int col, const int row, int& rocId, int& colROC, int& rowROC) const {
0197 if (rpixValues::CTPPS_CHECK_LIMITS) {
0198 if (col < 0 || col >= (rpixValues::ROCSizeInY * theChipsInY) || row < 0 ||
0199 row >= (rpixValues::ROCSizeInX * theChipsInX)) {
0200 edm::LogError("RPix") << "CTPPSPixelIndices: wrong index 3 ";
0201 return -1;
0202 }
0203 }
0204
0205
0206 int chipX = row / rpixValues::ROCSizeInX;
0207 int chipY = col / rpixValues::ROCSizeInY;
0208
0209
0210 rocId = rocIndex(chipX, chipY);
0211 if (rpixValues::CTPPS_CHECK_LIMITS && (rocId < 0 || rocId >= 6)) {
0212 edm::LogError("RPix") << "CTPPSPixelIndices: wrong roc index " << rocId;
0213 return -1;
0214 }
0215
0216 rowROC = (row % rpixValues::ROCSizeInX);
0217 colROC = (col % rpixValues::ROCSizeInY);
0218
0219 if (rocId < 3) {
0220 colROC = 51 - colROC;
0221 rowROC = 79 - rowROC;
0222 }
0223
0224 if (rpixValues::CTPPS_CHECK_LIMITS) {
0225 if (colROC < 0 || colROC >= rpixValues::ROCSizeInY || rowROC < 0 || rowROC >= rpixValues::ROCSizeInX) {
0226 edm::LogError("RPix") << "CTPPSPixelIndices: wrong index " << colROC << " " << rowROC;
0227 return -1;
0228 }
0229 }
0230
0231 return 0;
0232 }
0233
0234
0235
0236 int getROCId(const int col, const int row) const {
0237 int rocId = -1;
0238
0239 if (rpixValues::CTPPS_CHECK_LIMITS) {
0240 if (col < 0 || col >= (rpixValues::ROCSizeInY * theChipsInY) || row < 0 ||
0241 row >= (rpixValues::ROCSizeInX * theChipsInX)) {
0242 edm::LogError("RPix") << "CTPPSPixelIndices: wrong index ";
0243 return -1;
0244 }
0245 }
0246
0247
0248 int chipX = row / rpixValues::ROCSizeInX;
0249 int chipY = col / rpixValues::ROCSizeInY;
0250
0251
0252 rocId = rocIndex(chipX, chipY);
0253 if (rpixValues::CTPPS_CHECK_LIMITS && (rocId < 0 || rocId >= 6)) {
0254 edm::LogError("RPix") << "CTPPSPixelIndices: wrong roc index " << rocId;
0255 return -1;
0256 }
0257
0258 return rocId;
0259 }
0260
0261
0262 bool isOnEdge(const int col, const int row) const {
0263 if (col == 0 || row == 0 || col == (rpixValues::defaultDetSizeInY - 1) ||
0264 row == (rpixValues::defaultDetSizeInX - 1))
0265 return true;
0266 return false;
0267 }
0268
0269
0270
0271
0272
0273 inline static int rocIndex(const int chipX, const int chipY) {
0274 int rocId = -1;
0275 if (rpixValues::CTPPS_CHECK_LIMITS) {
0276 if (chipX < 0 || chipX >= 2 || chipY < 0 || chipY >= 3) {
0277 edm::LogError("RPix") << "PixelChipIndices: wrong index " << chipX << " " << chipY;
0278 return -1;
0279 }
0280 }
0281 if (chipX == 0)
0282 rocId = 5 - chipY;
0283 else if (chipX == 1)
0284 rocId = chipY;
0285
0286 if (rpixValues::CTPPS_CHECK_LIMITS) {
0287 if (rocId < 0 || rocId >= (rpixValues::maxROCsInX * rpixValues::maxROCsInY)) {
0288 edm::LogError("RPix") << "CTPPSPixelIndices: Error in ROC index " << rocId;
0289 return -1;
0290 }
0291 }
0292 return rocId;
0293 }
0294
0295
0296
0297 inline static int DColumn(const int colROC) {
0298 int dColumnId = (colROC) / 2;
0299 if (rpixValues::CTPPS_CHECK_LIMITS) {
0300 if (dColumnId < 0 || dColumnId >= 26) {
0301 edm::LogError("RPix") << "CTPPSPixelIndices: wrong dcol index " << dColumnId << " " << colROC;
0302 return -1;
0303 }
0304 }
0305 return dColumnId;
0306 }
0307
0308
0309
0310 inline static int DColumnInModule(const int dcol, const int chipIndex) {
0311 int dcolInMod = dcol + chipIndex * 26;
0312 return dcolInMod;
0313 }
0314
0315
0316
0317 inline static int pixelToChannelROC(const int rowROC, const int colROC) {
0318 return (rowROC << 6) | colROC;
0319 }
0320 inline static std::pair<int, int> channelToPixelROC(const int chan) {
0321 int rowROC = (chan >> 6) & 0x7F;
0322 int colROC = chan & 0x3F;
0323 return std::pair<int, int>(rowROC, colROC);
0324 }
0325
0326 inline int getDefaultRowDetSize() const { return rpixValues::defaultDetSizeInX; }
0327 inline int getDefaultColDetSize() const { return rpixValues::defaultDetSizeInY; }
0328
0329
0330 private:
0331 int theColsInDet;
0332 int theRowsInDet;
0333 int theChipsInX;
0334 int theChipsInY;
0335 };
0336
0337 #endif