File indexing completed on 2023-03-17 11:05:24
0001 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 std::pair<float, float> RectangularPixelTopology::pixel(const LocalPoint& p) const {
0014
0015 float py = p.y();
0016 float px = p.x();
0017
0018 #ifdef EDM_ML_DEBUG
0019 #define EPSCM 0
0020 #define EPS 0
0021
0022
0023
0024
0025 std::ostringstream debugstr;
0026 debugstr << "py = " << py << ", m_yoffset = " << m_yoffset << "px = " << px << ", m_xoffset = " << m_xoffset << "\n";
0027
0028 if (py < m_yoffset)
0029 {
0030 debugstr << " wrong lp y " << py << " " << m_yoffset << "\n";
0031 py = m_yoffset + EPSCM;
0032 }
0033 if (py > -m_yoffset) {
0034 debugstr << " wrong lp y " << py << " " << -m_yoffset << "\n";
0035 py = -m_yoffset - EPSCM;
0036 }
0037 if (px < m_xoffset)
0038 {
0039 debugstr << " wrong lp x " << px << " " << m_xoffset << "\n";
0040 px = m_xoffset + EPSCM;
0041 }
0042 if (px > -m_xoffset) {
0043 debugstr << " wrong lp x " << px << " " << -m_xoffset << "\n";
0044 px = -m_xoffset - EPSCM;
0045 }
0046
0047 if (!debugstr.str().empty())
0048 LogDebug("RectangularPixelTopology") << debugstr.str();
0049 #endif
0050
0051 float newybin = (py - m_yoffset) / m_pitchy;
0052 int iybin = int(newybin);
0053 float fractionY = newybin - iybin;
0054
0055
0056 int iybin0 = 0;
0057 int numROC = 0;
0058 float mpY = 0.;
0059
0060 if (m_upgradeGeometry) {
0061 iybin0 = (iybin % m_COLS_PER_ROC);
0062 numROC = iybin / m_COLS_PER_ROC;
0063 mpY = float(numROC * m_COLS_PER_ROC + iybin0) + fractionY;
0064
0065 #ifdef EDM_ML_DEBUG
0066
0067 if (iybin0 > m_COLS_PER_ROC) {
0068 LogDebug("RectangularPixelTopology") << " very bad, newbiny " << iybin0 << "\n"
0069 << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " "
0070 << iybin << " " << fractionY << " " << iybin0 << " " << numROC;
0071 }
0072 #endif
0073
0074 } else {
0075 iybin0 = (iybin % 54);
0076 numROC = iybin / 54;
0077
0078 if (iybin0 == 53) {
0079 iybin0 = 51;
0080 fractionY = (fractionY + 1.) / 2.;
0081 } else if (iybin0 == 52) {
0082 iybin0 = 51;
0083 fractionY = fractionY / 2.;
0084 } else if (iybin0 > 1) {
0085 iybin0 = iybin0 - 1;
0086 } else if (iybin0 == 1) {
0087 iybin0 = 0;
0088 fractionY = (fractionY + 1.) / 2.;
0089 } else if (iybin0 == 0) {
0090 iybin0 = 0;
0091 fractionY = fractionY / 2.;
0092 }
0093
0094 mpY = float(numROC * 52. + iybin0) + fractionY;
0095 }
0096
0097 #ifdef EDM_ML_DEBUG
0098
0099 if (mpY < 0. || mpY >= 416.) {
0100 LogDebug("RectangularPixelTopology") << " bad pix y " << mpY << "\n"
0101 << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin
0102 << " " << fractionY << " " << iybin0 << " " << numROC;
0103 }
0104 #endif
0105
0106
0107 float newxbin = (px - m_xoffset) / m_pitchx;
0108 int ixbin = int(newxbin);
0109 float fractionX = newxbin - ixbin;
0110
0111 #ifdef EDM_ML_DEBUG
0112
0113 if (ixbin > 161 || ixbin < 0)
0114 {
0115 LogDebug("RectangularPixelTopology") << " very bad, newbinx " << ixbin << "\n"
0116 << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
0117 << " " << fractionX;
0118 }
0119 #endif
0120
0121 if (!m_upgradeGeometry) {
0122 if (ixbin > 82) {
0123 ixbin = ixbin - 2;
0124 } else if (ixbin == 82) {
0125 ixbin = 80;
0126 fractionX = (fractionX + 1.) / 2.;
0127 } else if (ixbin == 81) {
0128 ixbin = 80;
0129 fractionX = fractionX / 2.;
0130 } else if (ixbin == 80) {
0131 ixbin = 79;
0132 fractionX = (fractionX + 1.) / 2.;
0133 } else if (ixbin == 79) {
0134 ixbin = 79;
0135 fractionX = fractionX / 2.;
0136 }
0137 }
0138
0139 float mpX = float(ixbin) + fractionX;
0140
0141 #ifdef EDM_ML_DEBUG
0142
0143 if (mpX < 0. || mpX >= 160.) {
0144 LogDebug("RectangularPixelTopology") << " bad pix x " << mpX << "\n"
0145 << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
0146 << " " << fractionX;
0147 }
0148 #endif
0149
0150 return std::pair<float, float>(mpX, mpY);
0151 }
0152
0153
0154
0155
0156 LocalPoint RectangularPixelTopology::localPosition(const MeasurementPoint& mp) const {
0157 float mpy = mp.y();
0158 float mpx = mp.x();
0159
0160 #ifdef EDM_ML_DEBUG
0161 #define EPS 0
0162
0163 std::ostringstream debugstr;
0164
0165 if (mpy < 0.) {
0166 debugstr << " wrong mp y, fix " << mpy << " " << 0 << "\n";
0167 mpy = 0.;
0168 }
0169 if (mpy >= m_ncols) {
0170 debugstr << " wrong mp y, fix " << mpy << " " << m_ncols << "\n";
0171 mpy = float(m_ncols) - EPS;
0172 }
0173 if (mpx < 0.) {
0174 debugstr << " wrong mp x, fix " << mpx << " " << 0 << "\n";
0175 mpx = 0.;
0176 }
0177 if (mpx >= m_nrows) {
0178 debugstr << " wrong mp x, fix " << mpx << " " << m_nrows << "\n";
0179 mpx = float(m_nrows) - EPS;
0180 }
0181 if (!debugstr.str().empty())
0182 LogDebug("RectangularPixelTopology") << debugstr.str();
0183 #endif
0184
0185 float lpY = localY(mpy);
0186 float lpX = localX(mpx);
0187
0188
0189 return LocalPoint(lpX, lpY);
0190 }
0191
0192
0193
0194
0195
0196 float RectangularPixelTopology::localX(const float mpx) const {
0197 int binoffx = int(mpx);
0198 float fractionX = mpx - float(binoffx);
0199 float local_pitchx = m_pitchx;
0200
0201 if UNLIKELY (m_upgradeGeometry) {
0202 #ifdef EDM_ML_DEBUG
0203 if (binoffx > m_ROWS_PER_ROC * m_ROCS_X)
0204 {
0205 LogDebug("RectangularPixelTopology")
0206 << " very bad, binx " << binoffx << "\n"
0207 << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset << "\n";
0208 }
0209 #endif
0210 } else {
0211 if (binoffx > 80) {
0212 binoffx = binoffx + 2;
0213 } else if (binoffx == 80) {
0214 binoffx = binoffx + 1;
0215 local_pitchx *= 2;
0216 } else if (binoffx == 79) {
0217 binoffx = binoffx + 0;
0218 local_pitchx *= 2;
0219 }
0220
0221
0222
0223
0224 #ifdef EDM_ML_DEBUG
0225 if (binoffx < 0)
0226 LogDebug("RectangularPixelTopology")
0227 << " very bad, binx " << binoffx << "\n"
0228 << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset;
0229 #endif
0230 }
0231
0232
0233 float lpX = float(binoffx * m_pitchx) + fractionX * local_pitchx + m_xoffset;
0234
0235 #ifdef EDM_ML_DEBUG
0236
0237 if (lpX < m_xoffset || lpX > (-m_xoffset)) {
0238 LogDebug("RectangularPixelTopology") << " bad lp x " << lpX << "\n"
0239 << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
0240 << m_xoffset;
0241 }
0242 #endif
0243
0244 return lpX;
0245 }
0246
0247
0248
0249 float RectangularPixelTopology::localY(const float mpy) const {
0250 int binoffy = int(mpy);
0251 float fractionY = mpy - float(binoffy);
0252 float local_pitchy = m_pitchy;
0253
0254 if UNLIKELY (m_upgradeGeometry) {
0255 #ifdef EDM_ML_DEBUG
0256 if (binoffy > m_ROCS_Y * m_COLS_PER_ROC)
0257 {
0258 LogDebug("RectangularPixelTopology")
0259 << " very bad, biny " << binoffy << "\n"
0260 << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " " << m_yoffset;
0261 }
0262 #endif
0263 } else {
0264 constexpr int bigYIndeces[]{0, 51, 52, 103, 104, 155, 156, 207, 208, 259, 260, 311, 312, 363, 364, 415, 416, 511};
0265 auto const j = std::lower_bound(std::begin(bigYIndeces), std::end(bigYIndeces), binoffy);
0266 if (*j == binoffy)
0267 local_pitchy *= 2;
0268 binoffy += (j - bigYIndeces);
0269 }
0270
0271
0272 float lpY = float(binoffy * m_pitchy) + fractionY * local_pitchy + m_yoffset;
0273
0274 #ifdef EDM_ML_DEBUG
0275
0276 if (lpY < m_yoffset || lpY > (-m_yoffset)) {
0277 LogDebug("RectangularPixelTopology") << " bad lp y " << lpY << "\n"
0278 << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " "
0279 << m_yoffset;
0280 }
0281 #endif
0282
0283 return lpY;
0284 }
0285
0286
0287
0288 LocalError RectangularPixelTopology::localError(const MeasurementPoint& mp, const MeasurementError& me) const {
0289 float pitchy = m_pitchy;
0290 int binoffy = int(mp.y());
0291 if (isItBigPixelInY(binoffy))
0292 pitchy = 2. * m_pitchy;
0293
0294 float pitchx = m_pitchx;
0295 int binoffx = int(mp.x());
0296 if (isItBigPixelInX(binoffx))
0297 pitchx = 2. * m_pitchx;
0298
0299 return LocalError(me.uu() * float(pitchx * pitchx), 0, me.vv() * float(pitchy * pitchy));
0300 }
0301
0302
0303
0304 MeasurementError RectangularPixelTopology::measurementError(const LocalPoint& lp, const LocalError& le) const {
0305 float pitchy = m_pitchy;
0306 float pitchx = m_pitchx;
0307
0308 if LIKELY (!m_upgradeGeometry) {
0309 int iybin = int((lp.y() - m_yoffset) / m_pitchy);
0310 int iybin0 = iybin % 54;
0311
0312 if ((iybin0 <= 1) | (iybin0 >= 52))
0313 pitchy = 2.f * m_pitchy;
0314
0315 int ixbin = int((lp.x() - m_xoffset) / m_pitchx);
0316
0317 if ((ixbin >= 79) & (ixbin <= 82))
0318 pitchx = 2.f * m_pitchx;
0319 }
0320
0321 return MeasurementError(le.xx() / float(pitchx * pitchx), 0, le.yy() / float(pitchy * pitchy));
0322 }