00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelErrorParametrization.h"
00014
00015
00016
00017
00018
00019 #include "FWCore/ParameterSet/interface/FileInPath.h"
00020 #include "FWCore/Utilities/interface/Exception.h"
00021
00022
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024
00025 #include <string>
00026 #include <iostream>
00027 #include <fstream>
00028 #include <sstream>
00029
00030
00031 #include <iterator>
00032 #include <cmath>
00033
00034 using namespace std;
00035 using namespace edm;
00036
00037 const float math_pi = 3.14159265;
00038 const float pitch_x = 0.0100;
00039 const float pitch_y = 0.0150;
00040
00041
00042 const float error_yb_big_pix = 0.0070;
00043 const float error_xb_big_pix = 0.0030;
00044 const float error_yf_big_pix = 0.0068;
00045 const float error_xf_big_pix = 0.0040;
00046
00047
00048 float aa_min[3] = {1.50, 1.45, 1.40};
00049 float aa_max[3] = {1.75, 1.70, 1.65};
00050
00051 bool verbose = false;
00052
00053
00054
00055
00056 PixelErrorParametrization::PixelErrorParametrization(edm::ParameterSet const& conf)
00057 {
00058
00059 theParametrizationType =
00060 conf.getParameter<string>("PixelErrorParametrization");
00061
00062 useNewParametrization = conf.getParameter<bool>("UseNewParametrization");
00063
00064 useSigma = conf.getParameter<bool>("UseSigma");
00065
00066 if ( !useNewParametrization )
00067 {
00068 if (verbose)
00069 {
00070 LogDebug ("PixelErrorParametrization::PixelErrorParametrization")
00071 << " Using OLD pixel hit error parameterization !!!" ;
00072 }
00073
00075
00077
00078
00079 a_min = 1.37078;
00080 a_max = 1.77078;
00081 a_bin = 0.1;
00082
00083
00084 brange_yb.resize(6);
00085 brange_yb[0] = pair<float,float>(0., 0.6);
00086 brange_yb[1] = pair<float,float>(0.1, 0.9);
00087 brange_yb[2] = pair<float,float>(0.6, 1.05);
00088 brange_yb[3] = pair<float,float>(0.9, 1.15);
00089 brange_yb[4] = pair<float,float>(1.05, 1.22);
00090 brange_yb[5] = pair<float,float>(1.15, 1.41);
00091
00092
00093
00094
00095
00096
00097 readYB( ybarrel_3D, "yres_npix", "_alpha", "_b.vec");
00098
00099
00100
00101
00102
00103 bbins_xb.resize(3);
00104
00105 (bbins_xb[0]).resize(1);
00106 (bbins_xb[0])[0] = 100.;
00107
00108 (bbins_xb[1]).resize(3);
00109 (bbins_xb[1])[0] = 0.7;
00110 (bbins_xb[1])[1] = 1.;
00111 (bbins_xb[1])[2] = 1.2;
00112
00113 (bbins_xb[2]).resize(3);
00114 (bbins_xb[2])[0] = 0.7;
00115 (bbins_xb[2])[1] = 1.;
00116 (bbins_xb[2])[2] = 1.2;
00117
00118
00119
00120
00121
00122 readXB( xbarrel_3D, "xpar_npix", "_beta", "_b.vec");
00123
00124
00125
00126
00127
00128 brange_yf = pair<float,float>(0.3, 0.4);
00129
00130
00131
00132
00133
00134
00135
00136
00137 readF( yforward_3D, "ypar_npix", "_alpha", "_f.vec");
00138
00139
00140
00141
00142 readF( xforward_3D, "xpar_npix", "_beta", "_f.vec");
00143 }
00144 else
00145 {
00146 if (verbose)
00147 {
00148 LogDebug ("PixelErrorParametrization::PixelErrorParametrization")
00149 << " Using NEW pixel hit error parameterization !!!" ;
00150 }
00151
00152 a_min = 1.37078;
00153 a_max = 1.77078;
00154 a_bin = 0.1;
00155
00156 ys_bl[0] = 0.05;
00157 ys_bh[0] = 0.50;
00158
00159 ys_bl[1] = 0.15;
00160 ys_bh[1] = 0.90;
00161
00162 ys_bl[2] = 0.70;
00163 ys_bh[2] = 1.05;
00164
00165 ys_bl[3] = 0.95;
00166 ys_bh[3] = 1.15;
00167
00168 ys_bl[4] = 1.15;
00169 ys_bh[4] = 1.20;
00170
00171 ys_bl[5] = 1.20;
00172 ys_bh[5] = 1.40;
00173
00174 edm::FileInPath file( "RecoLocalTracker/SiPixelRecHits/data/residuals.dat" );
00175 const char* fname = (file.fullPath()).c_str();
00176
00177 FILE* datfile;
00178
00179 if ( (datfile=fopen(fname,"r")) == NULL )
00180 throw cms::Exception("FileNotFound")
00181 << "PixelErrorParameterization::PixelErrorParameterization - Input file not found";
00182
00183 vec_error_XB.clear();
00184 vec_error_YB.clear();
00185 vec_error_XF.clear();
00186 vec_error_YF.clear();
00187
00188 while ( !feof(datfile) )
00189 {
00190 int detid = -999;
00191 int size = -999;
00192 int angle_ind1 = -999;
00193 int angle_ind2 = -999;
00194 float sigma = -999.9;
00195 float rms = -999.9;
00196
00197 fscanf( datfile,
00198 "%d %d %d %d %f %f \n",
00199 &detid, &size, &angle_ind1, &angle_ind2, &sigma, &rms );
00200
00201 float error = -9999.9;
00202 if ( useSigma )
00203 {
00204 if (verbose)
00205 LogDebug ("PixelErrorParametrization::PixelErrorParametrization")
00206 << " Use error = Gaussian sigma" ;
00207 error = sigma;
00208 }
00209 else
00210 {
00211 if (verbose)
00212 LogDebug ("PixelErrorParametrization::PixelErrorParametrization")
00213 << " Use error = RMS" ;
00214 error = rms;
00215 }
00216
00217 if ( detid == 1 )
00218 vec_error_YB.push_back( error );
00219 else if ( detid == 2 )
00220 vec_error_XB.push_back( error );
00221 else if ( detid == 3 )
00222 vec_error_YF.push_back( error );
00223 else if ( detid == 4 )
00224 vec_error_XF.push_back( error );
00225 else
00226 {
00227 throw cms::Exception("PixelErrorParametrization::PixelErrorParametrization")
00228 << " Wrong ID !!!";
00229 }
00230 }
00231
00232 int n_entries_yb = 240;
00233 if ( (int)vec_error_YB.size() != n_entries_yb )
00234 {
00235 throw cms::Exception(" PixelErrorParametrization::PixelErrorParametrization: ")
00236 << " Number of Y barrel constants read different than expected !!!"
00237 << " Expected " << n_entries_yb << " and found " << (int)vec_error_YB.size();
00238 }
00239 int n_entries_xb = 120;
00240 if ( (int)vec_error_XB.size() != n_entries_xb )
00241 {
00242 throw cms::Exception(" PixelErrorParametrization::PixelErrorParametrization: ")
00243 << " Number of X barrel constants read different than expected !!!"
00244 << " Expected " << n_entries_xb << " and found " << (int)vec_error_XB.size();
00245 }
00246 int n_entries_yf = 20;
00247 if ( (int)vec_error_YF.size() != n_entries_yf )
00248 {
00249 throw cms::Exception(" PixelErrorParametrization::PixelErrorParametrization: ")
00250 << " Number of Y forward constants read different than expected !!!"
00251 << " Expected " << n_entries_yf << " and found " << (int)vec_error_YF.size();
00252 }
00253 int n_entries_xf = 20;
00254 if ( (int)vec_error_XF.size() != n_entries_xf )
00255 {
00256 throw cms::Exception(" PixelErrorParametrization::PixelErrorParametrization: ")
00257 << " Number of X forward constants read different than expected !!!"
00258 << " Expected " << n_entries_xf << " and found " << (int)vec_error_XF.size();
00259 }
00260
00261 }
00262
00263 }
00264
00265
00266
00267
00268
00269 PixelErrorParametrization::~PixelErrorParametrization(){}
00270
00271
00272
00273
00274
00275
00276 pair<float,float>
00277 PixelErrorParametrization::getError( GeomDetType::SubDetector pixelPart,
00278 int sizex, int sizey,
00279 float alpha, float beta,
00280 bool bigInX, bool bigInY)
00281 {
00282 pair<float,float> element;
00283
00288 if( isnan(alpha) || isnan(beta) )
00289 {
00290 LogError ("NANcatched") << "PixelErrorParametrization::getError: NAN catched in angles alpha or beta" ;
00291
00292 element = pair<float,float>(0.010/sqrt(12.), 0.015/sqrt(12.));
00293 return element;
00294 }
00295
00296 switch (pixelPart)
00297 {
00298 case GeomDetEnumerators::PixelBarrel:
00299 element = pair<float,float>(error_XB(sizex, alpha, beta, bigInX),
00300 error_YB(sizey, alpha, beta, bigInY));
00301 break;
00302 case GeomDetEnumerators::PixelEndcap:
00303 element = pair<float,float>(error_XF(sizex, alpha, beta, bigInX),
00304 error_YF(sizey, alpha, beta, bigInY));
00305 break;
00306 default:
00307 throw cms::Exception("PixelErrorParametrization::getError")
00308 << "Non-pixel detector type !!!" ;
00309 }
00310
00311 LogDebug ("PixelErrorParametrization::getError") << " ErrorMatrix gives error: "
00312 << element.first << " , " << element.second;
00313
00314 return element;
00315 }
00316
00317 float PixelErrorParametrization::error_XB(int sizex, float alpha, float beta, bool bigInX)
00318 {
00319 if ( !useNewParametrization )
00320 {
00321 LogDebug("PixelErrorParametrization::error_XB") << "I'M AT THE BEGIN IN ERROR XB METHOD";
00322 bool barrelPart = true;
00323
00324 int i_size = min(sizex-1,2);
00325
00326
00327 int i_beta = betaIndex(i_size, bbins_xb[i_size], beta);
00328
00329
00330
00331
00332
00333
00334 if ( bigInX && sizex == 1 )
00335 return pitch_x/sqrt(12.0);
00336 else
00337 return quadParametrize(barrelPart, i_size, i_beta, alpha);
00338 }
00339 else
00340 {
00341 float error_xb = -999.9;
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 if ( bigInX && sizex == 1 )
00355 {
00356
00357 error_xb = error_xb_big_pix;
00358 }
00359 else
00360 {
00361 float alpha_rad = fabs(alpha);
00362
00363 float betap_rad = fabs( math_pi/2.0 - beta );
00364
00365
00366 if ( sizex > 3 ) sizex = 3;
00367
00368 int ind_sizex = sizex - 1;
00369 int ind_beta = -999;
00370 int ind_alpha = -999;
00371
00372 if ( betap_rad <= 0.7 ) ind_beta = 0;
00373 else if ( 0.7 < betap_rad && betap_rad <= 1.0 ) ind_beta = 1;
00374 else if ( 1.0 < betap_rad && betap_rad <= 1.2 ) ind_beta = 2;
00375 else if ( 1.2 <= betap_rad ) ind_beta = 3;
00376 else
00377 {
00378 throw cms::Exception("PixelErrorParametrization::error_XB") << " Wrong betap_rad = " << betap_rad;
00379 }
00380
00381 if ( alpha_rad <= aa_min[ind_sizex] ) ind_alpha = 0;
00382 else if ( alpha_rad >= aa_max[ind_sizex] ) ind_alpha = 9;
00383 else
00384 ind_alpha = (int) ( ( alpha_rad - aa_min[ind_sizex] ) / ( ( aa_max[ind_sizex] - aa_min[ind_sizex] ) / 10.0 ) );
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 int index = 40*ind_sizex + 10*ind_beta + ind_alpha;
00397
00398 if ( index < 0 || index >= 120 )
00399 {
00400 throw cms::Exception(" PixelErrorParametrization::error_XB") << " Wrong index !!!";
00401 }
00402
00403 error_xb = vec_error_XB[index];
00404
00405 }
00406
00407
00408
00409
00410 return error_xb;
00411 }
00412
00413 }
00414
00415
00416 float PixelErrorParametrization::error_XF(int sizex, float alpha, float beta, bool bigInX)
00417 {
00418 if ( !useNewParametrization )
00419 {
00420 LogDebug("PixelErrorParametrization::error_XF") << "I'M AT THE BEGIN IN ERROR XF METHOD";
00421
00422 bool barrelPart = false;
00423
00424 float alpha_prime = fabs(3.14159/2.-alpha);
00425
00426 int i_size = min(sizex-1,2);
00427
00428 int i_beta = 0;
00429
00430
00431 LogDebug("PixelErrorParametrization::error_XF") << "size index = " << i_size
00432 << "no beta index, "
00433 << " alphaprime = " << alpha_prime;
00434
00435 if ( bigInX && sizex == 1 )
00436 return pitch_x/sqrt(12.0);
00437 else
00438 return linParametrize(barrelPart, i_size, i_beta, alpha_prime);
00439 }
00440 else
00441 {
00442 float error_xf = -999.9;
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 if ( bigInX && sizex == 1 )
00456 {
00457
00458 error_xf = error_xf_big_pix;
00459 }
00460 else
00461 {
00462
00463
00464
00465 float alphap_rad = fabs( math_pi/2.0 - alpha );
00466
00467 if ( sizex > 2 ) sizex = 2;
00468
00469 int ind_sizex = sizex - 1;
00470 int ind_alpha = -9999;
00471
00472 if ( sizex == 1 )
00473 {
00474 if ( alphap_rad <= 0.15 ) ind_alpha = 0;
00475 else if ( alphap_rad >= 0.30 ) ind_alpha = 9;
00476 else
00477 ind_alpha = (int) ( ( alphap_rad - 0.15 ) / ( ( 0.30 - 0.15 ) / 10.0 ) );
00478 }
00479 if ( sizex > 1 )
00480 {
00481 if ( alphap_rad <= 0.15 ) ind_alpha = 0;
00482 else if ( alphap_rad >= 0.50 ) ind_alpha = 9;
00483 else
00484 ind_alpha = (int) ( ( alphap_rad - 0.15 ) / ( ( 0.50 - 0.15 ) / 10.0 ) );
00485 }
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 int index = 10*ind_sizex + ind_alpha;
00496
00497 if ( index < 0 || index >= 20 )
00498 {
00499 throw cms::Exception(" PixelErrorParametrization::error_XF") << " Wrong index !!!";
00500 }
00501
00502 error_xf = vec_error_XF[index];
00503
00504 }
00505
00506
00507
00508
00509 return error_xf;
00510 }
00511
00512 }
00513
00514
00515 float PixelErrorParametrization::error_YB(int sizey, float alpha, float beta, bool bigInY)
00516 {
00517 if ( !useNewParametrization )
00518 {
00519 LogDebug("PixelErrorParametrization::error_YB") << "I'M AT THE BEGIN IN ERROR YB METHOD";
00520
00521
00522
00523 if ( bigInY && sizey == 1 )
00524 {
00525 return pitch_y/sqrt(12.0);
00526 }
00527 else
00528 {
00529 int i_alpha;
00530 int i_size = min(sizey-1,5);
00531
00532 LogDebug("PixelErrorParametrization::error_YB") << "I found size index = " << i_size;
00533
00534 if (sizey < 4)
00535 {
00536 if (alpha <= a_min + a_bin)
00537 {
00538 i_alpha = 0;
00539 }
00540 else if (alpha < a_max-a_bin)
00541 {
00542 i_alpha = 1;
00543 }
00544 else
00545 {
00546 i_alpha = 2;
00547 }
00548 }
00549 else
00550 {
00551 i_alpha = 0;
00552 }
00553
00554 LogDebug("PixelErrorParametrization::error_YB") << "I found alpha index = " << i_alpha;
00555
00556
00557
00558 vector<float>& ybarrel_1D = (ybarrel_3D[i_size])[i_alpha];
00559
00560 LogDebug("PixelErrorParametrization::error_YB") << " beta vec has dimensions = " << ybarrel_1D.size()
00561 << " beta = " << beta
00562 << " beta max = " << brange_yb[i_size].second
00563 << " beta min = " << brange_yb[i_size].first;
00564
00565
00566 float beta_prime = fabs(3.14159/2.-beta);
00567
00568 if ( beta_prime <= brange_yb[i_size].first )
00569 {
00570 return ybarrel_1D[0];
00571 }
00572 else if ( beta_prime >= brange_yb[i_size].second )
00573 {
00574
00575 return pitch_y / sqrt(12.0);
00576 }
00577 else
00578 {
00579 return interpolation(ybarrel_1D, beta_prime, brange_yb[i_size] );
00580 }
00581 }
00582 }
00583 else
00584 {
00585 float error_yb = -999.9;
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 if ( bigInY && sizey == 1 )
00599 {
00600
00601 error_yb = error_yb_big_pix;
00602 }
00603 else
00604 {
00605 float alpha_rad = fabs(alpha);
00606
00607 float betap_rad = fabs( math_pi/2.0 - beta );
00608
00609
00610 if ( sizey > 6 ) sizey = 6;
00611
00612 int ind_sizey = sizey - 1;
00613 int ind_alpha = -9999;
00614 int ind_beta = -9999;
00615
00616 if ( alpha_rad <= a_min ) ind_alpha = 0;
00617 else if ( alpha_rad >= a_max ) ind_alpha = 3;
00618 else if ( alpha_rad > a_min &&
00619 alpha_rad < a_max )
00620 {
00621 double binw = ( a_max - a_min ) / 4.0;
00622 ind_alpha = (int)( ( alpha_rad - a_min ) / binw );
00623 }
00624 else
00625 {
00626 throw cms::Exception(" PixelErrorParametrization::error_YB") << " Wrong alpha_rad = " << alpha_rad;
00627
00628 }
00629
00630 if ( betap_rad <= ys_bl[sizey-1] ) ind_beta = 0;
00631 else if ( betap_rad >= ys_bh[sizey-1] ) ind_beta = 9;
00632 else if ( betap_rad > ys_bl[sizey-1] &&
00633 betap_rad < ys_bh[sizey-1] )
00634 {
00635 double binw = ( ys_bh[sizey-1] - ys_bl[sizey-1] ) / 8.0;
00636 ind_beta = 1 + (int)( ( betap_rad - ys_bl[sizey-1] ) / binw );
00637 }
00638 else
00639 {
00640 throw cms::Exception(" PixelErrorParametrization::error_YB") << " Wrong betap_rad = " << betap_rad;
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652 int index = 40*ind_sizey + 10*ind_alpha + ind_beta;
00653
00654 if ( index < 0 || index >= 240 )
00655 {
00656 throw cms::Exception(" PixelErrorParametrization::error_YB") << " Wrong index !!!";
00657 }
00658
00659 error_yb = vec_error_YB[index];
00660
00661 }
00662
00663
00664
00665
00666 return error_yb;
00667 }
00668
00669 }
00670
00671
00672 float PixelErrorParametrization::error_YF(int sizey, float alpha, float beta, bool bigInY)
00673 {
00674 if ( !useNewParametrization )
00675 {
00676 LogDebug("PixelErrorParametrization::error_YF") << "I'M AT THE BEGIN IN ERROR YF METHOD";
00677
00678 float err_par = 0.0;
00679
00680
00681 if ( bigInY && sizey == 1 )
00682 {
00683 err_par = pitch_y/sqrt(12.0);
00684 }
00685 else
00686 {
00687
00688 int i_size = min(sizey-1,1);
00689
00690 int i_alpha = 0;
00691
00692 float beta_prime = fabs(3.14159/2.-beta);
00693 if (beta_prime < brange_yf.first) beta_prime = brange_yf.first;
00694 if (beta_prime > brange_yf.second) beta_prime = brange_yf.second;
00695 err_par = 0.0;
00696 for(int ii=0; ii < (int)( (yforward_3D[i_size])[i_alpha] ).size(); ii++){
00697 err_par += ( (yforward_3D[i_size])[i_alpha] )[ii] * pow(beta_prime,ii);
00698 }
00699 }
00700
00701 return err_par;
00702 }
00703 else
00704 {
00705 float error_yf = -999.9;
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 if ( bigInY && sizey == 1 )
00719 {
00720
00721 error_yf = error_yf_big_pix;
00722 }
00723 else
00724 {
00725
00726
00727 float betap_rad = fabs( math_pi/2.0 - beta );
00728
00729
00730 if ( sizey > 2 ) sizey = 2;
00731
00732 int ind_sizey = sizey - 1;
00733 int ind_beta = -9999;
00734
00735 if ( betap_rad <= 0.3 ) ind_beta = 0;
00736 else if ( betap_rad >= 0.4 ) ind_beta = 9;
00737 else
00738 ind_beta = (int) ( ( betap_rad - 0.3 ) / ( ( 0.4 - 0.3 ) / 10.0 ) );
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748 int index = 10*ind_sizey + ind_beta;
00749
00750 if ( index < 0 || index >= 20 )
00751 {
00752 throw cms::Exception(" PixelErrorParametrization::error_YF") << " Wrong index !!!";
00753 }
00754
00755 error_yf = vec_error_YF[index];
00756
00757 }
00758
00759
00760
00761
00762 return error_yf;
00763 }
00764
00765 }
00766
00767
00768
00769
00770
00771 float PixelErrorParametrization::interpolation(vector<float>& vector_1D,
00772 float& angle, pair<float,float>& range)
00773 {
00774
00775 if (angle < range.first)
00776 LogDebug("PixelErrorParametrization::interpolation") << " IT IS NOT NECESSARY TO DO AN INTERPOLATION";
00777
00778 float bin = (range.second-range.first)/float(vector_1D.size());
00779 float curr = range.first;
00780 int i_bin = -1;
00781 for(int i = 0; i< (int)vector_1D.size(); i++){
00782
00783 curr += bin;
00784 if (angle <= curr){
00785 i_bin = i;
00786 break;
00787 }
00788 }
00789
00790 float y1;
00791 float y2;
00792 float x1;
00793 float x2;
00794
00795 if(i_bin == 0){
00796 x1 = range.first + bin/2;
00797 x2 = x1 + bin;
00798 y1 = vector_1D[0];
00799 y2 = vector_1D[1];
00800 }else if ( i_bin == (int)(vector_1D.size()-1) || i_bin == -1){
00801 x2 = range.second - bin/2;
00802 x1 = x2 - bin;
00803 y2 = vector_1D[(vector_1D.size()-1)];
00804 y1 = vector_1D[(vector_1D.size()-2)];
00805 } else if ( (curr-angle) < bin/2){
00806 x1 = curr - bin/2;
00807 x2 = x1 + bin;
00808 y1 = vector_1D[i_bin];
00809 y2 = vector_1D[i_bin+1];
00810 } else {
00811 x2 = curr - bin/2;
00812 x1 = x2 - bin;
00813 y2 = vector_1D[i_bin];
00814 y1 = vector_1D[i_bin-1];
00815 }
00816 float y = ((y2-y1)*angle + (y1*x2-y2*x1))/(x2-x1);
00817
00818
00819 LogDebug("PixelErrorParametrization::interpolation") << "INTERPOLATION GIVES"
00820 << " (x1,y1) = " << x1 << " , " << y1
00821 << " (x2,y2) = " << x2 << " , " << y2
00822 << "(angle,y) = " << angle << " , " << y;
00823
00824 return y;
00825 }
00826
00827
00828
00829
00830
00831
00832 int PixelErrorParametrization::betaIndex(int& i_size, vector<float>& betabins,
00833 float& beta)
00834 {
00835 int i_beta = -1;
00836
00837 float beta_prime = fabs(3.14159/2.-beta);
00838 for(int i = 0; i < (int)betabins.size(); i++){
00839 if (beta_prime < betabins[i]) {
00840 i_beta = i;
00841 break;
00842 }
00843 }
00844 if (i_beta < 0) i_beta = betabins.size();
00845 return i_beta;
00846 }
00847
00848
00849
00850
00851
00852
00853
00854
00855 float PixelErrorParametrization::linParametrize(bool& barrelPart, int& i_size,
00856 int& i_angle1, float& angle2)
00857 {
00858 LogDebug("PixelErrorParametrization::linParametrize") << "We are in linParametrize metod"
00859 << "barrel? " << barrelPart
00860 << "size index = " << i_size
00861 << "angle index = " << i_angle1
00862 << "angle variable = " << angle2;
00863
00864 float par0 = 0;
00865 float par1 = 0;
00866 if (barrelPart) {
00867 par0 = ((xbarrel_3D[i_size])[i_angle1])[0];
00868 par1 = ((xbarrel_3D[i_size])[i_angle1])[1];
00869 } else {
00870 par0 = ((xforward_3D[i_size])[i_angle1])[0];
00871 par1 = ((xforward_3D[i_size])[i_angle1])[1];
00872 }
00873
00874 LogDebug("PixelErrorParametrization::linParametrize") << "PAR0 = " << par0
00875 << "PAR1 = " << par1
00876 << "PAR1 = " << angle2
00877 << "X error = " << (par0 + par1*angle2);
00878
00879 return par0 + par1*angle2;
00880 }
00881
00882
00883
00884
00885
00886
00887
00888
00889 float PixelErrorParametrization::quadParametrize(bool& barrelPart, int& i_size,
00890 int& i_angle1, float& angle2)
00891 {
00892 LogDebug("PixelErrorParametrization::quadParametrize") << "barrel? " << barrelPart
00893 << "size index = " << i_size
00894 << "angle index = " << i_angle1
00895 << "angle variable = " << angle2;
00896
00897 float par0 = 0;
00898 float par1 = 0;
00899 float par2 = 0;
00900 if (barrelPart) {
00901 par0 = ((xbarrel_3D[i_size])[i_angle1])[0];
00902 par1 = ((xbarrel_3D[i_size])[i_angle1])[1];
00903 par2 = ((xbarrel_3D[i_size])[i_angle1])[2];
00904 } else {
00905 par0 = ((xforward_3D[i_size])[i_angle1])[0];
00906 par1 = ((xforward_3D[i_size])[i_angle1])[1];
00907 par2 = ((xforward_3D[i_size])[i_angle1])[2];
00908 }
00909
00910 LogDebug("PixelErrorParametrization::quadParametrize") << "PAR0 = " << par0
00911 << "PAR1 = " << par1
00912 << "PAR2 = " << par1
00913 << "ANGLE = " << angle2
00914 << "X error = " << (par0 + par1*angle2 + par2*angle2*angle2);
00915
00916 return par0 + par1*angle2 + par2*angle2*angle2;
00917 }
00918
00919
00920
00921
00922
00923
00924
00925 void PixelErrorParametrization::readYB( P3D& vec3D, const string& prefix,
00926 const string& postfix1, const string& postfix2)
00927 {
00928 vec3D.clear();
00929
00930
00931
00932 for(int i_pix = 1; i_pix <7; i_pix++ ) {
00933
00934 P2D tmp2D;
00935 if(i_pix < 4){
00936 for (int i_abin = 1; i_abin < 4; i_abin++) {
00937 ostringstream filename;
00938 filename << prefix << i_pix << postfix1 << i_abin << postfix2;
00939
00940
00941 tmp2D.push_back( readVec( filename.str() ));
00942 }
00943 } else {
00944 ostringstream filename;
00945 filename << prefix << i_pix << postfix1 << '0' << postfix2;
00946
00947 tmp2D.push_back( readVec( filename.str() ));
00948 }
00949 vec3D.push_back(tmp2D);
00950 }
00951 }
00952
00953
00954
00955
00956
00957
00958 void PixelErrorParametrization::readXB( P3D& vec3D, const string& prefix,
00959 const string& postfix1, const string& postfix2)
00960 {
00961 vec3D.clear();
00962
00963 for(int i_pix = 1; i_pix <4; i_pix++ ) {
00964 P2D tmp2D;
00965 if ( i_pix == 1 ){
00966
00967
00968
00969 ostringstream filename;
00970 filename << prefix << i_pix << postfix1 << '0' << postfix2;
00971 tmp2D.push_back( readVec( filename.str() ));
00972 } else {
00973 for (int i_bbin = 1; i_bbin < 5; i_bbin++) {
00974
00975
00976 ostringstream filename;
00977 filename << prefix << i_pix << postfix1 << i_bbin << postfix2;
00978 tmp2D.push_back( readVec( filename.str() ));
00979 }
00980 }
00981 vec3D.push_back(tmp2D);
00982 }
00983 }
00984
00985
00986
00987
00988
00989
00990 void PixelErrorParametrization::readF( P3D& vec3D, const string& prefix,
00991 const string& postfix1, const string& postfix2)
00992 {
00993 vec3D.clear();
00994 int maxPix = 3;
00995 if ( prefix == "xpar_npix" ) maxPix=4;
00996 for(int i_pix = 1; i_pix <maxPix; i_pix++ ) {
00997 P2D tmp2D;
00998
00999
01000 ostringstream filename;
01001 filename << prefix << i_pix << postfix1 << '0' << postfix2;
01002
01003 tmp2D.push_back(readVec( filename.str() ));
01004 vec3D.push_back(tmp2D);
01005 }
01006 }
01007
01008
01009
01010
01011
01012
01013
01014
01015 vector<float> PixelErrorParametrization::readVec( const string& name)
01016 {
01017 string partialName = "RecoLocalTracker/SiPixelRecHits/data/";
01018 if (theParametrizationType == "cmsim") {
01019 partialName += theParametrizationType + "/";
01020 }
01021 string fullName = partialName + name;
01022 edm::FileInPath f1( fullName );
01023 ifstream invec( (f1.fullPath()).c_str() );
01024
01025 vector<float> result;
01026 copy(istream_iterator<float>(invec),
01027 istream_iterator<float>(), back_inserter(result));
01028
01029 return result;
01030 }
01031