CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/FastSimulation/Muons/src/FML1EfficiencyHandler.cc

Go to the documentation of this file.
00001 #include <fstream>
00002 
00003 #include "FastSimulation/Muons/interface/FML1EfficiencyHandler.h"
00004 #include "FastSimDataFormats/L1GlobalMuonTrigger/interface/SimpleL1MuGMTCand.h"
00005 
00006 #include "Utilities/General/interface/FileInPath.h"
00007 #include "Utilities/General/interface/CMSexception.h"
00008 
00009 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00010 
00011 using namespace std;
00012 
00013 FML1EfficiencyHandler::FML1EfficiencyHandler(const RandomEngine * engine)
00014   : random(engine){
00015 
00016    string fname = "FastSimulation/Muons/data/efficiencyL1.data";
00017    //   std::string path(std::getenv("CMSSW_SEARCH__PATH"));
00018    std::string path(getenv("CMSSW_SEARCH_PATH"));
00019    FileInPath f1(path,fname);
00020    if ( f1() == 0) {
00021      std::cout << "File " << fname << " not found in " << path << std::endl;
00022      throw Genexception(" efficiency list not found for FML1EfficiencyHandler.");
00023    } else {
00024      // The following should be on LogDebug
00025      //std::cout << "Reading " << f1.name() << std::endl;
00026    }
00027    std::ifstream & listfile = *f1();
00028 
00029    double eff=0.;
00030    for (int i=0; i<nEtaBins; i++) {
00031      listfile >> eff;
00032      Effic_Eta[i]=eff;
00033    }
00034    int iStart=nEtaBins;
00035    for (int i=iStart; i<iStart+nPhiBins; i++) {
00036      listfile >> eff;
00037      Effic_Phi_Barrel[i-iStart]=eff;
00038    }
00039    iStart += nPhiBins;
00040    for (int i=iStart; i<iStart+nPhiBins; i++) {
00041      listfile >> eff;
00042      Effic_Phi_Endcap[i-iStart]=eff;
00043    }
00044    iStart += nPhiBins;
00045    for (int i=iStart; i<iStart+nPhiBins; i++) {
00046      listfile >> eff;
00047      Effic_Phi_Extern[i-iStart]=eff;
00048    }
00049 
00050 }
00051 
00052 FML1EfficiencyHandler::~FML1EfficiencyHandler() {}
00053 
00054 
00055 bool FML1EfficiencyHandler::kill(const SimpleL1MuGMTCand * aMuon) {
00056 
00057   double myEffEta=0. , myEffPhi=0. , myEff;
00058   double AbsEta = fabs(aMuon->getMomentum().eta());
00059   double Phi = aMuon->getMomentum().phi();
00060   double Pt = std::sqrt(aMuon->getMomentum().perp2());
00061 
00062 // efficiency as a function of |eta|
00063   
00064   if (AbsEta < 2.40) {
00065     int iEtaBin = (int) ( (AbsEta/2.40) * nEtaBins);
00066     myEffEta = Effic_Eta[iEtaBin];
00067   } else { myEffEta = 0.0; }
00068 
00069 // efficiency as a function of phi and combined efficiency:
00070   
00071   if (Phi < 0.) {Phi = 2* M_PI + Phi; }
00072   int iPhiBin = (int) ((Phi/(2*M_PI)) * nPhiBins);
00073 
00074   int ieta = 0;
00075   if (AbsEta < 1.04) {
00076     myEffPhi = Effic_Phi_Barrel[iPhiBin];
00077     myEff = myEffEta * myEffPhi * tuningfactor(0);
00078     ieta = 0;
00079   } else if (AbsEta < 2.07) {
00080     myEffPhi = Effic_Phi_Endcap[iPhiBin];
00081     myEff = myEffEta * myEffPhi * tuningfactor(1);
00082     ieta = 1;
00083   } else if (AbsEta < 2.40) {
00084     myEffPhi = Effic_Phi_Extern[iPhiBin];
00085     myEff = myEffEta * myEffPhi * tuningfactor(2);
00086     ieta = 2;
00087  } else { myEff = 0. ; }
00088 
00089 // Drop of efficiency at the lowest Pt's:
00090   if (Pt<6) myEff *= dumpingfactor(ieta,Pt);  
00091    
00092   double prob =  random->flatShoot();
00093 
00094   return (myEff > prob);
00095 }