00001 #include "Geometry/TrackerTopology/interface/RectangularPixelTopology.h"
00002
00006
00007
00008
00009
00010
00011
00012
00013 std::pair<float,float> RectangularPixelTopology::pixel(
00014 const LocalPoint& p) const {
00015 using std::cout;
00016 using std::endl;
00017
00018
00019 float py = p.y();
00020 float px = p.x();
00021
00022 if(TP_DEBUG) {
00023
00024
00025
00026 if( py<m_yoffset ) {
00027 cout<<" wrong lp y "<<py<<" "<<m_yoffset<<endl;
00028 py = m_yoffset + EPSCM;
00029 }
00030 if( py>-m_yoffset ) {
00031 cout<<" wrong lp y "<<py<<" "<<-m_yoffset<<endl;
00032 py = -m_yoffset - EPSCM;
00033 }
00034 if( px<m_xoffset ) {
00035 cout<<" wrong lp x "<<px<<" "<<m_xoffset<<endl;
00036 px = m_xoffset + EPSCM;
00037 }
00038 if( px>-m_xoffset ) {
00039 cout<<" wrong lp x "<<px<<" "<<-m_xoffset<<endl;
00040 px = -m_xoffset - EPSCM;
00041 }
00042 }
00043
00044 float newybin=(py - m_yoffset)/m_pitchy;
00045 int iybin = int(newybin);
00046 float fractionY = newybin - iybin;
00047
00048
00049
00050 int iybin0 = (iybin%54);
00051 int numROC = iybin/54;
00052
00053 if (iybin0>53) {
00054 if(TP_DEBUG) {
00055 cout<<" very bad, newbiny "<<iybin0<<endl;
00056 cout<<py<<" "<<m_yoffset<<" "<<m_pitchy<<" "
00057 <<newybin<<" "<<iybin<<" "<<fractionY<<" "<<iybin0<<" "
00058 <<numROC<<endl;
00059 }
00060 } else if (iybin0==53) {
00061 iybin0=51;
00062 fractionY = (fractionY+1.)/2.;
00063 } else if (iybin0==52) {
00064 iybin0=51;
00065 fractionY = fractionY/2.;
00066 } else if (iybin0>1) {
00067 iybin0=iybin0-1;
00068 } else if (iybin0==1) {
00069 iybin0=0;
00070 fractionY = (fractionY+1.)/2.;
00071 } else if (iybin0==0) {
00072 iybin0=0;
00073 fractionY = fractionY/2.;
00074 } else {
00075 if(TP_DEBUG) {
00076 cout<<" very bad, newbiny "<<newybin<<endl;
00077 cout<<py<<" "<<m_yoffset<<" "<<m_pitchy<<" "
00078 <<newybin<<" "<<iybin<<" "<<fractionY<<" "
00079 <<iybin0<<" "<<numROC<<endl;
00080 }
00081 }
00082 float mpY = float(numROC*52. + iybin0) + fractionY;
00083 if(TP_DEBUG && (mpY<0. || mpY>=416.)) {
00084 cout<<" bad pix y "<<mpY<<endl;
00085 cout<<py<<" "<<m_yoffset<<" "<<m_pitchy<<" "
00086 <<newybin<<" "<<iybin<<" "<<fractionY<<" "
00087 <<iybin0<<" "<<numROC<<endl;
00088 }
00089
00090
00091 float newxbin=(px - m_xoffset) / m_pitchx;
00092 int ixbin = int(newxbin);
00093 float fractionX = newxbin - ixbin;
00094
00095
00096
00097
00098
00099
00100 if (ixbin>161) {
00101 if(TP_DEBUG) {
00102 cout<<" very bad, newbinx "<<ixbin<<endl;
00103 cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
00104 <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
00105 }
00106 } else if (ixbin>82) {
00107 ixbin=ixbin-2;
00108 } else if (ixbin==82) {
00109 ixbin=80;
00110 fractionX = (fractionX+1.)/2.;
00111 } else if (ixbin==81) {
00112 ixbin=80;
00113 fractionX = fractionX/2.;
00114 } else if (ixbin==80) {
00115 ixbin=79;
00116 fractionX = (fractionX+1.)/2.;
00117 } else if (ixbin==79) {
00118 ixbin=79;
00119 fractionX = fractionX/2.;
00120 } else if (ixbin<0) {
00121 if(TP_DEBUG) {
00122 cout<<" very bad, newbinx "<<ixbin<<endl;
00123 cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
00124 <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
00125 }
00126 }
00127
00128 float mpX = float(ixbin) + fractionX;
00129
00130 if(TP_DEBUG && (mpX<0. || mpX>=160.) ) {
00131 cout<<" bad pix x "<<mpX<<" "<<endl;
00132 cout<<px<<" "<<m_xoffset<<" "<<m_pitchx<<" "
00133 <<newxbin<<" "<<ixbin<<" "<<fractionX<<endl;
00134 }
00135
00136 return std::pair<float,float>(mpX,mpY);
00137 }
00138
00139
00140
00141 LocalPoint RectangularPixelTopology::localPosition(
00142 const MeasurementPoint& mp) const {
00143 using std::cout;
00144 using std::endl;
00145
00146 float mpy = mp.y();
00147 float mpx = mp.x();
00148
00149
00150 if(TP_DEBUG) {
00151 if( mpy<0.) {
00152 cout<<" wrong mp y, fix "<<mpy<<" "
00153 <<0<<endl;
00154 mpy = 0.;
00155 }
00156 if( mpy>=m_ncols) {
00157 cout<<" wrong mp y, fix "<<mpy<<" "
00158 <<m_ncols<<endl;
00159 mpy = float(m_ncols) - EPS;
00160 }
00161 if( mpx<0.) {
00162 cout<<" wrong mp x, fix "<<mpx<<" "
00163 <<0<<endl;
00164 mpx = 0.;
00165 }
00166 if( mpx>=m_nrows) {
00167 cout<<" wrong mp x, fix "<<mpx<<" "
00168 <<m_nrows<<endl;
00169 mpx = float(m_nrows) - EPS;
00170 }
00171 }
00172
00173
00174
00175 float lpY = localY(mpy);
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 float lpX = localX(mpx);
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 return LocalPoint( lpX, lpY);
00325 }
00326
00327
00328
00329
00330 float RectangularPixelTopology::localX(const float mpx) const {
00331 using std::cout;
00332 using std::endl;
00333
00334 int binoffx=int(mpx);
00335 float fractionX = mpx - binoffx;
00336 float local_pitchx = m_pitchx;
00337
00338
00339 if (binoffx>80) {
00340 binoffx=binoffx+2;
00341 } else if (binoffx==80) {
00342 binoffx=binoffx+1;
00343 local_pitchx = 2 * m_pitchx;
00344
00345 } else if (binoffx==79) {
00346 binoffx=binoffx+0;
00347 local_pitchx = 2 * m_pitchx;
00348 } else if (binoffx>=0) {
00349 binoffx=binoffx+0;
00350
00351 } else {
00352 if(TP_DEBUG) {
00353 cout<<" very bad, binx "<<binoffx<<endl;
00354 cout<<mpx<<" "<<binoffx<<" "
00355 <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
00356 }
00357 }
00358
00359
00360 float lpX = float(binoffx*m_pitchx) + fractionX*local_pitchx +
00361 m_xoffset;
00362
00363 if(TP_DEBUG && (lpX<m_xoffset || lpX>(-m_xoffset)) ) {
00364 cout<<" bad lp x "<<lpX<<endl;
00365 cout<<mpx<<" "<<binoffx<<" "
00366 <<fractionX<<" "<<local_pitchx<<" "<<m_xoffset<<endl;
00367 }
00368
00369 return lpX;
00370 }
00371
00372
00373
00374 float RectangularPixelTopology::localY(const float mpy) const {
00375 using std::cout;
00376 using std::endl;
00377 int binoffy = int(mpy);
00378 float fractionY = mpy - binoffy;
00379 float local_pitchy = m_pitchy;
00380
00381
00382 if (binoffy>416) {
00383 binoffy=binoffy+17;
00384 } else if (binoffy==416) {
00385 binoffy=binoffy+16;
00386 local_pitchy = 2 * m_pitchy;
00387
00388 } else if (binoffy==415) {
00389 binoffy=binoffy+15;
00390 local_pitchy = 2 * m_pitchy;
00391 } else if (binoffy>364) {
00392 binoffy=binoffy+15;
00393 } else if (binoffy==364) {
00394 binoffy=binoffy+14;
00395 local_pitchy = 2 * m_pitchy;
00396
00397 } else if (binoffy==363) {
00398 binoffy=binoffy+13;
00399 local_pitchy = 2 * m_pitchy;
00400 } else if (binoffy>312) {
00401 binoffy=binoffy+13;
00402 } else if (binoffy==312) {
00403 binoffy=binoffy+12;
00404 local_pitchy = 2 * m_pitchy;
00405
00406 } else if (binoffy==311) {
00407 binoffy=binoffy+11;
00408 local_pitchy = 2 * m_pitchy;
00409 } else if (binoffy>260) {
00410 binoffy=binoffy+11;
00411 } else if (binoffy==260) {
00412 binoffy=binoffy+10;
00413 local_pitchy = 2 * m_pitchy;
00414
00415 } else if (binoffy==259) {
00416 binoffy=binoffy+9;
00417 local_pitchy = 2 * m_pitchy;
00418 } else if (binoffy>208) {
00419 binoffy=binoffy+9;
00420 } else if (binoffy==208) {
00421 binoffy=binoffy+8;
00422 local_pitchy = 2 * m_pitchy;
00423
00424 } else if (binoffy==207) {
00425 binoffy=binoffy+7;
00426 local_pitchy = 2 * m_pitchy;
00427 } else if (binoffy>156) {
00428 binoffy=binoffy+7;
00429 } else if (binoffy==156) {
00430 binoffy=binoffy+6;
00431 local_pitchy = 2 * m_pitchy;
00432
00433 } else if (binoffy==155) {
00434 binoffy=binoffy+5;
00435 local_pitchy = 2 * m_pitchy;
00436 } else if (binoffy>104) {
00437 binoffy=binoffy+5;
00438 } else if (binoffy==104) {
00439 binoffy=binoffy+4;
00440 local_pitchy = 2 * m_pitchy;
00441
00442 } else if (binoffy==103) {
00443 binoffy=binoffy+3;
00444 local_pitchy = 2 * m_pitchy;
00445 } else if (binoffy>52) {
00446 binoffy=binoffy+3;
00447 } else if (binoffy==52) {
00448 binoffy=binoffy+2;
00449 local_pitchy = 2 * m_pitchy;
00450
00451 } else if (binoffy==51) {
00452 binoffy=binoffy+1;
00453 local_pitchy = 2 * m_pitchy;
00454 } else if (binoffy>0) {
00455 binoffy=binoffy+1;
00456 } else if (binoffy==0) {
00457 binoffy=binoffy+0;
00458 local_pitchy = 2 * m_pitchy;
00459 } else {
00460 if(TP_DEBUG) {
00461 cout<<" very bad, biny "<<binoffy<<endl;
00462 cout<<mpy<<" "<<binoffy<<" "
00463 <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
00464 }
00465 }
00466
00467
00468 float lpY = float(binoffy*m_pitchy) + fractionY*local_pitchy +
00469 m_yoffset;
00470 if(TP_DEBUG && (lpY<m_yoffset || lpY>(-m_yoffset)) ) {
00471 cout<<" bad lp y "<<lpY<<endl;
00472 cout<<mpy<<" "<<binoffy<<" "
00473 <<fractionY<<" "<<local_pitchy<<" "<<m_yoffset<<endl;
00474 }
00475
00476 return lpY;
00477 }
00479
00480 LocalError RectangularPixelTopology::localError(
00481 const MeasurementPoint& mp,
00482 const MeasurementError& me) const {
00483 float pitchy=m_pitchy;
00484 int binoffy=int(mp.y());
00485 if( isItBigPixelInY(binoffy) )pitchy = 2.*m_pitchy;
00486
00487 float pitchx=m_pitchx;
00488 int binoffx=int(mp.x());
00489 if( isItBigPixelInX(binoffx) )pitchx = 2.*m_pitchx;
00490
00491 return LocalError( me.uu()*float(pitchx*pitchx), 0,
00492 me.vv()*float(pitchy*pitchy));
00493 }
00495
00496 MeasurementError RectangularPixelTopology::measurementError(
00497 const LocalPoint& lp,
00498 const LocalError& le) const {
00499
00500 float pitchy=m_pitchy;
00501 int iybin = int( (lp.y() - m_yoffset)/m_pitchy );
00502 int iybin0 = iybin%54;
00503
00504 if(iybin0==0 || iybin0==1 || iybin0==52 || iybin0==53 )
00505 pitchy = 2. * m_pitchy;
00506
00507 float pitchx=m_pitchx;
00508 int ixbin = int( (lp.x() - m_xoffset)/m_pitchx );
00509
00510 if(ixbin>=79 && ixbin<=82) pitchx = 2. * m_pitchx;
00511
00512 return MeasurementError( le.xx()/float(pitchx*pitchx), 0,
00513 le.yy()/float(pitchy*pitchy));
00514 }
00515
00516 bool RectangularPixelTopology::containsBigPixelInX(const int& ixmin, const int& ixmax) const {
00517 bool big = false;
00518 for(int i=ixmin; i!=ixmax+1; i++) {
00519 if(isItBigPixelInX(i) && big==false) big=true;
00520 }
00521 return big;
00522 }
00523
00524 bool RectangularPixelTopology::containsBigPixelInY(const int& iymin, const int& iymax) const {
00525 bool big = false;
00526 for(int i=iymin; i!=iymax+1; i++) {
00527 if(isItBigPixelInY(i) && big==false) big=true;
00528 }
00529 return big;
00530 }