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