00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "AtlfastAlgs/MuonAcceptor.h"
00013
00014 #include "CLHEP/Random/JamesRandom.h"
00015 #include "CLHEP/Random/RandGauss.h"
00016 #include "CLHEP/Units/SystemOfUnits.h"
00017
00018 #include <iostream>
00019 #include <fstream>
00020 #include <iostream>
00021 #include <sstream>
00022 #include <cmath>
00023
00024 #include "PathResolver/PathResolver.h"
00025
00026
00027
00028 namespace Atlfast {
00029
00030 using std::abs;
00031 using std::pair;
00032 using std::make_pair;
00033
00034
00035
00036
00037
00038 muEffdata::muEffdata(){}
00039 muEffdata::~muEffdata(){}
00040
00041
00042 void muEffdata::Print(std::ostream* out){
00043 *out <<std::setw(12)<<std::setprecision(3)<<GetPt()
00044 <<std::setw(12)<<std::setprecision(3)<<GetEtaMin()
00045 <<std::setw(12)<<std::setprecision(3)<<GetEtaMax()
00046 << std::endl;
00047 }
00048
00049 void muEffdata::SetPt (double pt) { m_pt = pt ;}
00050 void muEffdata::SetEtaMin (double etamin) { m_etamin = etamin ;}
00051 void muEffdata::SetEtaMax (double etamax) { m_etamax = etamax ;}
00052 void muEffdata::SetPtEtaNum(std::vector<int> ptEtaNum){m_ptEtaNum=ptEtaNum;}
00053
00054 void muEffdata::SetPtEtaNumeDeno(std::vector<std::pair<int, int> > VecPaire)
00055 {m_VecPaire = VecPaire;}
00056
00057 double muEffdata::GetPt() {return m_pt ;}
00058 double muEffdata::GetEtaMin(){return m_etamin;}
00059 double muEffdata::GetEtaMax(){return m_etamax;}
00060 int muEffdata::GetPtEtaNum(std::vector<int> &ptEtaNum){
00061
00062 int SizeOfVectorOfmuEffdata = m_ptEtaNum.size();
00063 ptEtaNum = m_ptEtaNum;
00064 return SizeOfVectorOfmuEffdata;
00065
00066 }
00067
00068 void muEffdata::GetPtEtaNumeDeno(double &pt,double &etamin,double &etamax,
00069 std::vector<std::pair<int, int> > &VecPaire){
00070
00071 pt = m_pt ;
00072 etamin = m_etamin ;
00073 etamax = m_etamax ;
00074 VecPaire = m_VecPaire;
00075
00076 }
00077
00078 muEffdata::muEffdata(double &pt,double &etamin,double &etamax,
00079 std::vector<std::pair<int, int> > &VecPaire){
00080
00081 pt = m_pt ;
00082 etamin = m_etamin ;
00083 etamax = m_etamax ;
00084 VecPaire = m_VecPaire;
00085
00086 }
00087
00088
00089
00090
00091
00092 MuonAcceptor::MuonAcceptor(int muSmearKey, MsgStream& log) : m_log(log) {
00093
00094 m_log << MSG::DEBUG << "MuonAcceptor::MuonAcceptor" << endreq;
00095
00096 m_randomEngine = new HepJamesRandom(12345);
00097
00098
00099
00100 std::string filename = muSmearKey == 1 ?
00101 "atlfastDatafiles/MuonSpectrometerEff.txt" :
00102 "atlfastDatafiles/MuonCombinedEff.txt";
00103 filename = PathResolver::find_file (filename, "DATAPATH");
00104 m_log << MSG::DEBUG << "Opening file: " << filename << endreq;
00105 std::ifstream InputFile;
00106 InputFile.open(filename.c_str());
00107 if(!InputFile) {
00108 m_log << MSG::ERROR << "Error: file could not be opened" << endreq;
00109 exit(1);
00110 }
00111
00112 std::vector<muEffdata>VectorOfmuEffdata;
00113 std::vector<std::pair<int, int> > ptEtaNumeDeno;
00114 VectorOfmuEffdata.clear();
00115 ptEtaNumeDeno.clear();
00116
00117 m_muEffdataObject.clear();
00118 m_ptValues.clear();
00119 m_etaminValues.clear();
00120 m_etamaxValues.clear();
00121
00122
00123
00124 int Istatus = 1;
00125 while ( Istatus == 1 ) {
00126
00127
00128
00129 Istatus = muReadEff(InputFile,VectorOfmuEffdata);
00130
00131 if (Istatus == 1){
00132
00133 std::vector<int> ptEtaNum;
00134 int SizeOfVectorOfmuEffdata = VectorOfmuEffdata.size() ;
00135 for (int Item=0; Item <SizeOfVectorOfmuEffdata ; Item++){
00136 double pt;double etamin;double etamax;
00137 VectorOfmuEffdata[Item].GetPtEtaNumeDeno(pt,etamin,etamax,ptEtaNumeDeno);
00138 m_muEffdataObject.push_back(VectorOfmuEffdata[Item]);
00139 m_ptValues.push_back(pt);
00140 m_etaminValues.push_back(etamin);
00141 m_etamaxValues.push_back(etamax);
00142 }
00143 }
00144 }
00145
00146 InputFile.close();
00147 m_log << MSG::DEBUG << "Done with MuonAcceptor constructor" << endreq;
00148 }
00149
00150 bool MuonAcceptor::accept( const ReconstructedParticle &particle, MsgStream &log ){
00151
00152 log << MSG::DEBUG << "MuonAcceptor::accept" << endreq;
00153
00154
00155 double pTinGeV = particle.pT() / GeV;
00156
00157 double muEff = muEfficiency(pTinGeV,
00158 particle.eta(),
00159 particle.phi()).first;
00160 log << MSG::DEBUG << "pT,eta,phi,efficiency = " << pTinGeV
00161 << "," << particle.eta() << ","
00162 << particle.phi() << "," << muEff << endreq;
00163 double random = m_randomEngine->flat();
00164 log << MSG::DEBUG << "random = " << random << endreq;
00165 return ( random < muEff) ? true : false;
00166 }
00167
00168
00169 int MuonAcceptor::muReadEff(std::ifstream& InputFile,
00170 std::vector<muEffdata>& VectorOfmuEffdata){
00171
00172 VectorOfmuEffdata.clear();
00173
00174 std::vector<int> ptEtaNume;
00175 std::vector<int> ptEtaDeno;
00176
00177 std::vector<int> ptEtaNume1;
00178 std::vector<int> ptEtaDeno1;
00179
00180 std::vector<int> ptEtaNume2;
00181 std::vector<int> ptEtaDeno2;
00182
00183 std::vector<int> ptEtaNume3;
00184 std::vector<int> ptEtaDeno3;
00185
00186 std::vector<int> ptEtaNume4;
00187 std::vector<int> ptEtaDeno4;
00188
00189 std::vector<std::pair<int, int> > VecPaire;
00190 std::pair<int, int> mapaire;
00191
00192 std::vector<std::pair<int, int> > VecPaire1;
00193 std::pair<int, int> mapaire1;
00194
00195 std::vector<std::pair<int, int> > VecPaire2;
00196 std::pair<int, int> mapaire2;
00197
00198 std::vector<std::pair<int, int> > VecPaire3;
00199 std::pair<int, int> mapaire3;
00200
00201 std::vector<std::pair<int, int> > VecPaire4;
00202 std::pair<int, int> mapaire4;
00203
00204 ptEtaNume.clear();
00205 ptEtaDeno.clear();
00206 ptEtaNume1.clear();
00207 ptEtaDeno1.clear();
00208 ptEtaNume2.clear();
00209 ptEtaDeno2.clear();
00210 ptEtaNume3.clear();
00211 ptEtaDeno3.clear();
00212 ptEtaNume4.clear();
00213 ptEtaDeno4.clear();
00214
00215 muEffdata pmuEffdata;
00216
00217 if(!InputFile) return 0;
00218 if(InputFile.eof()) return 0;
00219
00220 double pt;
00221 double etamin,etamax;
00222 int nBin;
00223 int nnum,ndeno;
00224
00225 if(InputFile.eof()) return 0;
00226 InputFile >> pt;
00227 if(InputFile.eof()) return 0;
00228 InputFile >>etamin>>etamax>>nBin;
00229 if(InputFile.eof()) return 0;
00230
00231 pmuEffdata.SetPt(pt);
00232 pmuEffdata.SetEtaMin(etamin );
00233 pmuEffdata.SetEtaMax(etamax);
00234
00235 for (int ibin=0; ibin < nBin ; ibin++){
00236 if(InputFile.eof()) return 0;
00237 InputFile >> nnum ;
00238 ptEtaNume.push_back(nnum);
00239 }
00240 if(InputFile.eof()) return 0;
00241 for (int ibin=0; ibin < nBin ; ibin++){
00242 if(InputFile.eof()) return 0;
00243 InputFile >> ndeno ;
00244 ptEtaDeno.push_back(ndeno);
00245 }
00246 pmuEffdata.SetPtEtaNum(ptEtaNume);
00247 pmuEffdata.SetPtEtaNum(ptEtaDeno);
00248
00249 int SizeOfptEtaNume =ptEtaNume.size();
00250 for(int i=0;i<SizeOfptEtaNume;i++){
00251 mapaire.first=ptEtaNume[i];
00252 mapaire.second = ptEtaDeno[i];
00253 VecPaire.push_back(mapaire);
00254 }
00255 pmuEffdata.SetPtEtaNumeDeno(VecPaire);
00256
00257
00258 if(InputFile.eof()) return 0;
00259
00260 VectorOfmuEffdata.push_back(pmuEffdata);
00261
00262 int nBin1 =0;
00263 double etamin1=0;
00264 double etamax1=0;
00265 int ndeno1=0;
00266 int nnum1=0;
00267
00268 InputFile >>etamin1>>etamax1>>nBin1;
00269 if(InputFile.eof()) return 0;
00270
00271 pmuEffdata.SetEtaMin(etamin1 );
00272 pmuEffdata.SetEtaMax(etamax1);
00273
00274 for (int Item=0; Item < nBin1 ; Item++){
00275 if(InputFile.eof()) return 0;
00276 InputFile >> nnum1 ;
00277 ptEtaNume1.push_back(nnum1);
00278 }
00279 if(InputFile.eof()) return 0;
00280 for (int Item=0; Item < nBin1 ; Item++){
00281 if(InputFile.eof()) return 0;
00282 InputFile >> ndeno1 ;
00283 ptEtaDeno1.push_back(ndeno1);
00284 }
00285 pmuEffdata.SetPtEtaNum(ptEtaNume1);
00286 pmuEffdata.SetPtEtaNum(ptEtaDeno1);
00287
00288
00289 if(InputFile.eof()) return 0;
00290
00291 int SizeOfptEtaNume1 =ptEtaNume1.size();
00292 for(int i=0;i<SizeOfptEtaNume1;i++){
00293 mapaire1.first=ptEtaNume1[i];
00294 mapaire1.second = ptEtaDeno1[i];
00295 VecPaire1.push_back(mapaire1);
00296 }
00297 pmuEffdata.SetPtEtaNumeDeno(VecPaire1);
00298 VectorOfmuEffdata.push_back(pmuEffdata);
00299
00300
00301 int nBin2 =0;
00302 double etamin2=0;
00303 double etamax2=0;
00304 int ndeno2=0;
00305 int nnum2=0;
00306
00307 InputFile >>etamin2>>etamax2>>nBin2;
00308 if(InputFile.eof()) return 0;
00309
00310 pmuEffdata.SetEtaMin(etamin2 );
00311 pmuEffdata.SetEtaMax(etamax2);
00312
00313 for (int Item=0; Item < nBin2 ; Item++){
00314 if(InputFile.eof()) return 0;
00315 InputFile >> nnum2 ;
00316 ptEtaNume2.push_back(nnum2);
00317 }
00318 if(InputFile.eof()) return 0;
00319 for (int Item=0; Item < nBin2 ; Item++){
00320 if(InputFile.eof()) return 0;
00321 InputFile >> ndeno2 ;
00322 ptEtaDeno2.push_back(ndeno2);
00323 }
00324 pmuEffdata.SetPtEtaNum(ptEtaNume2);
00325 pmuEffdata.SetPtEtaNum(ptEtaDeno2);
00326
00327
00328 if(InputFile.eof()) return 0;
00329
00330 int SizeOfptEtaNume2 =ptEtaNume2.size();
00331 for(int i=0;i<SizeOfptEtaNume2;i++){
00332 mapaire2.first=ptEtaNume2[i];
00333 mapaire2.second = ptEtaDeno2[i];
00334 VecPaire2.push_back(mapaire2);
00335 }
00336 pmuEffdata.SetPtEtaNumeDeno(VecPaire2);
00337 VectorOfmuEffdata.push_back(pmuEffdata);
00338
00339
00340
00341 int nBin3 =0;
00342 double etamin3=0;
00343 double etamax3=0;
00344 int ndeno3=0;
00345 int nnum3=0;
00346
00347 InputFile >>etamin3>>etamax3>>nBin3;
00348 if(InputFile.eof()) return 0;
00349
00350 pmuEffdata.SetEtaMin(etamin3 );
00351 pmuEffdata.SetEtaMax(etamax3);
00352
00353 for (int Item=0; Item < nBin3 ; Item++){
00354 if(InputFile.eof()) return 0;
00355 InputFile >> nnum3 ;
00356 ptEtaNume3.push_back(nnum3);
00357 }
00358 if(InputFile.eof()) return 0;
00359 for (int Item=0; Item < nBin3 ; Item++){
00360 if(InputFile.eof()) return 0;
00361 InputFile >> ndeno3 ;
00362 ptEtaDeno3.push_back(ndeno3);
00363 }
00364 pmuEffdata.SetPtEtaNum(ptEtaNume3);
00365 pmuEffdata.SetPtEtaNum(ptEtaDeno3);
00366
00367
00368 if(InputFile.eof()) return 0;
00369
00370 int SizeOfptEtaNume3 =ptEtaNume3.size();
00371 for(int i=0;i<SizeOfptEtaNume3;i++){
00372 mapaire3.first=ptEtaNume3[i];
00373 mapaire3.second = ptEtaDeno3[i];
00374 VecPaire3.push_back(mapaire3);
00375 }
00376 pmuEffdata.SetPtEtaNumeDeno(VecPaire3);
00377 VectorOfmuEffdata.push_back(pmuEffdata);
00378
00379
00380
00381
00382 int nBin4 =0;
00383 double etamin4=0;
00384 double etamax4=0;
00385 int ndeno4=0;
00386 int nnum4=0;
00387
00388 InputFile >>etamin4>>etamax4>>nBin4;
00389 if(InputFile.eof()) return 0;
00390
00391 pmuEffdata.SetEtaMin(etamin4 );
00392 pmuEffdata.SetEtaMax(etamax4);
00393
00394 for (int Item=0; Item < nBin4 ; Item++){
00395 if(InputFile.eof()) return 0;
00396 InputFile >> nnum4 ;
00397 ptEtaNume4.push_back(nnum4);
00398 }
00399 if(InputFile.eof()) return 0;
00400 for (int Item=0; Item < nBin4 ; Item++){
00401 if(InputFile.eof()) return 0;
00402 InputFile >> ndeno4 ;
00403 ptEtaDeno4.push_back(ndeno4);
00404 }
00405 pmuEffdata.SetPtEtaNum(ptEtaNume4);
00406 pmuEffdata.SetPtEtaNum(ptEtaDeno4);
00407
00408
00409 if(InputFile.eof()) return 0;
00410
00411 int SizeOfptEtaNume4 =ptEtaNume4.size();
00412 for(int i=0;i<SizeOfptEtaNume4;i++){
00413 mapaire4.first=ptEtaNume4[i];
00414 mapaire4.second = ptEtaDeno4[i];
00415 VecPaire4.push_back(mapaire4);
00416 }
00417 pmuEffdata.SetPtEtaNumeDeno(VecPaire4);
00418 VectorOfmuEffdata.push_back(pmuEffdata);
00419
00420
00421 return 1;
00422 }
00423
00424
00425
00426 std::pair<double,double>
00427 MuonAcceptor::muEfficiency(double ptIn,double etaIn, double phi)
00428 {
00429
00430 double efficiency =0;
00431 double errEfficiency =0;
00432
00433 double eta = fabs(etaIn);
00434 double pt = fabs(ptIn);
00435
00436
00437 double pt1 = 0.;
00438 double pt2 = 0.;
00439
00440
00441 std::pair<double,double>ptLowHigh;
00442 ptLowHigh= muGetPtLowHigh(pt);
00443 pt1 = ptLowHigh.first;
00444 pt2 = ptLowHigh.second;
00445
00446 if(pt >= pt1 && pt < pt2){
00447 std::pair<double,double> eff1_errff1;
00448 std::pair<double,double> eff2_errff2;
00449
00450 eff1_errff1 = muEff(pt1,eta,phi);
00451 eff2_errff2 = muEff(pt2,eta,phi);
00452
00453 double eff1 = eff1_errff1.first ;
00454 double eeff1 = eff1_errff1.second;
00455
00456 double eff2 = eff2_errff2.first;
00457 double eeff2 = eff2_errff2.second;
00458
00459 efficiency = eff2 *log(pt/pt1)/log(pt2/pt1);
00460 efficiency = efficiency + eff1 *log(pt2/pt)/log(pt2/pt1);
00461 errEfficiency = pow((eeff2*log(pt/pt1)/log(pt2/pt1)),2);
00462 errEfficiency = errEfficiency +pow((eeff1*log(pt2/pt)/log(pt2/pt1)),2);
00463 errEfficiency = sqrt(errEfficiency);
00464 }
00465
00466 if(efficiency < 0){
00467 efficiency =0.;
00468 errEfficiency=0.;
00469 }
00470 if(efficiency > 1){
00471 efficiency =1.;
00472 errEfficiency=0.;
00473 }
00474
00475 return make_pair(efficiency,errEfficiency);
00476 }
00477
00478 std::pair<double,double>
00479 MuonAcceptor::muEff(double ptIn,double etaIn, double phi)
00480 {
00481 double eta = fabs(etaIn);
00482 double pt = fabs(ptIn);
00483
00484 double xEtaMinOut = 0.;
00485 double xEtaMaxOut = 2.5;
00486
00487 int nNumOut = 0;
00488 int nDenoOut = 0;
00489
00490 int nNumTotOut = 0;
00491 int nDenoTotOut= 0;
00492
00493 int iEtaBin = muGetEtaBin(eta);
00494
00495 std::vector<std::pair<int, int> > ptEtaNumeDeno;
00496 ptEtaNumeDeno.clear();
00497 ptEtaNumeDeno= muEffGetPaire(pt,xEtaMinOut,xEtaMaxOut);
00498
00499 nNumOut=ptEtaNumeDeno[iEtaBin].first;
00500 nDenoOut=ptEtaNumeDeno[iEtaBin].second;
00501
00502 int nBinOut = ptEtaNumeDeno.size();
00503
00504 for(unsigned int i=0 ; i<ptEtaNumeDeno.size() ; i++){
00505 nNumTotOut = nNumTotOut+ptEtaNumeDeno[i].first;
00506 nDenoTotOut = nDenoTotOut+ptEtaNumeDeno[i].second;
00507 }
00508
00509 double eff1 = double(nNumOut)/double(nDenoOut);
00510 double eeff1 = sqrt(eff1*(1.-eff1)/double(nDenoOut));
00511 double delta = (xEtaMaxOut-xEtaMinOut)/double(nBinOut) ;
00512 double xcbin1 = xEtaMinOut+delta/2.+delta*double(iEtaBin) ;
00513
00514 muPhiEfficiency(pt,xcbin1,phi,eff1,eeff1);
00515
00516 return make_pair(eff1,eeff1);
00517 }
00518
00519 int MuonAcceptor::muGetEtaBin(double etaIn){
00520
00521 int iEtaBin = -1;
00522 double eta = fabs(etaIn);
00523
00524 double xMaxOut =2.5;
00525 double xMinOut = 0.;
00526 double pt=50.;
00527
00528 std::vector<std::pair<int, int> > ptEtaNumeDeno;
00529 ptEtaNumeDeno.clear();
00530 ptEtaNumeDeno= muEffGetPaire(pt,xMinOut,xMaxOut);
00531
00532 int NbinOut = ptEtaNumeDeno.size();
00533
00534 double delta=double(xMaxOut-xMinOut)/double(NbinOut);
00535 iEtaBin = int(floor(eta/delta));
00536 if( iEtaBin >= NbinOut) iEtaBin= NbinOut-1;
00537
00538 return iEtaBin;
00539 }
00540
00541 void MuonAcceptor::muPhiEfficiency(double pt,double etaIn,double phi,double &eff,double &eeff){
00542
00543 double pi = 3.1415927;
00544 double phig = phi;
00545 if (phi < 0.) {
00546 phig = pi*2 + phi;
00547 }
00548
00549 double effin = eff;
00550
00551
00552 double eta = fabs(etaIn);
00553
00554
00555
00556
00557
00558 double etamin1 = 0.;
00559 double etamax1 = 0.15;
00560 if (eta >= etamin1 && eta < etamax1) {
00561 double pion4 = pi/4.;
00562 double pion8 = pi/8.;
00563 double phig2 = fmod(phig,pion4);
00564 if (phig2 >= pion8) phig2 = pion4-phig2;
00565
00566 std::pair<double,double> eff_erreff;
00567 eff_erreff = getPhiEff(pt,effin,phig2,etamin1,etamax1);
00568 eff = eff_erreff.first ;
00569 eeff = eff_erreff.second;
00570 }
00571
00572
00573
00574
00575
00576 double etamin2 = 0.3;
00577 double etamax2 = 0.4;
00578 double etamin22 = 0.8;
00579 double etamax22 = 0.9;
00580 if ((eta >= etamin2 && eta < etamax2) ||
00581 (eta >= etamin22 && eta < etamax22) ) {
00582 std::pair<double,double> eff_erreff;
00583 eff_erreff = getPhiEff(pt,effin,phig,etamin2,etamax2);
00584 eff = eff_erreff.first ;
00585 eeff = eff_erreff.second;
00586 }
00587
00588
00589
00590 double etamin3 =1.05;
00591 double etamax3 =1.15;
00592 if (eta >= etamin3 && eta < etamax3) {
00593
00594 std::pair<double,double> eff_erreff;
00595 eff_erreff = getPhiEff(pt,effin,phig,etamin3,etamax3);
00596 eff = eff_erreff.first ;
00597 eeff = eff_erreff.second;
00598 }
00599
00600
00601
00602
00603 double etamin4 =1.20;
00604 double etamax4 =1.25;
00605
00606 if (eta >= etamin4 && eta < etamax4) {
00607
00608 std::pair<double,double> eff_erreff;
00609 eff_erreff = getPhiEff(pt,effin,phig,etamin4,etamax4);
00610 eff = eff_erreff.first ;
00611 eeff = eff_erreff.second;
00612 }
00613
00614 }
00615
00616
00617 int MuonAcceptor::muGetPhiBin(double phi){
00618
00619 double pi = 3.1415927;
00620 int iPhiBin = -1;
00621
00622 double xMaxOut =360;
00623 double xMinOut = 0.;
00624 int NbinOut = 20;
00625
00626 double phig = phi;
00627 if (phi < 0.) {
00628 phig = pi*2 + phi;
00629 }
00630 double phideg = phig*180./ pi;
00631
00632 double delta=double(xMaxOut-xMinOut)/double(NbinOut);
00633 iPhiBin = int(floor(phideg/delta));
00634 if( iPhiBin >= NbinOut) iPhiBin= NbinOut-1;
00635
00636 return iPhiBin;
00637 }
00638
00639 int MuonAcceptor::muGetPhiBin1(double phi){
00640
00641 double pi = 3.1415927;
00642 int iPhiBin = -1;
00643
00644 double xMaxOut = 22.5;
00645 double xMinOut = 0.;
00646 int NbinOut = 20;
00647
00648 double phig = phi;
00649 if (phi < 0.) {
00650 phig = pi*2 + phi;
00651 }
00652 double phideg = phig*180./ pi;
00653
00654 double delta=double(xMaxOut-xMinOut)/double(NbinOut);
00655 iPhiBin = int(floor(phideg/delta));
00656 if( iPhiBin >= NbinOut) iPhiBin= NbinOut-1;
00657
00658 return iPhiBin;
00659 }
00660
00661
00662 std::pair<double,double>
00663 MuonAcceptor::getPhiEff(double pt,double effin,double phig,double etamin,double etamax)
00664 {
00665 double eff = 1.;
00666 double eeff =0.;
00667
00668 double phivalue[21];
00669 double efficiency[21];
00670 double errefficiency[21];
00671
00672 for (int j = 0; j < 21; j++) {
00673 efficiency[j] = 0.;
00674 errefficiency[j] = 0.;
00675 phivalue[j] = 0.;
00676 }
00677
00678 double pi = 3.1415927;
00679 double degrad = pi/180.;
00680
00681 for (int j = 0; j < 21; j++) {
00682 phivalue[j] = j*18.*degrad;
00683 if(etamin ==0. && etamax ==0.15)phivalue[j] = j*1.125*degrad;
00684 }
00685
00686
00687
00688 std::pair<double,double> eff_errff;
00689 double phiLow = phivalue[0];
00690 double phiHigh = phivalue[20];
00691 eff_errff = muPhiEff(pt,etamin,etamax,phiLow,phiHigh);
00692 efficiency[20] = eff_errff.first ;
00693 errefficiency[20] = eff_errff.second;
00694
00695
00696 double delta2 = 8.9*degrad;
00697 if(etamin ==0. && etamax ==0.15)delta2 = 0.55*degrad;
00698 for (int j = 0; j < 20; j++) {
00699 double phicenter = (phivalue[j+1]+phivalue[j])/2.;
00700 double phimin = phicenter - delta2;
00701 double phimax = phicenter + delta2;
00702 eff_errff = muPhiEff(pt,etamin,etamax,phimin,phimax);
00703 efficiency[j] = eff_errff.first ;
00704 errefficiency[j] = eff_errff.second;
00705 }
00706
00707 double averaefficiency = effin/efficiency[20];
00708 double factornorm = averaefficiency;
00709 if(factornorm > 1. || factornorm < 0.9)factornorm =1;
00710
00711 if (phig >= phivalue[0] && phig <= phivalue[1]) {
00712 eff = efficiency[0] * factornorm;
00713 eeff = errefficiency[0];
00714 }
00715 for (int j = 1; j < 20; j++) {
00716 if (phig > phivalue[j] && phig <= phivalue[j+1]) {
00717 eff = efficiency[j] * factornorm;
00718 eeff= errefficiency[j];
00719 }
00720 }
00721 if (phig > phivalue[20] && phig <= phivalue[21]) {
00722 eff = efficiency[19] * factornorm;
00723 eeff= errefficiency[19];
00724 }
00725
00726 if (eff < 0.) {
00727 eff = 0.;
00728 eeff = 0.;
00729 }
00730 if (eff > 1.) {
00731 eff = 1.;
00732 eeff =0.;
00733 }
00734
00735 return make_pair(eff,eeff);
00736 }
00737
00738
00739 std::pair<double,double>
00740 MuonAcceptor::muPhiEff(double pt,double etamin,double etamax,double phimin,double phimax){
00741
00742 int NnumTot=0 ;
00743 int NdenoTot=0;
00744
00745 double eff =0;
00746 double eeff=0;
00747
00748 int ibinmin;
00749 int ibinmax;
00750
00751 if(etamin==0. && etamax==0.15){
00752 ibinmin = muGetPhiBin1(phimin) ;
00753 ibinmax = muGetPhiBin1(phimax) ;
00754 }
00755 else{
00756 ibinmin = muGetPhiBin(phimin) ;
00757 ibinmax = muGetPhiBin(phimax) ;
00758 }
00759 std::vector<std::pair<int, int> > ptEtaNumeDeno;
00760 ptEtaNumeDeno.clear();
00761 ptEtaNumeDeno= muEffGetPaire(pt,etamin,etamax);
00762
00763 for (int ibin=ibinmin;ibin<=ibinmax;ibin++){
00764 NnumTot =NnumTot+ptEtaNumeDeno[ibin].first;
00765 NdenoTot=NdenoTot+ptEtaNumeDeno[ibin].second;
00766 }
00767
00768 eff =double(NnumTot)/double(NdenoTot);
00769 eeff=sqrt(eff*(1.-eff)/double(NdenoTot));
00770
00771 return make_pair(eff,eeff);
00772 }
00773
00774
00775 std::vector<std::pair<int, int> >
00776 MuonAcceptor::muEffGetPaire(double pt,double etamin,double etamax){
00777
00778 std::vector<std::pair<int, int> > vecPaireNumeDeno;
00779 vecPaireNumeDeno.clear();
00780
00781 std::vector<std::pair<int, int> > ptEtaNumeDeno;
00782 ptEtaNumeDeno.clear();
00783
00784 int iposition = muGetPaireNumeDenoPosi(pt,etamin,etamax);
00785
00786 if(iposition != -1){
00787 int i=iposition;
00788 m_muEffdataObject[i].GetPtEtaNumeDeno(pt,etamin,etamax,ptEtaNumeDeno);
00789 vecPaireNumeDeno=ptEtaNumeDeno;
00790 }
00791
00792 return vecPaireNumeDeno;
00793 }
00794
00795 int MuonAcceptor::muGetPaireNumeDenoPosi(double pt,double etamin,double etamax){
00796
00797 int iposition =-1;
00798 const double epsilon=1.e-6;
00799 for(unsigned int i= 0;i<m_ptValues.size();i++){
00800 if( fabs(pt-m_ptValues[i]) < epsilon &&
00801 fabs(etamin - m_etaminValues[i]) < epsilon &&
00802 fabs( etamax - m_etamaxValues[i]) < epsilon
00803 )
00804 iposition=i;
00805 }
00806 return iposition;
00807 }
00808
00809 std::pair<double,double>
00810 MuonAcceptor::muGetPtLowHigh(double pt){
00811
00812 std::pair<double,double> ptLowHigh;
00813
00814 int sizeOfptvalues = m_ptValues.size();
00815 double ptmin= m_ptValues.at(0);
00816 double ptmax= m_ptValues.at(sizeOfptvalues-1);
00817
00818 for (int i=0; i <sizeOfptvalues-1 ; i++){
00819 ptmin= m_ptValues[i];
00820 ptmax= m_ptValues[i+1];
00821 if(pt >=ptmin && ptmin<ptmax){
00822 double ptlow =m_ptValues[i] ;
00823 double pthigh =m_ptValues[i+1] ;
00824 ptLowHigh=make_pair(ptlow,pthigh);
00825 }
00826 }
00827 if(pt>=m_ptValues.at(sizeOfptvalues-1)){
00828 double ptlow = m_ptValues.at(sizeOfptvalues-2);
00829 double pthigh = m_ptValues.at(sizeOfptvalues-1);
00830 ptLowHigh=make_pair(ptlow,pthigh);
00831 }
00832 if(pt <=m_ptValues.at(0)){
00833 double ptlow = m_ptValues.at(0);
00834 double pthigh = m_ptValues.at(0) ;
00835 ptLowHigh=make_pair(ptlow,pthigh);
00836 }
00837 return ptLowHigh ;
00838 }
00839
00840 }