Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-29 04:20:37

0001 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelPhase2Topology.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> RectangularPixelPhase2Topology::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("RectangularPixelPhase2Topology") << debugstr.str();
0049 #endif  // EDM_ML_DEBUG
0050 
0051   float newybin = py - m_yoffset;  // m_pitchy;
0052   int iybin = 0;                   //int(newybin);
0053   float fractionY = 0;             //newybin - iybin;
0054   int iybin0 = 0;
0055   float mpY = 0.;
0056 
0057   if ((newybin >= m_pitchy * (m_ncols / 2 - m_BIG_PIX_PER_ROC_Y)) &&
0058       (newybin < (m_pitchy * (m_ncols / 2 - m_BIG_PIX_PER_ROC_Y) +
0059                   m_BIG_PIX_PER_ROC_Y * m_BIG_PIX_PITCH_Y * m_ncols / m_COLS_PER_ROC))) {
0060     iybin = m_ncols / 2 - m_BIG_PIX_PER_ROC_Y;
0061     iybin0 = iybin;
0062     fractionY = (newybin - m_pitchy * (m_ncols / 2 - m_BIG_PIX_PER_ROC_Y)) / m_BIG_PIX_PITCH_Y;
0063   } else if ((newybin >= (m_pitchy * (m_ncols / 2 - m_BIG_PIX_PER_ROC_Y) +
0064                           m_BIG_PIX_PER_ROC_Y * m_BIG_PIX_PITCH_Y * m_ncols / m_COLS_PER_ROC))) {
0065     iybin = int((newybin - (m_pitchy * (m_ncols / 2 - m_BIG_PIX_PER_ROC_Y) +
0066                             m_BIG_PIX_PER_ROC_Y * m_BIG_PIX_PITCH_Y * m_ncols / m_COLS_PER_ROC)) /
0067                 m_pitchy) +
0068             m_ncols / 2 - m_BIG_PIX_PER_ROC_Y + m_BIG_PIX_PER_ROC_Y * m_ncols / m_COLS_PER_ROC;
0069     iybin0 = iybin - m_ncols / 2;
0070     fractionY = (newybin - (m_pitchy * (m_ncols / 2 - m_BIG_PIX_PER_ROC_Y) +
0071                             m_BIG_PIX_PER_ROC_Y * m_BIG_PIX_PITCH_Y * m_ncols / m_COLS_PER_ROC +
0072                             (iybin0 - m_BIG_PIX_PER_ROC_Y) * m_pitchy)) /
0073                 m_pitchy;
0074   } else {
0075     iybin = int(newybin / m_pitchy);
0076     iybin0 = iybin;
0077     fractionY = newybin / m_pitchy - iybin;
0078   }
0079 
0080   mpY = fractionY + iybin;
0081 #ifdef EDM_ML_DEBUG
0082 
0083   if (iybin0 > m_COLS_PER_ROC) {
0084     LogDebug("RectangularPixelPhase2Topology") << " very bad, newbiny " << iybin0 << "\n"
0085                                                << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " "
0086                                                << iybin << " " << fractionY << " " << iybin0 << " " << m_COLS_PER_ROC;
0087   }
0088 #endif  // EDM_ML_DEBUG
0089 
0090 #ifdef EDM_ML_DEBUG
0091 
0092   if (mpY < 0. || mpY >= 2 * m_COLS_PER_ROC) {
0093     LogDebug("RectangularPixelPhase2Topology")
0094         << " bad pix y " << mpY << "\n"
0095         << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin << " " << fractionY << " "
0096         << iybin0 << " " << 2 * m_COLS_PER_ROC;
0097   }
0098 #endif  // EDM_ML_DEBUG
0099 
0100   // In X
0101   float newxbin = (px - m_xoffset);
0102   int ixbin = 0;
0103   float fractionX = 0;
0104   int ixbin0 = 0;
0105   float mpX = 0.;
0106 
0107   if ((newxbin >= m_pitchx * (m_nrows / 2 - m_BIG_PIX_PER_ROC_X)) &&
0108       (newxbin < (m_pitchx * (m_nrows / 2 - m_BIG_PIX_PER_ROC_X) +
0109                   m_BIG_PIX_PER_ROC_X * m_BIG_PIX_PITCH_X * m_nrows / m_ROWS_PER_ROC))) {
0110     ixbin = m_nrows / 2 - m_BIG_PIX_PER_ROC_X;
0111     ixbin0 = ixbin;
0112     fractionX = (newxbin - m_pitchx * (m_nrows / 2 - m_BIG_PIX_PER_ROC_X)) / m_BIG_PIX_PITCH_X;
0113   } else if ((newxbin >= (m_pitchx * (m_nrows / 2 - m_BIG_PIX_PER_ROC_X) +
0114                           m_BIG_PIX_PER_ROC_X * m_BIG_PIX_PITCH_X * m_nrows / m_ROWS_PER_ROC))) {
0115     ixbin = int((newxbin - (m_pitchx * (m_nrows / 2 - m_BIG_PIX_PER_ROC_X) +
0116                             m_BIG_PIX_PER_ROC_X * m_BIG_PIX_PITCH_X * m_nrows / m_ROWS_PER_ROC)) /
0117                 m_pitchx) +
0118             m_nrows / 2 - m_BIG_PIX_PER_ROC_X + m_BIG_PIX_PER_ROC_X * m_nrows / m_ROWS_PER_ROC;
0119     ixbin0 = ixbin - m_nrows / 2;
0120     fractionX = (newxbin - (m_pitchx * (m_nrows / 2 - m_BIG_PIX_PER_ROC_X) +
0121                             m_BIG_PIX_PER_ROC_X * m_BIG_PIX_PITCH_X * m_nrows / m_ROWS_PER_ROC +
0122                             (ixbin0 - m_BIG_PIX_PER_ROC_X) * m_pitchx)) /
0123                 m_pitchx;
0124   } else {
0125     ixbin = int(newxbin / m_pitchx);
0126     ixbin0 = ixbin;
0127     fractionX = newxbin / m_pitchx - ixbin;
0128   }
0129 
0130   mpX = fractionX + ixbin;
0131 
0132 #ifdef EDM_ML_DEBUG
0133 
0134   if (ixbin0 > m_ROWS_PER_ROC || ixbin0 < 0)  //  ixbin < 0 outside range
0135   {
0136     LogDebug("RectangularPixelPhase2Topology")
0137         << " very bad, newbinx " << ixbin << "\n"
0138         << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin << " " << fractionX;
0139   }
0140 #endif  // EDM_ML_DEBUG
0141 
0142 #ifdef EDM_ML_DEBUG
0143 
0144   if (mpX < 0. || mpX >= 2 * m_ROWS_PER_ROC) {
0145     LogDebug("RectangularPixelPhase2Topology")
0146         << " bad pix x " << mpX << "\n"
0147         << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin << " " << fractionX;
0148   }
0149 #endif  // EDM_ML_DEBUG
0150 
0151   return std::pair<float, float>(mpX, mpY);
0152 }
0153 
0154 //----------------------------------------------------------------------
0155 // Topology interface, go from Masurement to Local corrdinates
0156 // pixel coordinates (mp) -> cm (LocalPoint)
0157 LocalPoint RectangularPixelPhase2Topology::localPosition(const MeasurementPoint& mp) const {
0158   float mpy = mp.y();  // measurements
0159   float mpx = mp.x();
0160 
0161 #ifdef EDM_ML_DEBUG
0162 #define EPS 0
0163   // check limits
0164   std::ostringstream debugstr;
0165 
0166   if (mpy < 0.) {
0167     debugstr << " wrong mp y, fix " << mpy << " " << 0 << "\n";
0168     mpy = 0.;
0169   }
0170   if (mpy >= m_ncols) {
0171     debugstr << " wrong mp y, fix " << mpy << " " << m_ncols << "\n";
0172     mpy = float(m_ncols) - EPS;  // EPS is a small number
0173   }
0174   if (mpx < 0.) {
0175     debugstr << " wrong mp x, fix " << mpx << " " << 0 << "\n";
0176     mpx = 0.;
0177   }
0178   if (mpx >= m_nrows) {
0179     debugstr << " wrong mp x, fix " << mpx << " " << m_nrows << "\n";
0180     mpx = float(m_nrows) - EPS;  // EPS is a small number
0181   }
0182   if (!debugstr.str().empty())
0183     LogDebug("RectangularPixelPhase2Topology") << debugstr.str();
0184 #endif  // EDM_ML_DEBUG
0185 
0186   float lpY = localY(mpy);
0187   float lpX = localX(mpx);
0188 
0189   // Return it as a LocalPoint
0190   return LocalPoint(lpX, lpY);
0191 }
0192 
0193 //--------------------------------------------------------------------
0194 //
0195 // measurement to local transformation for X coordinate
0196 // X coordinate is in the ROC row number direction
0197 float RectangularPixelPhase2Topology::localX(const float mpx) const {
0198   int binoffx = int(mpx);                  // truncate to int
0199   float fractionX = mpx - float(binoffx);  // find the fraction
0200   float local_pitchx = m_pitchx;           // defaultpitch
0201   int ispix_secondhalf_x = 0;
0202 
0203   if (binoffx >= (m_nrows / 2 - 2 + 2 * m_nrows / m_ROWS_PER_ROC)) {  // ROC 1 - handles x on edge cluster
0204     binoffx = binoffx - 2 * m_nrows / m_ROWS_PER_ROC;
0205     ispix_secondhalf_x = 1;
0206   } else if (((m_nrows / 2 - 2) <= binoffx) && (binoffx < (m_nrows / 2 - 2 + 2 * m_nrows / m_ROWS_PER_ROC))) {  // ROC 1
0207     binoffx = m_nrows / 2 - 2;
0208     fractionX = mpx - float(m_nrows / 2 - 2);
0209     local_pitchx = m_BIG_PIX_PITCH_X;
0210   }
0211 
0212 #ifdef EDM_ML_DEBUG
0213   if (binoffx > m_ROWS_PER_ROC * m_ROCS_X)  // too large
0214   {
0215     LogDebug("RectangularPixelPhase2Topology")
0216         << " very bad, binx " << binoffx << "\n"
0217         << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset << "\n";
0218   }
0219 #endif
0220 
0221   // The final position in local coordinates
0222   float lpX = float(binoffx * m_pitchx) + fractionX * local_pitchx +
0223               ispix_secondhalf_x * 2 * m_BIG_PIX_PITCH_X * m_nrows / m_ROWS_PER_ROC + m_xoffset;
0224 
0225 #ifdef EDM_ML_DEBUG
0226 
0227   if (lpX < m_xoffset || lpX > (-m_xoffset)) {
0228     LogDebug("RectangularPixelPhase2Topology")
0229         << " bad lp x " << lpX << "\n"
0230         << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset;
0231   }
0232 #endif  // EDM_ML_DEBUG
0233 
0234   return lpX;
0235 }
0236 
0237 // measurement to local transformation for Y coordinate
0238 // Y is in the ROC column number direction
0239 float RectangularPixelPhase2Topology::localY(const float mpy) const {
0240   int binoffy = int(mpy);                  // truncate to int
0241   float fractionY = mpy - float(binoffy);  // find the fraction
0242   float local_pitchy = m_pitchy;           // defaultpitch
0243   int ispix_secondhalf_y = 0;
0244 
0245   if (binoffy >= (m_ncols / 2 - 1 + m_ncols / m_COLS_PER_ROC)) {  // ROC 1 - handles x on edge cluster
0246     binoffy = binoffy - m_ncols / m_COLS_PER_ROC;
0247     ispix_secondhalf_y = 1;
0248   } else if (((m_ncols / 2 - 1) <= binoffy) && (binoffy < (m_ncols / 2 - 1 + m_ncols / m_COLS_PER_ROC))) {  // ROC 1
0249     binoffy = m_ncols / 2 - 1;
0250     fractionY = mpy - float(m_ncols / 2 - 1);
0251     local_pitchy = m_BIG_PIX_PITCH_Y;
0252   }
0253 
0254 #ifdef EDM_ML_DEBUG
0255   if (binoffy > m_ROCS_Y * m_COLS_PER_ROC)  // too large
0256   {
0257     LogDebug("RectangularPixelPhase2Topology")
0258         << " very bad, biny " << binoffy << "\n"
0259         << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " " << m_yoffset;
0260   }
0261 #endif
0262 
0263   // The final position in local coordinates   // using an int to switch first or second half of the module.
0264   float lpY = float(binoffy * m_pitchy) + fractionY * local_pitchy +
0265               ispix_secondhalf_y * m_BIG_PIX_PITCH_Y * m_ncols / m_COLS_PER_ROC + m_yoffset;
0266 
0267 #ifdef EDM_ML_DEBUG
0268 
0269   if (lpY < m_yoffset || lpY > (-m_yoffset)) {
0270     LogDebug("RectangularPixelPhase2Topology")
0271         << " bad lp y " << lpY << "\n"
0272         << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " " << m_yoffset;
0273   }
0274 #endif  // EDM_ML_DEBUG
0275 
0276   return lpY;
0277 }
0278 
0279 ///////////////////////////////////////////////////////////////////
0280 // Get hit errors in LocalPoint coordinates (cm)
0281 LocalError RectangularPixelPhase2Topology::localError(const MeasurementPoint& mp, const MeasurementError& me) const {
0282   float pitchy = m_pitchy;
0283   int binoffy = int(mp.y());
0284   if (isItBigPixelInY(binoffy))
0285     pitchy = 2. * m_pitchy;
0286 
0287   float pitchx = m_pitchx;
0288   int binoffx = int(mp.x());
0289   if (isItBigPixelInX(binoffx))
0290     pitchx = 2. * m_pitchx;
0291 
0292   return LocalError(me.uu() * float(pitchx * pitchx), 0, me.vv() * float(pitchy * pitchy));
0293 }
0294 
0295 /////////////////////////////////////////////////////////////////////
0296 // Get errors in pixel pitch units.
0297 MeasurementError RectangularPixelPhase2Topology::measurementError(const LocalPoint& lp, const LocalError& le) const {
0298   float pitchy = m_pitchy;
0299   float pitchx = m_pitchx;
0300 
0301   return MeasurementError(le.xx() / float(pitchx * pitchx), 0, le.yy() / float(pitchy * pitchy));
0302 }