File indexing completed on 2024-04-06 12:15:16
0001 #include "Geometry/MTDGeometryBuilder/interface/RectangularMTDTopology.h"
0002
0003
0004
0005
0006 std::pair<float, float> RectangularMTDTopology::pixel(const LocalPoint& p) const {
0007
0008 float py = p.y();
0009 float px = p.x();
0010
0011
0012 float newybin = (py - m_yoffset) / m_pitchy;
0013
0014 float newxbin = (px - m_xoffset) / m_pitchx;
0015
0016 return std::pair<float, float>(newxbin, newybin);
0017 }
0018
0019
0020 std::pair<int, int> RectangularMTDTopology::pixelIndex(const LocalPoint& p) const {
0021 const auto& thepixel = pixel(p);
0022 bool fail(false);
0023
0024 static constexpr float tol = 5e-5f;
0025
0026 int row = static_cast<int>(thepixel.first);
0027 if (row >= m_nrows) {
0028 fail = (p.x() - m_pitchx * m_nrows > tol);
0029 if (!fail) {
0030 row--;
0031 }
0032 }
0033 int col = static_cast<int>(thepixel.second);
0034 if (col >= m_ncols) {
0035 fail = (p.y() - m_pitchy * m_ncols > tol);
0036 if (!fail) {
0037 col--;
0038 }
0039 }
0040 if (fail) {
0041 throw cms::Exception("RectangularMTDTopology")
0042 << "Incorrect pixel id! r/c " << std::fixed << std::setw(2) << row << " / " << std::fixed << std::setw(2) << col
0043 << " with max " << std::fixed << std::setw(2) << m_nrows << " / " << std::fixed << std::setw(2) << m_ncols
0044 << " for LocalPoint " << std::fixed << std::setw(8) << std::setprecision(4) << p.x() << " , " << std::fixed
0045 << std::setw(8) << std::setprecision(4) << p.y() << " pixel " << std::fixed << std::setw(8)
0046 << std::setprecision(4) << thepixel.first << " , " << std::fixed << std::setw(8) << std::setprecision(4)
0047 << thepixel.second << " deltas " << p.x() - m_pitchx * m_nrows << " , " << p.y() - m_pitchy * m_ncols;
0048 }
0049
0050 return std::pair<int, int>(row, col);
0051 }
0052
0053
0054 bool RectangularMTDTopology::isInPixel(const LocalPoint& p) const {
0055 bool isInside = true;
0056 const auto& thepixel = pixel(p);
0057 const int ixbin = static_cast<int>(thepixel.first);
0058 const int iybin = static_cast<int>(thepixel.second);
0059 const float fractionX = thepixel.first - ixbin;
0060 const float fractionY = thepixel.second - iybin;
0061 if ((fractionX > 1.0 - m_GAPxInterpadFrac || fractionX < m_GAPxInterpadFrac) ||
0062 (ixbin == 0 && fractionX < m_GAPxBorderFrac) || (ixbin == m_nrows - 1 && fractionX > 1.0 - m_GAPxBorderFrac)) {
0063 isInside = false;
0064 }
0065 if ((fractionY > 1.0 - m_GAPyInterpadFrac || fractionY < m_GAPyInterpadFrac) ||
0066 (iybin == 0 && fractionY < m_GAPyBorderFrac) || (iybin == m_ncols - 1 && fractionY > 1.0 - m_GAPyBorderFrac)) {
0067 isInside = false;
0068 }
0069 return isInside;
0070 }
0071
0072
0073
0074
0075 LocalPoint RectangularMTDTopology::localPosition(const MeasurementPoint& mp) const {
0076 float mpy = mp.y();
0077 float mpx = mp.x();
0078
0079 float lpY = localY(mpy);
0080 float lpX = localX(mpx);
0081
0082
0083 return LocalPoint(lpX, lpY);
0084 }
0085
0086
0087
0088
0089 float RectangularMTDTopology::localX(const float mpx) const {
0090
0091 float lpX = (mpx + 0.5f) * m_pitchx + m_xoffset;
0092
0093 return lpX;
0094 }
0095
0096 float RectangularMTDTopology::localY(const float mpy) const {
0097
0098 float lpY = (mpy + 0.5f) * m_pitchy + m_yoffset;
0099
0100 return lpY;
0101 }
0102
0103
0104
0105 LocalError RectangularMTDTopology::localError(const MeasurementPoint& mp, const MeasurementError& me) const {
0106 return LocalError(me.uu() * float(m_pitchx * m_pitchx), 0, me.vv() * float(m_pitchy * m_pitchy));
0107 }
0108
0109
0110
0111 MeasurementError RectangularMTDTopology::measurementError(const LocalPoint& lp, const LocalError& le) const {
0112 return MeasurementError(le.xx() / float(m_pitchx * m_pitchx), 0, le.yy() / float(m_pitchy * m_pitchy));
0113 }