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  iybin0 = (iybin % 54); // 0-53
61  numROC = iybin / 54; // 0-7
62 
63  if (iybin0 == 53) { // inside big pixel
64  iybin0 = 51;
65  fractionY = (fractionY + 1.) / 2.;
66  } else if (iybin0 == 52) { // inside big pixel
67  iybin0 = 51;
68  fractionY = fractionY / 2.;
69  } else if (iybin0 > 1) { // inside normal pixel
70  iybin0 = iybin0 - 1;
71  } else if (iybin0 == 1) { // inside big pixel
72  iybin0 = 0;
73  fractionY = (fractionY + 1.) / 2.;
74  } else if (iybin0 == 0) { // inside big pixel
75  iybin0 = 0;
76  fractionY = fractionY / 2.;
77  }
78 
79  mpY = float(numROC * 52. + iybin0) + fractionY;
80 
81 #ifdef EDM_ML_DEBUG
82 
83  if (mpY < 0. || mpY >= 416.) {
84  LogDebug("RectangularPixelTopology") << " bad pix y " << mpY << "\n"
85  << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin
86  << " " << fractionY << " " << iybin0 << " " << numROC;
87  }
88 #endif // EDM_ML_DEBUG
89 
90  // In X
91  float newxbin = (px - m_xoffset) / m_pitchx;
92  int ixbin = int(newxbin);
93  float fractionX = newxbin - ixbin;
94 
95 #ifdef EDM_ML_DEBUG
96 
97  if (ixbin > 161 || ixbin < 0) // ixbin < 0 outside range
98  {
99  LogDebug("RectangularPixelTopology") << " very bad, newbinx " << ixbin << "\n"
100  << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
101  << " " << fractionX;
102  }
103 #endif // EDM_ML_DEBUG
104 
105  if (ixbin > 82) { // inside normal pixel, ROC 1
106  ixbin = ixbin - 2;
107  } else if (ixbin == 82) { // inside bin pixel
108  ixbin = 80;
109  fractionX = (fractionX + 1.) / 2.;
110  } else if (ixbin == 81) { // inside big pixel
111  ixbin = 80;
112  fractionX = fractionX / 2.;
113  } else if (ixbin == 80) { // inside bin pixel, ROC 0
114  ixbin = 79;
115  fractionX = (fractionX + 1.) / 2.;
116  } else if (ixbin == 79) { // inside big pixel
117  ixbin = 79;
118  fractionX = fractionX / 2.;
119  }
120 
121  float mpX = float(ixbin) + fractionX;
122 
123 #ifdef EDM_ML_DEBUG
124 
125  if (mpX < 0. || mpX >= 160.) {
126  LogDebug("RectangularPixelTopology") << " bad pix x " << mpX << "\n"
127  << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
128  << " " << fractionX;
129  }
130 #endif // EDM_ML_DEBUG
131 
132  return std::pair<float, float>(mpX, mpY);
133 }
134 
135 //----------------------------------------------------------------------
136 // Topology interface, go from Masurement to Local corrdinates
137 // pixel coordinates (mp) -> cm (LocalPoint)
139  float mpy = mp.y(); // measurements
140  float mpx = mp.x();
141 
142 #ifdef EDM_ML_DEBUG
143 #define EPS 0
144  // check limits
145  std::ostringstream debugstr;
146 
147  if (mpy < 0.) {
148  debugstr << " wrong mp y, fix " << mpy << " " << 0 << "\n";
149  mpy = 0.;
150  }
151  if (mpy >= m_ncols) {
152  debugstr << " wrong mp y, fix " << mpy << " " << m_ncols << "\n";
153  mpy = float(m_ncols) - EPS; // EPS is a small number
154  }
155  if (mpx < 0.) {
156  debugstr << " wrong mp x, fix " << mpx << " " << 0 << "\n";
157  mpx = 0.;
158  }
159  if (mpx >= m_nrows) {
160  debugstr << " wrong mp x, fix " << mpx << " " << m_nrows << "\n";
161  mpx = float(m_nrows) - EPS; // EPS is a small number
162  }
163  if (!debugstr.str().empty())
164  LogDebug("RectangularPixelTopology") << debugstr.str();
165 #endif // EDM_ML_DEBUG
166 
167  float lpY = localY(mpy);
168  float lpX = localX(mpx);
169 
170  // Return it as a LocalPoint
171  return LocalPoint(lpX, lpY);
172 }
173 
174 //--------------------------------------------------------------------
175 //
176 // measuremet to local transformation for X coordinate
177 // X coordinate is in the ROC row number direction
178 float RectangularPixelTopology::localX(const float mpx) const {
179  int binoffx = int(mpx); // truncate to int
180  float fractionX = mpx - float(binoffx); // find the fraction
181  float local_pitchx = m_pitchx; // defaultpitch
182 
183  if (binoffx > 80) { // ROC 1 - handles x on edge cluster
184  binoffx = binoffx + 2;
185  } else if (binoffx == 80) { // ROC 1
186  binoffx = binoffx + 1;
187  local_pitchx *= 2;
188  } else if (binoffx == 79) { // ROC 0
189  binoffx = binoffx + 0;
190  local_pitchx *= 2;
191  }
192  // else if (binoffx>=0) { // ROC 0
193  // binoffx=binoffx+0;
194  // }
195 
196 #ifdef EDM_ML_DEBUG
197  if (binoffx < 0) // too small
198  LogDebug("RectangularPixelTopology") << " very bad, binx " << binoffx << "\n"
199  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
200  << m_xoffset;
201 #endif
202 
203  // The final position in local coordinates
204  float lpX = float(binoffx * m_pitchx) + fractionX * local_pitchx + m_xoffset;
205 
206 #ifdef EDM_ML_DEBUG
207 
208  if (lpX < m_xoffset || lpX > (-m_xoffset)) {
209  LogDebug("RectangularPixelTopology") << " bad lp x " << lpX << "\n"
210  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
211  << m_xoffset;
212  }
213 #endif // EDM_ML_DEBUG
214 
215  return lpX;
216 }
217 
218 // measuremet to local transformation for Y coordinate
219 // Y is in the ROC column number direction
220 float RectangularPixelTopology::localY(const float mpy) const {
221  int binoffy = int(mpy); // truncate to int
222  float fractionY = mpy - float(binoffy); // find the fraction
223  float local_pitchy = m_pitchy; // defaultpitch
224 
225  constexpr int bigYIndeces[]{0, 51, 52, 103, 104, 155, 156, 207, 208, 259, 260, 311, 312, 363, 364, 415, 416, 511};
226  auto const j = std::lower_bound(std::begin(bigYIndeces), std::end(bigYIndeces), binoffy);
227  if (*j == binoffy)
228  local_pitchy *= 2;
229  binoffy += (j - bigYIndeces);
230 
231  // The final position in local coordinates
232  float lpY = float(binoffy * m_pitchy) + fractionY * local_pitchy + m_yoffset;
233 
234 #ifdef EDM_ML_DEBUG
235 
236  if (lpY < m_yoffset || lpY > (-m_yoffset)) {
237  LogDebug("RectangularPixelTopology") << " bad lp y " << lpY << "\n"
238  << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " "
239  << m_yoffset;
240  }
241 #endif // EDM_ML_DEBUG
242 
243  return lpY;
244 }
245 
247 // Get hit errors in LocalPoint coordinates (cm)
249  float pitchy = m_pitchy;
250  int binoffy = int(mp.y());
251  if (isItBigPixelInY(binoffy))
252  pitchy = 2. * m_pitchy;
253 
254  float pitchx = m_pitchx;
255  int binoffx = int(mp.x());
256  if (isItBigPixelInX(binoffx))
257  pitchx = 2. * m_pitchx;
258 
259  return LocalError(me.uu() * float(pitchx * pitchx), 0, me.vv() * float(pitchy * pitchy));
260 }
261 
263 // Get errors in pixel pitch units.
265  float pitchy = m_pitchy;
266  float pitchx = m_pitchx;
267 
268  int iybin = int((lp.y() - m_yoffset) / m_pitchy); //get bin for equal picth
269  int iybin0 = iybin % 54; //This is just to avoid many ifs by using the periodicy
270  //quasi bins 0,1,52,53 fall into larger pixels
271  if ((iybin0 <= 1) | (iybin0 >= 52))
272  pitchy = 2.f * m_pitchy;
273 
274  int ixbin = int((lp.x() - m_xoffset) / m_pitchx); //get bin for equal pitch
275  //quasi bins 79,80,81,82 fall into the 2 larger pixels
276  if ((ixbin >= 79) & (ixbin <= 82))
277  pitchx = 2.f * m_pitchx;
278 
279  return MeasurementError(le.xx() / float(pitchx * pitchx), 0, le.yy() / float(pitchy * pitchy));
280 }
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
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
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)