Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:05:24

0001 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
0002 
0003 /**
0004    * Topology for rectangular pixel detector with BIG pixels.
0005    */
0006 // Modified for the large pixles.
0007 // Danek Kotlinski & Michele Pioppi, 3/06.
0008 // See documentation in the include file.
0009 
0010 //--------------------------------------------------------------------
0011 // PixelTopology interface.
0012 // Transform LocalPoint in cm to measurement in pitch units.
0013 std::pair<float, float> RectangularPixelTopology::pixel(const LocalPoint& p) const {
0014   // check limits
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   // This will catch points which are outside the active sensor area.
0022   // In the digitizer during the early induce_signal phase non valid
0023   // location are passed here. They are cleaned later.
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)  // m_yoffset is negative
0029   {
0030     debugstr << " wrong lp y " << py << " " << m_yoffset << "\n";
0031     py = m_yoffset + EPSCM;  // make sure it is in, add an EPS in cm
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)  // m_xoffset is negative
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  // EDM_ML_DEBUG
0050 
0051   float newybin = (py - m_yoffset) / m_pitchy;
0052   int iybin = int(newybin);
0053   float fractionY = newybin - iybin;
0054 
0055   // Normalize it all to 1 ROC
0056   int iybin0 = 0;
0057   int numROC = 0;
0058   float mpY = 0.;
0059 
0060   if (m_upgradeGeometry) {
0061     iybin0 = (iybin % m_COLS_PER_ROC);  // 0-51
0062     numROC = iybin / m_COLS_PER_ROC;    // 0-7
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  // EDM_ML_DEBUG
0073 
0074   } else {
0075     iybin0 = (iybin % 54);  // 0-53
0076     numROC = iybin / 54;    // 0-7
0077 
0078     if (iybin0 == 53) {  // inside big pixel
0079       iybin0 = 51;
0080       fractionY = (fractionY + 1.) / 2.;
0081     } else if (iybin0 == 52) {  // inside big pixel
0082       iybin0 = 51;
0083       fractionY = fractionY / 2.;
0084     } else if (iybin0 > 1) {  // inside normal pixel
0085       iybin0 = iybin0 - 1;
0086     } else if (iybin0 == 1) {  // inside big pixel
0087       iybin0 = 0;
0088       fractionY = (fractionY + 1.) / 2.;
0089     } else if (iybin0 == 0) {  // inside big pixel
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  // EDM_ML_DEBUG
0105 
0106   // In X
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)  //  ixbin < 0 outside range
0114   {
0115     LogDebug("RectangularPixelTopology") << " very bad, newbinx " << ixbin << "\n"
0116                                          << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
0117                                          << " " << fractionX;
0118   }
0119 #endif  // EDM_ML_DEBUG
0120 
0121   if (!m_upgradeGeometry) {
0122     if (ixbin > 82) {  // inside normal pixel, ROC 1
0123       ixbin = ixbin - 2;
0124     } else if (ixbin == 82) {  // inside bin pixel
0125       ixbin = 80;
0126       fractionX = (fractionX + 1.) / 2.;
0127     } else if (ixbin == 81) {  // inside big pixel
0128       ixbin = 80;
0129       fractionX = fractionX / 2.;
0130     } else if (ixbin == 80) {  // inside bin pixel, ROC 0
0131       ixbin = 79;
0132       fractionX = (fractionX + 1.) / 2.;
0133     } else if (ixbin == 79) {  // inside big pixel
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  // EDM_ML_DEBUG
0149 
0150   return std::pair<float, float>(mpX, mpY);
0151 }
0152 
0153 //----------------------------------------------------------------------
0154 // Topology interface, go from Masurement to Local corrdinates
0155 // pixel coordinates (mp) -> cm (LocalPoint)
0156 LocalPoint RectangularPixelTopology::localPosition(const MeasurementPoint& mp) const {
0157   float mpy = mp.y();  // measurements
0158   float mpx = mp.x();
0159 
0160 #ifdef EDM_ML_DEBUG
0161 #define EPS 0
0162   // check limits
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;  // EPS is a small number
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;  // EPS is a small number
0180   }
0181   if (!debugstr.str().empty())
0182     LogDebug("RectangularPixelTopology") << debugstr.str();
0183 #endif  // EDM_ML_DEBUG
0184 
0185   float lpY = localY(mpy);
0186   float lpX = localX(mpx);
0187 
0188   // Return it as a LocalPoint
0189   return LocalPoint(lpX, lpY);
0190 }
0191 
0192 //--------------------------------------------------------------------
0193 //
0194 // measuremet to local transformation for X coordinate
0195 // X coordinate is in the ROC row number direction
0196 float RectangularPixelTopology::localX(const float mpx) const {
0197   int binoffx = int(mpx);                  // truncate to int
0198   float fractionX = mpx - float(binoffx);  // find the fraction
0199   float local_pitchx = m_pitchx;           // defaultpitch
0200 
0201   if UNLIKELY (m_upgradeGeometry) {
0202 #ifdef EDM_ML_DEBUG
0203     if (binoffx > m_ROWS_PER_ROC * m_ROCS_X)  // too large
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) {  // ROC 1 - handles x on edge cluster
0212       binoffx = binoffx + 2;
0213     } else if (binoffx == 80) {  // ROC 1
0214       binoffx = binoffx + 1;
0215       local_pitchx *= 2;
0216     } else if (binoffx == 79) {  // ROC 0
0217       binoffx = binoffx + 0;
0218       local_pitchx *= 2;
0219     }
0220     // else if (binoffx>=0) {       // ROC 0
0221     //  binoffx=binoffx+0;
0222     // }
0223 
0224 #ifdef EDM_ML_DEBUG
0225     if (binoffx < 0)  // too small
0226       LogDebug("RectangularPixelTopology")
0227           << " very bad, binx " << binoffx << "\n"
0228           << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset;
0229 #endif
0230   }
0231 
0232   // The final position in local coordinates
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  // EDM_ML_DEBUG
0243 
0244   return lpX;
0245 }
0246 
0247 // measuremet to local transformation for Y coordinate
0248 // Y is in the ROC column number direction
0249 float RectangularPixelTopology::localY(const float mpy) const {
0250   int binoffy = int(mpy);                  // truncate to int
0251   float fractionY = mpy - float(binoffy);  // find the fraction
0252   float local_pitchy = m_pitchy;           // defaultpitch
0253 
0254   if UNLIKELY (m_upgradeGeometry) {
0255 #ifdef EDM_ML_DEBUG
0256     if (binoffy > m_ROCS_Y * m_COLS_PER_ROC)  // too large
0257     {
0258       LogDebug("RectangularPixelTopology")
0259           << " very bad, biny " << binoffy << "\n"
0260           << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " " << m_yoffset;
0261     }
0262 #endif
0263   } else {  // 415 is last big pixel, 416 and above do not exists!
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   // The final position in local coordinates
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  // EDM_ML_DEBUG
0282 
0283   return lpY;
0284 }
0285 
0286 ///////////////////////////////////////////////////////////////////
0287 // Get hit errors in LocalPoint coordinates (cm)
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 // Get errors in pixel pitch units.
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);  //get bin for equal picth
0310     int iybin0 = iybin % 54;                           //This is just to avoid many ifs by using the periodicy
0311     //quasi bins 0,1,52,53 fall into larger pixels
0312     if ((iybin0 <= 1) | (iybin0 >= 52))
0313       pitchy = 2.f * m_pitchy;
0314 
0315     int ixbin = int((lp.x() - m_xoffset) / m_pitchx);  //get bin for equal pitch
0316     //quasi bins 79,80,81,82 fall into the 2 larger pixels
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 }