CMS 3D CMS Logo

RectangularMTDTopology.cc
Go to the documentation of this file.
2 
6 // Modified for the large pixles.
7 // Danek Kotlinski & Michele Pioppi, 3/06.
8 // See documentation in the include file.
9 
10 //--------------------------------------------------------------------
11 // Calculate the edge of the active sensor with respect to the center,
12 // that is simply the half-size.
13 // Take into account large pixels
14 void RectangularMTDTopology::setOffset(const int& BIG_PIX_PER_ROC_X,
15  const int& BIG_PIX_PER_ROC_Y,
16  const int& ROWS_PER_ROC,
17  const int& COLS_PER_ROC) {
18  m_xoffset = -(m_nrows + BIG_PIX_PER_ROC_X * m_nrows / ROWS_PER_ROC) / 2. * m_pitchx;
19  m_yoffset = -(m_ncols + BIG_PIX_PER_ROC_Y * m_ncols / COLS_PER_ROC) / 2. * m_pitchy;
20 
21  LogDebug("RectangularMTDTopology") << "nrows " << m_nrows << ", ncols " << m_ncols << ", pitchx " << m_pitchx
22  << ", pitchy " << m_pitchy << ", xoffset " << m_xoffset << ", yoffset "
23  << m_yoffset << ", BIG_PIX_PER_ROC_X " << BIG_PIX_PER_ROC_X
24  << ", BIG_PIX_PER_ROC_Y " << BIG_PIX_PER_ROC_Y << ", ROWS_PER_ROC " << ROWS_PER_ROC
25  << ", COLS_PER_ROC " << COLS_PER_ROC << ", ROCS_X " << m_ROCS_X << ", ROCS_Y "
26  << m_ROCS_Y << "\nNROWS " << m_ROWS_PER_ROC * m_ROCS_X << ", NCOL "
28 }
29 
30 //--------------------------------------------------------------------
31 // PixelTopology interface.
32 // Transform LocalPoint in cm to measurement in pitch units.
33 std::pair<float, float> RectangularMTDTopology::pixel(const LocalPoint& p) const {
34  // check limits
35  float py = p.y();
36  float px = p.x();
37 
38  LogDebug("RectangularMTDTopology").log([&](auto& debugstr) {
39 #define EPSCM 0
40 #define EPS 0
41  // This will catch points which are outside the active sensor area.
42  // In the digitizer during the early induce_signal phase non valid
43  // location are passed here. They are cleaned later.
44  debugstr << "py = " << py << ", m_yoffset = " << m_yoffset << "px = " << px << ", m_xoffset = " << m_xoffset
45  << "\n";
46 
47  if (py < m_yoffset) // m_yoffset is negative
48  {
49  debugstr << " wrong lp y " << py << " " << m_yoffset << "\n";
50  py = m_yoffset + EPSCM; // make sure it is in, add an EPS in cm
51  }
52  if (py > -m_yoffset) {
53  debugstr << " wrong lp y " << py << " " << -m_yoffset << "\n";
54  py = -m_yoffset - EPSCM;
55  }
56  if (px < m_xoffset) // m_xoffset is negative
57  {
58  debugstr << " wrong lp x " << px << " " << m_xoffset << "\n";
59  px = m_xoffset + EPSCM;
60  }
61  if (px > -m_xoffset) {
62  debugstr << " wrong lp x " << px << " " << -m_xoffset << "\n";
63  px = -m_xoffset - EPSCM;
64  }
65  });
66 
67  float newybin = (py - m_yoffset) / m_pitchy;
68  int iybin = int(newybin);
69  float fractionY = newybin - iybin;
70 
71  // Normalize it all to 1 ROC
72  int iybin0 = 0;
73  int numROC = 0;
74  float mpY = 0.;
75 
76  if (m_upgradeGeometry) {
77  iybin0 = (iybin % m_COLS_PER_ROC); // 0-51
78  numROC = iybin / m_COLS_PER_ROC; // 0-7
79  mpY = float(numROC * m_COLS_PER_ROC + iybin0) + fractionY;
80 
81 #ifdef EDM_ML_DEBUG
82 
83  if (iybin0 > m_COLS_PER_ROC) {
84  LogDebug("RectangularMTDTopology") << " very bad, newbiny " << iybin0 << "\n"
85  << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin
86  << " " << fractionY << " " << iybin0 << " " << numROC;
87  }
88 #endif // EDM_ML_DEBUG
89 
90  } else {
91  iybin0 = (iybin % 54); // 0-53
92  numROC = iybin / 54; // 0-7
93 
94  if (iybin0 == 53) { // inside big pixel
95  iybin0 = 51;
96  fractionY = (fractionY + 1.) / 2.;
97  } else if (iybin0 == 52) { // inside big pixel
98  iybin0 = 51;
99  fractionY = fractionY / 2.;
100  } else if (iybin0 > 1) { // inside normal pixel
101  iybin0 = iybin0 - 1;
102  } else if (iybin0 == 1) { // inside big pixel
103  iybin0 = 0;
104  fractionY = (fractionY + 1.) / 2.;
105  } else if (iybin0 == 0) { // inside big pixel
106  iybin0 = 0;
107  fractionY = fractionY / 2.;
108  }
109 
110  mpY = float(numROC * 52. + iybin0) + fractionY;
111  }
112 
113 #ifdef EDM_ML_DEBUG
114 
115  if (mpY < 0. || mpY >= 416.) {
116  LogDebug("RectangularMTDTopology") << " bad pix y " << mpY << "\n"
117  << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin
118  << " " << fractionY << " " << iybin0 << " " << numROC;
119  }
120 #endif // EDM_ML_DEBUG
121 
122  // In X
123  float newxbin = (px - m_xoffset) / m_pitchx;
124  int ixbin = int(newxbin);
125  float fractionX = newxbin - ixbin;
126 
127 #ifdef EDM_ML_DEBUG
128 
129  if (ixbin > 161 || ixbin < 0) // ixbin < 0 outside range
130  {
131  LogDebug("RectangularMTDTopology") << " very bad, newbinx " << ixbin << "\n"
132  << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
133  << " " << fractionX;
134  }
135 #endif // EDM_ML_DEBUG
136 
137  if (!m_upgradeGeometry) {
138  if (ixbin > 82) { // inside normal pixel, ROC 1
139  ixbin = ixbin - 2;
140  } else if (ixbin == 82) { // inside bin pixel
141  ixbin = 80;
142  fractionX = (fractionX + 1.) / 2.;
143  } else if (ixbin == 81) { // inside big pixel
144  ixbin = 80;
145  fractionX = fractionX / 2.;
146  } else if (ixbin == 80) { // inside bin pixel, ROC 0
147  ixbin = 79;
148  fractionX = (fractionX + 1.) / 2.;
149  } else if (ixbin == 79) { // inside big pixel
150  ixbin = 79;
151  fractionX = fractionX / 2.;
152  }
153  }
154 
155  float mpX = float(ixbin) + fractionX;
156 
157 #ifdef EDM_ML_DEBUG
158 
159  if (mpX < 0. || mpX >= 160.) {
160  LogDebug("RectangularMTDTopology") << " bad pix x " << mpX << "\n"
161  << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
162  << " " << fractionX;
163  }
164 #endif // EDM_ML_DEBUG
165 
166  return std::pair<float, float>(mpX, mpY);
167 }
168 
169 //----------------------------------------------------------------------
170 // Topology interface, go from Measurement to Local corrdinates
171 // pixel coordinates (mp) -> cm (LocalPoint)
173  float mpy = mp.y(); // measurements
174  float mpx = mp.x();
175 
176 #ifdef EDM_ML_DEBUG
177 #define EPS 0
178  // check limits
179  std::ostringstream debugstr;
180 
181  if (mpy < 0.) {
182  debugstr << " wrong mp y, fix " << mpy << " " << 0 << "\n";
183  mpy = 0.;
184  }
185  if (mpy >= m_ncols) {
186  debugstr << " wrong mp y, fix " << mpy << " " << m_ncols << "\n";
187  mpy = float(m_ncols) - EPS; // EPS is a small number
188  }
189  if (mpx < 0.) {
190  debugstr << " wrong mp x, fix " << mpx << " " << 0 << "\n";
191  mpx = 0.;
192  }
193  if (mpx >= m_nrows) {
194  debugstr << " wrong mp x, fix " << mpx << " " << m_nrows << "\n";
195  mpx = float(m_nrows) - EPS; // EPS is a small number
196  }
197  if (!debugstr.str().empty())
198  LogDebug("RectangularMTDTopology") << debugstr.str();
199 #endif // EDM_ML_DEBUG
200 
201  float lpY = localY(mpy);
202  float lpX = localX(mpx);
203 
204  // Return it as a LocalPoint
205  return LocalPoint(lpX, lpY);
206 }
207 
208 //--------------------------------------------------------------------
209 //
210 // measuremet to local transformation for X coordinate
211 // X coordinate is in the ROC row number direction
212 float RectangularMTDTopology::localX(const float mpx) const {
213  int binoffx = int(mpx); // truncate to int
214  float fractionX = mpx - float(binoffx); // find the fraction
215  float local_pitchx = m_pitchx; // defaultpitch
216 
217  if
219 #ifdef EDM_ML_DEBUG
220  if (binoffx > m_ROWS_PER_ROC * m_ROCS_X) // too large
221  {
222  LogDebug("RectangularMTDTopology")
223  << " very bad, binx " << binoffx << "\n"
224  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset << "\n";
225  }
226 #endif
227  }
228  else {
229  if (binoffx > 80) { // ROC 1 - handles x on edge cluster
230  binoffx = binoffx + 2;
231  } else if (binoffx == 80) { // ROC 1
232  binoffx = binoffx + 1;
233  local_pitchx *= 2;
234  } else if (binoffx == 79) { // ROC 0
235  binoffx = binoffx + 0;
236  local_pitchx *= 2;
237  }
238  // else if (binoffx>=0) { // ROC 0
239  // binoffx=binoffx+0;
240  // }
241 
242 #ifdef EDM_ML_DEBUG
243  if (binoffx < 0) // too small
244  LogDebug("RectangularMTDTopology") << " very bad, binx " << binoffx << "\n"
245  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
246  << m_xoffset;
247 #endif
248  }
249 
250  // The final position in local coordinates
251  float lpX = float(binoffx * m_pitchx) + fractionX * local_pitchx + m_xoffset;
252 
253 #ifdef EDM_ML_DEBUG
254 
255  if (lpX < m_xoffset || lpX > (-m_xoffset)) {
256  LogDebug("RectangularMTDTopology") << " bad lp x " << lpX << "\n"
257  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
258  << m_xoffset;
259  }
260 #endif // EDM_ML_DEBUG
261 
262  return lpX;
263 }
264 
265 // measuremet to local transformation for Y coordinate
266 // Y is in the ROC column number direction
267 float RectangularMTDTopology::localY(const float mpy) const {
268  int binoffy = int(mpy); // truncate to int
269  float fractionY = mpy - float(binoffy); // find the fraction
270  float local_pitchy = m_pitchy; // defaultpitch
271 
272  if
274 #ifdef EDM_ML_DEBUG
275  if (binoffy > m_ROCS_Y * m_COLS_PER_ROC) // too large
276  {
277  LogDebug("RectangularMTDTopology")
278  << " very bad, biny " << binoffy << "\n"
279  << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " " << m_yoffset;
280  }
281 #endif
282  }
283  else { // 415 is last big pixel, 416 and above do not exists!
284  constexpr int bigYIndeces[]{0, 51, 52, 103, 104, 155, 156, 207, 208, 259, 260, 311, 312, 363, 364, 415, 416, 511};
285  auto const j = std::lower_bound(std::begin(bigYIndeces), std::end(bigYIndeces), binoffy);
286  if (*j == binoffy)
287  local_pitchy *= 2;
288  binoffy += (j - bigYIndeces);
289  }
290 
291  // The final position in local coordinates
292  float lpY = float(binoffy * m_pitchy) + fractionY * local_pitchy + m_yoffset;
293 
294 #ifdef EDM_ML_DEBUG
295 
296  if (lpY < m_yoffset || lpY > (-m_yoffset)) {
297  LogDebug("RectangularMTDTopology") << " bad lp y " << lpY << "\n"
298  << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " "
299  << m_yoffset;
300  }
301 #endif // EDM_ML_DEBUG
302 
303  return lpY;
304 }
305 
307 // Get hit errors in LocalPoint coordinates (cm)
309  float pitchy = m_pitchy;
310  int binoffy = int(mp.y());
311  if (isItBigPixelInY(binoffy))
312  pitchy = 2. * m_pitchy;
313 
314  float pitchx = m_pitchx;
315  int binoffx = int(mp.x());
316  if (isItBigPixelInX(binoffx))
317  pitchx = 2. * m_pitchx;
318 
319  return LocalError(me.uu() * float(pitchx * pitchx), 0, me.vv() * float(pitchy * pitchy));
320 }
321 
323 // Get errors in pixel pitch units.
325  float pitchy = m_pitchy;
326  float pitchx = m_pitchx;
327 
328  if
330  int iybin = int((lp.y() - m_yoffset) / m_pitchy); //get bin for equal picth
331  int iybin0 = iybin % 54; //This is just to avoid many ifs by using the periodicy
332  //quasi bins 0,1,52,53 fall into larger pixels
333  if ((iybin0 <= 1) | (iybin0 >= 52))
334  pitchy = 2.f * m_pitchy;
335 
336  int ixbin = int((lp.x() - m_xoffset) / m_pitchx); //get bin for equal pitch
337  //quasi bins 79,80,81,82 fall into the 2 larger pixels
338  if ((ixbin >= 79) & (ixbin <= 82))
339  pitchx = 2.f * m_pitchx;
340  }
341 
342  return MeasurementError(le.xx() / float(pitchx * pitchx), 0, le.yy() / float(pitchy * pitchy));
343 }
#define LogDebug(id)
float xx() const
Definition: LocalError.h:22
float vv() const
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T y() const
Definition: PV2DBase.h:44
bool isItBigPixelInX(const int ixbin) const override
float localX(const float mpX) const override
LocalError localError(const MeasurementPoint &, const MeasurementError &) const override
T y() const
Definition: PV3DBase.h:60
#define LIKELY(x)
Definition: Likely.h:20
bool isItBigPixelInY(const int iybin) const override
#define EPS
#define EPSCM
float yy() const
Definition: LocalError.h:24
LocalPoint localPosition(const MeasurementPoint &mp) const override
float uu() const
std::pair< float, float > pixel(const LocalPoint &p) const override
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
void setOffset(const int &BIG_PIX_PER_ROC_X, const int &BIG_PIX_PER_ROC_Y, const int &ROWS_PER_ROC, const int &COLS_PER_ROC)
float localY(const float mpY) const override
MeasurementError measurementError(const LocalPoint &, const LocalError &) const override
#define UNLIKELY(x)
Definition: Likely.h:21
T x() const
Definition: PV2DBase.h:43
T x() const
Definition: PV3DBase.h:59
#define constexpr