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> RectangularPixelTopology::pixel(
14  const LocalPoint& p) const {
15  using std::cout;
16  using std::endl;
17 
18  // check limits
19  float py = p.y();
20  float px = p.x();
21 
22  if(TP_DEBUG) {
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  if( py<m_yoffset ) { // m_yoffset is negative
27  cout<<" wrong lp y "<<py<<" "<<m_yoffset<<endl;
28  py = m_yoffset + EPSCM; // make sure it is in, add an EPS in cm
29  }
30  if( py>-m_yoffset ) {
31  cout<<" wrong lp y "<<py<<" "<<-m_yoffset<<endl;
32  py = -m_yoffset - EPSCM;
33  }
34  if( px<m_xoffset ) { // m_xoffset is negative
35  cout<<" wrong lp x "<<px<<" "<<m_xoffset<<endl;
36  px = m_xoffset + EPSCM;
37  }
38  if( px>-m_xoffset ) {
39  cout<<" wrong lp x "<<px<<" "<<-m_xoffset<<endl;
40  px = -m_xoffset - EPSCM;
41  }
42  } // end TP_DEBUG
43 
44  float newybin=(py - m_yoffset)/m_pitchy;
45  int iybin = int(newybin);
46  float fractionY = newybin - iybin;
47  //if(fractionY<0.) cout<<" fractiony "<<fractionY<<" "<<newybin<<endl;
48 
49  // Normalize it all to 1 ROC
50  int iybin0 = (iybin%54); // 0-53
51  int numROC = iybin/54; // 0-7
52 
53  if (iybin0>53) {
54  if(TP_DEBUG) {
55  cout<<" very bad, newbiny "<<iybin0<<endl;
56  cout<<py<<" "<<m_yoffset<<" "<<m_pitchy<<" "
57  <<newybin<<" "<<iybin<<" "<<fractionY<<" "<<iybin0<<" "
58  <<numROC<<endl;
59  }
60  } else if (iybin0==53) { // inside big pixel
61  iybin0=51;
62  fractionY = (fractionY+1.)/2.;
63  } else if (iybin0==52) { // inside big pixel
64  iybin0=51;
65  fractionY = fractionY/2.;
66  } else if (iybin0>1) { // inside normal pixel
67  iybin0=iybin0-1;
68  } else if (iybin0==1) { // inside big pixel
69  iybin0=0;
70  fractionY = (fractionY+1.)/2.;
71  } else if (iybin0==0) { // inside big pixel
72  iybin0=0;
73  fractionY = fractionY/2.;
74  } else {
75  if(TP_DEBUG) {
76  cout<<" very bad, newbiny "<<newybin<<endl;
77  cout<<py<<" "<<m_yoffset<<" "<<m_pitchy<<" "
78  <<newybin<<" "<<iybin<<" "<<fractionY<<" "
79  <<iybin0<<" "<<numROC<<endl;
80  }
81  }
82  float mpY = float(numROC*52. + iybin0) + fractionY;
83  if(TP_DEBUG && (mpY<0. || mpY>=416.)) {
84  cout<<" bad pix y "<<mpY<<endl;
85  cout<<py<<" "<<m_yoffset<<" "<<m_pitchy<<" "
86  <<newybin<<" "<<iybin<<" "<<fractionY<<" "
87  <<iybin0<<" "<<numROC<<endl;
88  }
89 
90  // In X
91  float newxbin=(px - m_xoffset) / m_pitchx;
92  int ixbin = int(newxbin);
93  float fractionX = newxbin - ixbin;
94  // if(fractionX<0.) {
95  // cout<<" fractionx "<<fractionX<<" "<<newxbin<<" "<<ixbin<<" ";
96  // cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
97  // <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
98  // }
99 
100  if (ixbin>161) {
101  if(TP_DEBUG) {
102  cout<<" very bad, newbinx "<<ixbin<<endl;
103  cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
104  <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
105  }
106  } else if (ixbin>82) { // inside normal pixel, ROC 1
107  ixbin=ixbin-2;
108  } else if (ixbin==82) { // inside bin pixel
109  ixbin=80;
110  fractionX = (fractionX+1.)/2.;
111  } else if (ixbin==81) { // inside big pixel
112  ixbin=80;
113  fractionX = fractionX/2.;
114  } else if (ixbin==80) { // inside bin pixel, ROC 0
115  ixbin=79;
116  fractionX = (fractionX+1.)/2.;
117  } else if (ixbin==79) { // inside big pixel
118  ixbin=79;
119  fractionX = fractionX/2.;
120  } else if (ixbin<0) { // outside range
121  if(TP_DEBUG) {
122  cout<<" very bad, newbinx "<<ixbin<<endl;
123  cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
124  <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
125  }
126  }
127 
128  float mpX = float(ixbin) + fractionX;
129 
130  if(TP_DEBUG && (mpX<0. || mpX>=160.) ) {
131  cout<<" bad pix x "<<mpX<<" "<<endl;
132  cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
133  <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
134  }
135 
136  return std::pair<float,float>(mpX,mpY);
137 }
138 //----------------------------------------------------------------------
139 // Topology interface, go from Masurement to Local corrdinates
140 // pixel coordinates (mp) -> cm (LocalPoint)
142  const MeasurementPoint& mp) const {
143  using std::cout;
144  using std::endl;
145 
146  float mpy = mp.y(); // measurements
147  float mpx = mp.x();
148 
149  // check limits
150  if(TP_DEBUG) {
151  if( mpy<0.) { //
152  cout<<" wrong mp y, fix "<<mpy<<" "
153  <<0<<endl;
154  mpy = 0.;
155  }
156  if( mpy>=m_ncols) {
157  cout<<" wrong mp y, fix "<<mpy<<" "
158  <<m_ncols<<endl;
159  mpy = float(m_ncols) - EPS; // EPS is a small number
160  }
161  if( mpx<0.) { //
162  cout<<" wrong mp x, fix "<<mpx<<" "
163  <<0<<endl;
164  mpx = 0.;
165  }
166  if( mpx>=m_nrows) {
167  cout<<" wrong mp x, fix "<<mpx<<" "
168  <<m_nrows<<endl;
169  mpx = float(m_nrows) - EPS; // EPS is a small number
170  }
171  } // if TP_DEBUG
172 
173 
174  // IF IT WORKS OK REPLACE THE CODE BELOW BY A CALL TO localY()
175  float lpY = localY(mpy);
176 
177 // // Start with Y
178 // int binoffy = int(mpy); // truncate to int
179 // float fractionY = mpy - binoffy; // find the fraction
180 // float local_pitchy = m_pitchy; // defaultpitch
181 // //if(fractionY<0.) cout<<" fractiony m "<<fractionY<<" "<<mpy<<endl;
182 
183 // if (binoffy>415) { // too large
184 // if(TP_DEBUG) {
185 // cout<<" very bad, biny "<<binoffy<<endl;
186 // cout<<mpy<<" "<<binoffy<<" "
187 // <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
188 // }
189 // } else if (binoffy==415) { // ROC 7, last big pixel
190 // binoffy=binoffy+15;
191 // local_pitchy = 2 * m_pitchy;
192 // } else if (binoffy>364) { // ROC 7
193 // binoffy=binoffy+15;
194 // } else if (binoffy==364) { // ROC 7
195 // binoffy=binoffy+14;
196 // local_pitchy = 2 * m_pitchy;
197 
198 // } else if (binoffy==363) { // ROC 6
199 // binoffy=binoffy+13;
200 // local_pitchy = 2 * m_pitchy;
201 // } else if (binoffy>312) { // ROC 6
202 // binoffy=binoffy+13;
203 // } else if (binoffy==312) { // ROC 6
204 // binoffy=binoffy+12;
205 // local_pitchy = 2 * m_pitchy;
206 
207 // } else if (binoffy==311) { // ROC 5
208 // binoffy=binoffy+11;
209 // local_pitchy = 2 * m_pitchy;
210 // } else if (binoffy>260) { // ROC 5
211 // binoffy=binoffy+11;
212 // } else if (binoffy==260) { // ROC 5
213 // binoffy=binoffy+10;
214 // local_pitchy = 2 * m_pitchy;
215 
216 // } else if (binoffy==259) { // ROC 4
217 // binoffy=binoffy+9;
218 // local_pitchy = 2 * m_pitchy;
219 // } else if (binoffy>208) { // ROC 4
220 // binoffy=binoffy+9;
221 // } else if (binoffy==208) { // ROC 4
222 // binoffy=binoffy+8;
223 // local_pitchy = 2 * m_pitchy;
224 
225 // } else if (binoffy==207) { // ROC 3
226 // binoffy=binoffy+7;
227 // local_pitchy = 2 * m_pitchy;
228 // } else if (binoffy>156) { // ROC 3
229 // binoffy=binoffy+7;
230 // } else if (binoffy==156) { // ROC 3
231 // binoffy=binoffy+6;
232 // local_pitchy = 2 * m_pitchy;
233 
234 // } else if (binoffy==155) { // ROC 2
235 // binoffy=binoffy+5;
236 // local_pitchy = 2 * m_pitchy;
237 // } else if (binoffy>104) { // ROC 2
238 // binoffy=binoffy+5;
239 // } else if (binoffy==104) { // ROC 2
240 // binoffy=binoffy+4;
241 // local_pitchy = 2 * m_pitchy;
242 
243 // } else if (binoffy==103) { // ROC 1
244 // binoffy=binoffy+3;
245 // local_pitchy = 2 * m_pitchy;
246 // } else if (binoffy>52) { // ROC 1
247 // binoffy=binoffy+3;
248 // } else if (binoffy==52) { // ROC 1
249 // binoffy=binoffy+2;
250 // local_pitchy = 2 * m_pitchy;
251 
252 // } else if (binoffy==51) { // ROC 0
253 // binoffy=binoffy+1;
254 // local_pitchy = 2 * m_pitchy;
255 // } else if (binoffy>0) { // ROC 0
256 // binoffy=binoffy+1;
257 // } else if (binoffy==0) { // ROC 0
258 // binoffy=binoffy+0;
259 // local_pitchy = 2 * m_pitchy;
260 // } else { // too small
261 // if(TP_DEBUG) {
262 // cout<<" very bad, biny "<<binoffy<<endl;
263 // cout<<mpy<<" "<<binoffy<<" "
264 // <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
265 // }
266 // }
267 
268 // // The final position in local coordinates
269 // float lpY = float(binoffy*m_pitchy) + fractionY*local_pitchy +
270 // m_yoffset;
271 // if(TP_DEBUG && (lpY<m_yoffset || lpY>(-m_yoffset)) ) {
272 // cout<<" bad lp y "<<lpY<<endl;
273 // cout<<mpy<<" "<<binoffy<<" "
274 // <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
275 // }
276 
277 
278  // IF IT WORKS OK REPLACE THE CODE BELOW BY A CALL TO localX()
279  float lpX = localX(mpx);
280 
281 // // Do the X
282 // int binoffx=int(mpx); // truncate to int
283 // float fractionX = mpx - binoffx; // find the fraction
284 // float local_pitchx = m_pitchx; // defaultpitch
285 // //if(fractionX<0.) cout<<" fractionx m "<<fractionX<<" "<<mpx<<endl;
286 
287 // if (binoffx>159) { // too large
288 // if(TP_DEBUG) {
289 // cout<<" very bad, binx "<<binoffx<<endl;
290 // cout<<mpx<<" "<<binoffx<<" "
291 // <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
292 // }
293 // } else if (binoffx>80) { // ROC 1
294 // binoffx=binoffx+2;
295 // } else if (binoffx==80) { // ROC 1
296 // binoffx=binoffx+1;
297 // local_pitchx = 2 * m_pitchx;
298 
299 // } else if (binoffx==79) { // ROC 0
300 // binoffx=binoffx+0;
301 // local_pitchx = 2 * m_pitchx;
302 // } else if (binoffx>=0) { // ROC 0
303 // binoffx=binoffx+0;
304 
305 // } else { // too small
306 // if(TP_DEBUG) {
307 // cout<<" very bad, binx "<<binoffx<<endl;
308 // cout<<mpx<<" "<<binoffx<<" "
309 // <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
310 // }
311 // }
312 
313 // // The final position in local coordinates
314 // float lpX = float(binoffx*m_pitchx) + fractionX*local_pitchx +
315 // m_xoffset;
316 
317 // if(TP_DEBUG && (lpX<m_xoffset || lpX>(-m_xoffset)) ) {
318 // cout<<" bad lp x "<<lpX<<endl;
319 // cout<<mpx<<" "<<binoffx<<" "
320 // <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
321 // }
322 
323  // Return it as a LocalPoint
324  return LocalPoint( lpX, lpY);
325 }
326 //--------------------------------------------------------------------
327 //
328 // measuremet to local transformation for X coordinate
329 // X coordinate is in the ROC row number direction
330 float RectangularPixelTopology::localX(const float mpx) const {
331  using std::cout;
332  using std::endl;
333 
334  int binoffx=int(mpx); // truncate to int
335  float fractionX = mpx - binoffx; // find the fraction
336  float local_pitchx = m_pitchx; // defaultpitch
337  //if(fractionX<0.) cout<<" fractionx m "<<fractionX<<" "<<mpx<<endl;
338 
339  if (binoffx>80) { // ROC 1 - handles x on edge cluster
340  binoffx=binoffx+2;
341  } else if (binoffx==80) { // ROC 1
342  binoffx=binoffx+1;
343  local_pitchx = 2 * m_pitchx;
344 
345  } else if (binoffx==79) { // ROC 0
346  binoffx=binoffx+0;
347  local_pitchx = 2 * m_pitchx;
348  } else if (binoffx>=0) { // ROC 0
349  binoffx=binoffx+0;
350 
351  } else { // too small
352  if(TP_DEBUG) {
353  cout<<" very bad, binx "<<binoffx<<endl;
354  cout<<mpx<<" "<<binoffx<<" "
355  <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
356  }
357  }
358 
359  // The final position in local coordinates
360  float lpX = float(binoffx*m_pitchx) + fractionX*local_pitchx +
361  m_xoffset;
362 
363  if(TP_DEBUG && (lpX<m_xoffset || lpX>(-m_xoffset)) ) {
364  cout<<" bad lp x "<<lpX<<endl;
365  cout<<mpx<<" "<<binoffx<<" "
366  <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
367  }
368 
369  return lpX;
370 }
371 
372 // measuremet to local transformation for Y coordinate
373 // Y is in the ROC column number direction
374 float RectangularPixelTopology::localY(const float mpy) const {
375  using std::cout;
376  using std::endl;
377  int binoffy = int(mpy); // truncate to int
378  float fractionY = mpy - binoffy; // find the fraction
379  float local_pitchy = m_pitchy; // defaultpitch
380  //if(fractionY<0.) cout<<" fractiony m "<<fractionY<<" "<<mpy<<endl;
381 
382  if (binoffy>416) { // ROC 8, not real ROC
383  binoffy=binoffy+17;
384  } else if (binoffy==416) { // ROC 8
385  binoffy=binoffy+16;
386  local_pitchy = 2 * m_pitchy;
387 
388  } else if (binoffy==415) { // ROC 7, last big pixel
389  binoffy=binoffy+15;
390  local_pitchy = 2 * m_pitchy;
391  } else if (binoffy>364) { // ROC 7
392  binoffy=binoffy+15;
393  } else if (binoffy==364) { // ROC 7
394  binoffy=binoffy+14;
395  local_pitchy = 2 * m_pitchy;
396 
397  } else if (binoffy==363) { // ROC 6
398  binoffy=binoffy+13;
399  local_pitchy = 2 * m_pitchy;
400  } else if (binoffy>312) { // ROC 6
401  binoffy=binoffy+13;
402  } else if (binoffy==312) { // ROC 6
403  binoffy=binoffy+12;
404  local_pitchy = 2 * m_pitchy;
405 
406  } else if (binoffy==311) { // ROC 5
407  binoffy=binoffy+11;
408  local_pitchy = 2 * m_pitchy;
409  } else if (binoffy>260) { // ROC 5
410  binoffy=binoffy+11;
411  } else if (binoffy==260) { // ROC 5
412  binoffy=binoffy+10;
413  local_pitchy = 2 * m_pitchy;
414 
415  } else if (binoffy==259) { // ROC 4
416  binoffy=binoffy+9;
417  local_pitchy = 2 * m_pitchy;
418  } else if (binoffy>208) { // ROC 4
419  binoffy=binoffy+9;
420  } else if (binoffy==208) { // ROC 4
421  binoffy=binoffy+8;
422  local_pitchy = 2 * m_pitchy;
423 
424  } else if (binoffy==207) { // ROC 3
425  binoffy=binoffy+7;
426  local_pitchy = 2 * m_pitchy;
427  } else if (binoffy>156) { // ROC 3
428  binoffy=binoffy+7;
429  } else if (binoffy==156) { // ROC 3
430  binoffy=binoffy+6;
431  local_pitchy = 2 * m_pitchy;
432 
433  } else if (binoffy==155) { // ROC 2
434  binoffy=binoffy+5;
435  local_pitchy = 2 * m_pitchy;
436  } else if (binoffy>104) { // ROC 2
437  binoffy=binoffy+5;
438  } else if (binoffy==104) { // ROC 2
439  binoffy=binoffy+4;
440  local_pitchy = 2 * m_pitchy;
441 
442  } else if (binoffy==103) { // ROC 1
443  binoffy=binoffy+3;
444  local_pitchy = 2 * m_pitchy;
445  } else if (binoffy>52) { // ROC 1
446  binoffy=binoffy+3;
447  } else if (binoffy==52) { // ROC 1
448  binoffy=binoffy+2;
449  local_pitchy = 2 * m_pitchy;
450 
451  } else if (binoffy==51) { // ROC 0
452  binoffy=binoffy+1;
453  local_pitchy = 2 * m_pitchy;
454  } else if (binoffy>0) { // ROC 0
455  binoffy=binoffy+1;
456  } else if (binoffy==0) { // ROC 0
457  binoffy=binoffy+0;
458  local_pitchy = 2 * m_pitchy;
459  } else { // too small
460  if(TP_DEBUG) {
461  cout<<" very bad, biny "<<binoffy<<endl;
462  cout<<mpy<<" "<<binoffy<<" "
463  <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
464  }
465  }
466 
467  // The final position in local coordinates
468  float lpY = float(binoffy*m_pitchy) + fractionY*local_pitchy +
469  m_yoffset;
470  if(TP_DEBUG && (lpY<m_yoffset || lpY>(-m_yoffset)) ) {
471  cout<<" bad lp y "<<lpY<<endl;
472  cout<<mpy<<" "<<binoffy<<" "
473  <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
474  }
475 
476  return lpY;
477 }
479 // Get hit errors in LocalPoint coordinates (cm)
481  const MeasurementPoint& mp,
482  const MeasurementError& me) const {
483  float pitchy=m_pitchy;
484  int binoffy=int(mp.y());
485  if( isItBigPixelInY(binoffy) )pitchy = 2.*m_pitchy;
486 
487  float pitchx=m_pitchx;
488  int binoffx=int(mp.x());
489  if( isItBigPixelInX(binoffx) )pitchx = 2.*m_pitchx;
490 
491  return LocalError( me.uu()*float(pitchx*pitchx), 0,
492  me.vv()*float(pitchy*pitchy));
493 }
495 // Get errors in pixel pitch units.
497  const LocalPoint& lp,
498  const LocalError& le) const {
499 
500  float pitchy=m_pitchy;
501  int iybin = int( (lp.y() - m_yoffset)/m_pitchy ); //get bin for equal picth
502  int iybin0 = iybin%54; //This is just to avoid many ifs by using the periodicy
503  //quasi bins 0,1,52,53 fall into larger pixels
504  if(iybin0==0 || iybin0==1 || iybin0==52 || iybin0==53 )
505  pitchy = 2. * m_pitchy;
506 
507  float pitchx=m_pitchx;
508  int ixbin = int( (lp.x() - m_xoffset)/m_pitchx ); //get bin for equal pitch
509  //quasi bins 79,80,81,82 fall into the 2 larger pixels
510  if(ixbin>=79 && ixbin<=82) pitchx = 2. * m_pitchx;
511 
512  return MeasurementError( le.xx()/float(pitchx*pitchx), 0,
513  le.yy()/float(pitchy*pitchy));
514 }
515 
516 bool RectangularPixelTopology::containsBigPixelInX(const int& ixmin, const int& ixmax) const {
517  bool big = false;
518  for(int i=ixmin; i!=ixmax+1; i++) {
519  if(isItBigPixelInX(i) && big==false) big=true;
520  }
521  return big;
522 }
523 
524 bool RectangularPixelTopology::containsBigPixelInY(const int& iymin, const int& iymax) const {
525  bool big = false;
526  for(int i=iymin; i!=iymax+1; i++) {
527  if(isItBigPixelInY(i) && big==false) big=true;
528  }
529  return big;
530 }
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
float vv() const
T y() const
Definition: PV2DBase.h:45
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:62
bool containsBigPixelInY(const int &iymin, const int &iymax) const
float yy() const
Definition: LocalError.h:26
bool containsBigPixelInX(const int &ixmin, const int &ixmax) const
float uu() const
#define TP_DEBUG
virtual LocalError localError(const MeasurementPoint &, const MeasurementError &) const
virtual LocalPoint localPosition(const MeasurementPoint &mp) const
virtual float localX(const float mpX) const
virtual std::pair< float, float > pixel(const LocalPoint &p) const
Definition: big.h:6
virtual bool isItBigPixelInX(const int ixbin) const
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV2DBase.h:44
T x() const
Definition: PV3DBase.h:61
unsigned long long le
Definition: VDTMath.h:202