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
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 cout << "Reading " << f1.name() << std::endl;
00028 }
00029 std::ifstream & listfile = *f1();
00030
00031 int ind;
00032 float num=0.;
00033 for (int ieta=0; ieta<3; ieta++) {
00034 for (int i=0; i<NPT; i++) {
00035 float sum = 0.;
00036 ind = i*NPTL1 + ieta*(NPT*NPTL1);
00037 for (int j=0; j<NPTL1; j++) {
00038 listfile >> num;
00039 sum += num;
00040 resolution[ind]=sum;
00041 ind++;
00042 }
00043 ind = i*NPTL1 + ieta*(NPT*NPTL1);
00044 for (int j=0; j<NPTL1 ; j++){
00045 resolution[ind] /= sum;
00046 ind++;
00047 }
00048 }
00049 }
00050
00051 }
00052
00053 FML1PtSmearer::~FML1PtSmearer(){}
00054
00055
00056
00057 bool FML1PtSmearer::smear(SimpleL1MuGMTCand * aMuon) {
00058
00059 double Pt=aMuon->smearedPt();
00060 double AbsEta=fabs(aMuon->getMomentum().eta());
00061
00062 bool StatusCode=true;
00063
00064 if (AbsEta>2.40 || Pt<3) { StatusCode=false;}
00065
00066 if (StatusCode){
00067
00068 int ieta = 0;
00069 if (AbsEta<1.04) ieta = 0 ;
00070 else if (AbsEta<2.07) ieta = 1 ;
00071 else if (AbsEta<2.40) ieta = 2 ;
00072
00073 int counter = 0;
00074 int ipt = IndexOfPtgen(Pt);
00075 int ind = counter + ipt*NPTL1 + ieta*(NPT*NPTL1);
00076 double prob = random->flatShoot();
00077 while ( (prob > resolution[ind]) && counter<NPTL1 ){
00078 counter++;
00079 ind++;
00080 }
00081 counter++;
00082 aMuon->setPtPacked(counter & 31);
00083 aMuon->setPtValue(SimpleL1MuGMTCand::ptScale[counter]);
00084
00085 prob = random->flatShoot();
00086 if (prob <= ChargeMisIdent(ieta,Pt)) {
00087 int OldCharge = aMuon->charge();
00088 int NewCharge = -OldCharge;
00089 aMuon->setCharge(NewCharge);
00090 }
00091
00092 }
00093
00094 return StatusCode;
00095
00096 }
00097
00098
00099 int FML1PtSmearer::IndexOfPtgen(float pt) {
00100
00101 static float vecpt[NPT] = {
00102 1., 2., 3., 4., 5., 6., 7., 8., 9.,
00103 10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
00104 20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
00105 30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
00106 40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
00107 50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
00108 60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
00109 70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
00110 80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
00111 90., 91., 92., 93., 94., 95., 96., 97., 98., 99.,
00112 100., 110., 120., 130., 140., 150., 160., 170., 180., 190.,
00113 200., 210., 220., 230., 240., 250., 260., 270., 280., 290.,
00114 300., 310., 320., 330., 340., 350., 360., 370., 380., 390.,
00115 400., 500., 600., 700., 800., 900., 1000. };
00116
00117 for (int i=0; i<NPT; i++) {
00118 if (pt<vecpt[i]) return i;
00119 }
00120 return NPT;
00121 }