CMS 3D CMS Logo

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