CMS 3D CMS Logo

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