CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 
00002 #include "FastSimulation/Muons/interface/FML1PtSmearer.h"
00003 #include "FastSimDataFormats/L1GlobalMuonTrigger/interface/SimpleL1MuGMTCand.h"
00004 
00005 #include "Utilities/General/interface/FileInPath.h"
00006 #include "Utilities/General/interface/CMSexception.h"
00007 
00008 #include <cmath>
00009 #include <iostream>
00010 #include <fstream>
00011 
00012 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00013 
00014 using namespace std;
00015 
00016 FML1PtSmearer::FML1PtSmearer(const RandomEngine * engine)
00017   : random(engine) {
00018 
00019   string fname = "FastSimulation/Muons/data/resolutionL1.data";
00020   //   std::string path(std::getenv("CMSSW_SEARCH__PATH"));
00021   std::string path(getenv("CMSSW_SEARCH_PATH"));
00022   FileInPath f1(path,fname);
00023   if ( f1() == 0) {
00024     std::cout << "File " << fname << " not found in " << path << std::endl;
00025     throw Genexception(" resolution list not found for FastMuonLvl1Trigger.");
00026   } else {
00027     // The following should be on LogInfo
00028     //cout << "Reading " << f1.name() << std::endl;
00029   }
00030   std::ifstream & listfile = *f1();
00031    
00032   int ind;
00033   float num=0.;
00034   for (int ieta=0; ieta<3; ieta++) {
00035     for (int i=0; i<NPT; i++) {
00036       float sum = 0.;
00037       ind = i*NPTL1 + ieta*(NPT*NPTL1);
00038       for (int j=0; j<NPTL1; j++) {
00039         listfile >> num;
00040         sum += num;
00041         resolution[ind]=sum; 
00042         ind++;
00043       }
00044       ind = i*NPTL1 + ieta*(NPT*NPTL1);
00045       for (int j=0; j<NPTL1 ; j++){
00046         resolution[ind] /= sum;
00047         ind++;
00048       }
00049     }
00050   }
00051   
00052 }
00053 
00054 FML1PtSmearer::~FML1PtSmearer(){}
00055 
00056 
00057 
00058 bool FML1PtSmearer::smear(SimpleL1MuGMTCand * aMuon) {
00059   // get and smear the pt
00060   double Pt=aMuon->smearedPt();
00061   double AbsEta=fabs(aMuon->getMomentum().eta());
00062 
00063   bool StatusCode=true;  
00064   
00065   if (AbsEta>2.40 || Pt<3) { StatusCode=false;}
00066 
00067   if (StatusCode){
00068 
00069     int ieta = 0;
00070     if      (AbsEta<1.04) ieta = 0 ;
00071     else if (AbsEta<2.07) ieta = 1 ;
00072     else if (AbsEta<2.40) ieta = 2 ;
00073 
00074     int counter = 0;
00075     int ipt = IndexOfPtgen(Pt);
00076     int ind = counter + ipt*NPTL1 + ieta*(NPT*NPTL1);
00077     double prob = random->flatShoot();
00078     while ( (prob > resolution[ind]) && counter<NPTL1 ){ 
00079       counter++;
00080       ind++;
00081     }
00082     counter++;
00083     aMuon->setPtPacked(counter & 31);
00084     aMuon->setPtValue(SimpleL1MuGMTCand::ptScale[counter]);
00085 
00086     prob = random->flatShoot();
00087     if (prob <= ChargeMisIdent(ieta,Pt)) {
00088       int OldCharge = aMuon->charge(); 
00089       int NewCharge = -OldCharge;
00090       aMuon->setCharge(NewCharge);
00091     } 
00092 
00093   }
00094 
00095   return StatusCode;
00096 
00097 }  
00098 
00099 
00100 int FML1PtSmearer::IndexOfPtgen(float pt) {
00101 
00102   static float vecpt[NPT] = {
00103                 1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,
00104          10.,  11.,  12.,  13.,  14.,  15.,  16.,  17.,  18.,  19.,
00105          20.,  21.,  22.,  23.,  24.,  25.,  26.,  27.,  28.,  29.,
00106          30.,  31.,  32.,  33.,  34.,  35.,  36.,  37.,  38.,  39.,
00107          40.,  41.,  42.,  43.,  44.,  45.,  46.,  47.,  48.,  49.,
00108          50.,  51.,  52.,  53.,  54.,  55.,  56.,  57.,  58.,  59.,
00109          60.,  61.,  62.,  63.,  64.,  65.,  66.,  67.,  68.,  69.,
00110          70.,  71.,  72.,  73.,  74.,  75.,  76.,  77.,  78.,  79.,
00111          80.,  81.,  82.,  83.,  84.,  85.,  86.,  87.,  88.,  89.,
00112          90.,  91.,  92.,  93.,  94.,  95.,  96.,  97.,  98.,  99.,
00113         100., 110., 120., 130., 140., 150., 160., 170., 180., 190.,
00114         200., 210., 220., 230., 240., 250., 260., 270., 280., 290.,
00115         300., 310., 320., 330., 340., 350., 360., 370., 380., 390.,
00116         400., 500., 600., 700., 800., 900., 1000. };
00117 
00118   for (int i=0; i<NPT; i++) {
00119     if (pt<vecpt[i]) return i;
00120   }
00121   return NPT;
00122 }