test
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>
15 {
16  // check limits
17  float py = p.y();
18  float px = p.x();
19 
20 #ifdef EDM_ML_DEBUG
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 
27  std::ostringstream debugstr;
28  debugstr << "py = " << py << ", m_yoffset = " << m_yoffset
29  << "px = " << px << ", m_xoffset = " << m_xoffset << "\n";
30 
31  if( py < m_yoffset ) // m_yoffset is negative
32  {
33  debugstr << " wrong lp y " << py << " " << m_yoffset << "\n";
34  py = m_yoffset + EPSCM; // make sure it is in, add an EPS in cm
35  }
36  if( py>-m_yoffset )
37  {
38  debugstr << " wrong lp y " << py << " " << -m_yoffset << "\n";
39  py = -m_yoffset - EPSCM;
40  }
41  if( px<m_xoffset ) // m_xoffset is negative
42  {
43  debugstr << " wrong lp x " << px << " " << m_xoffset << "\n";
44  px = m_xoffset + EPSCM;
45  }
46  if( px>-m_xoffset )
47  {
48  debugstr << " wrong lp x " << px << " " << -m_xoffset << "\n";
49  px = -m_xoffset - EPSCM;
50  }
51 
52  if( !debugstr.str().empty())
53  LogDebug( "RectangularPixelTopology" ) << debugstr.str();
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)
172 {
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  {
183  debugstr << " wrong mp y, fix " << mpy << " " << 0 << "\n";
184  mpy = 0.;
185  }
186  if( mpy >= m_ncols)
187  {
188  debugstr << " wrong mp y, fix " << mpy << " " << m_ncols << "\n";
189  mpy = float(m_ncols) - EPS; // EPS is a small number
190  }
191  if( mpx < 0.)
192  {
193  debugstr << " wrong mp x, fix " << mpx << " " << 0 << "\n";
194  mpx = 0.;
195  }
196  if( mpx >= m_nrows )
197  {
198  debugstr << " wrong mp x, fix " << mpx << " " << m_nrows << "\n";
199  mpx = float(m_nrows) - EPS; // EPS is a small number
200  }
201  if(! debugstr.str().empty())
202  LogDebug("RectangularPixelTopology") << debugstr.str();
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 
224 #ifdef EDM_ML_DEBUG
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 #endif
232  } else {
233  if (binoffx>80) { // ROC 1 - handles x on edge cluster
234  binoffx=binoffx+2;
235  } else if (binoffx==80) { // ROC 1
236  binoffx=binoffx+1;
237  local_pitchx *= 2;
238  } else if (binoffx==79) { // ROC 0
239  binoffx=binoffx+0;
240  local_pitchx *= 2;
241  }
242  // else if (binoffx>=0) { // ROC 0
243  // binoffx=binoffx+0;
244  // }
245 
246 #ifdef EDM_ML_DEBUG
247  if (binoffx<0) // too small
248  LogDebug("RectangularPixelTopology") << " very bad, binx " << binoffx << "\n"
249  << mpx << " " << binoffx << " "
250  << fractionX << " " << local_pitchx << " " << m_xoffset;
251 #endif
252  }
253 
254  // The final position in local coordinates
255  float lpX = float( binoffx * m_pitchx ) + fractionX * local_pitchx + m_xoffset;
256 
257 #ifdef EDM_ML_DEBUG
258 
259  if( lpX < m_xoffset || lpX > ( -m_xoffset ))
260  {
261  LogDebug("RectangularPixelTopology") << " bad lp x " << lpX << "\n"
262  << mpx << " " << binoffx << " "
263  << fractionX << " " << local_pitchx << " " << m_xoffset;
264  }
265 #endif // EDM_ML_DEBUG
266 
267  return lpX;
268 }
269 
270 // measuremet to local transformation for Y coordinate
271 // Y is in the ROC column number direction
272 float
273 RectangularPixelTopology::localY( const float mpy ) const
274 {
275  int binoffy = int( mpy ); // truncate to int
276  float fractionY = mpy - float(binoffy); // find the fraction
277  float local_pitchy = m_pitchy; // defaultpitch
278 
280  #ifdef EDM_ML_DEBUG
281  if( binoffy > m_ROCS_Y * m_COLS_PER_ROC ) // too large
282  {
283  LogDebug( "RectangularPixelTopology" ) << " very bad, biny " << binoffy << "\n"
284  << mpy << " " << binoffy << " " << fractionY
285  << " " << local_pitchy << " " << m_yoffset;
286  }
287 #endif
288  } else { // 415 is last big pixel, 416 and above do not exists!
289  constexpr int bigYIndeces[]{0,51,52,103,104,155,156,207,208,259,260,311,312,363,364,415,416,511};
290  auto const j = std::lower_bound(std::begin(bigYIndeces),std::end(bigYIndeces),binoffy);
291  if (*j==binoffy) local_pitchy *= 2 ;
292  binoffy += (j-bigYIndeces);
293  }
294 
295  // The final position in local coordinates
296  float lpY = float(binoffy*m_pitchy) + fractionY*local_pitchy + m_yoffset;
297 
298 #ifdef EDM_ML_DEBUG
299 
300  if( lpY < m_yoffset || lpY > ( -m_yoffset ))
301  {
302  LogDebug( "RectangularPixelTopology" ) << " bad lp y " << lpY << "\n"
303  << mpy << " " << binoffy << " "
304  << fractionY << " " << local_pitchy << " " << m_yoffset;
305  }
306 #endif // EDM_ML_DEBUG
307 
308  return lpY;
309 }
310 
312 // Get hit errors in LocalPoint coordinates (cm)
315  const MeasurementError& me ) const
316 {
317  float pitchy=m_pitchy;
318  int binoffy=int(mp.y());
319  if( isItBigPixelInY(binoffy) )pitchy = 2.*m_pitchy;
320 
321  float pitchx=m_pitchx;
322  int binoffx=int(mp.x());
323  if( isItBigPixelInX(binoffx) )pitchx = 2.*m_pitchx;
324 
325  return LocalError( me.uu()*float(pitchx*pitchx), 0,
326  me.vv()*float(pitchy*pitchy));
327 }
328 
330 // Get errors in pixel pitch units.
333  const LocalError& le ) const
334 {
335  float pitchy=m_pitchy;
336  float pitchx=m_pitchx;
337 
338  if likely( !m_upgradeGeometry ) {
339  int iybin = int( (lp.y() - m_yoffset)/m_pitchy ); //get bin for equal picth
340  int iybin0 = iybin%54; //This is just to avoid many ifs by using the periodicy
341  //quasi bins 0,1,52,53 fall into larger pixels
342  if( (iybin0<=1) | (iybin0>=52) )
343  pitchy = 2.f * m_pitchy;
344 
345  int ixbin = int( (lp.x() - m_xoffset)/m_pitchx ); //get bin for equal pitch
346  //quasi bins 79,80,81,82 fall into the 2 larger pixels
347  if( (ixbin>=79) & (ixbin<=82) ) pitchx = 2.f * m_pitchx;
348  }
349 
350  return MeasurementError( le.xx()/float(pitchx*pitchx), 0,
351  le.yy()/float(pitchy*pitchy));
352 }
353 
#define LogDebug(id)
float xx() const
Definition: LocalError.h:24
float vv() const
T y() const
Definition: PV2DBase.h:46
virtual float localY(const float mpY) const
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const
#define EPS
virtual bool isItBigPixelInY(const int iybin) const
T y() const
Definition: PV3DBase.h:63
#define constexpr
#define unlikely(x)
#define likely(x)
float yy() const
Definition: LocalError.h:26
float uu() const
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:37
virtual LocalError localError(const MeasurementPoint &, const MeasurementError &) const
virtual LocalPoint localPosition(const MeasurementPoint &mp) const
virtual float localX(const float mpX) const
#define begin
Definition: vmac.h:30
virtual std::pair< float, float > pixel(const LocalPoint &p) const
virtual bool isItBigPixelInX(const int ixbin) const
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
T x() const
Definition: PV2DBase.h:45
T x() const
Definition: PV3DBase.h:62