ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/TriggerWeight.h
Revision: 1.11
Committed: Thu Nov 10 00:01:40 2011 UTC (13 years, 5 months ago) by arizzi
Content type: text/plain
Branch: MAIN
CVS Tags: V21emuCand, EdmV33Jun12v0, Step2ForV31_v0, EdmV32May24v0, EdmV31May21v1, EdmV31May17v0, May14thStep2, EdmV30Apr10, EdmV21Apr10v2, EdmV22May9, EdmV21Apr06, EdmV21Apr10, EdmV21Apr04, EdmV21Apr03, EdmV21Apr2, EdmV21Mar30, EdmV20Mar12, AR_Nov10Ntuple
Branch point for: V21emuCandidate
Changes since 1.10: +68 -14 lines
Log Message:
- 3D PU reweighting with latest recipe and targetting the full 2011B run period
- PU reweight fixed in 2011A against Fall11 MC
- run boundary handling to properly handle the two periods of 2011B
- factorized MET triggers
- events failing the "at least 2 jets pt > 20" are recovered with a pt15 cut (NB: the election of higest dijet is first done with 20GeV threshold, the 15 GeV is consiered only if the 20 fails)
- apply JER smearing by default
- add leptons generator info
- add jet by jet btag SF info
- add electron id80NoIso

File Contents

# User Rev Content
1 arizzi 1.1 #ifndef TRIGGERWEIGHT_H
2     #define TRIGGERWEIGHT_H
3    
4     #include "FWCore/ParameterSet/interface/ProcessDesc.h"
5     #include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
6 arizzi 1.11 //#include "VHbbAnalysis/VHbbDataFormats/interface/TriggerZnunuCurve.h"
7 arizzi 1.4 #include "VHbbAnalysis/VHbbDataFormats/interface/MultiThresholdEfficiency.h"
8 arizzi 1.1 #include <TH1F.h>
9 arizzi 1.3 #include <TF1.h>
10 arizzi 1.1 #include <TFile.h>
11     #include <TTree.h>
12     #include <iostream>
13    
14     class TriggerWeight
15     {
16     public:
17 arizzi 1.11 TriggerWeight(const edm::ParameterSet& ana) : combiner2Thr(2), combiner1Thr(1)
18 arizzi 1.1 {
19 arizzi 1.4 tscaleHLTmu=openFile(ana,"hltMuFileName");
20     tscaleIDmu=openFile(ana,"idMuFileName");
21     tscaleHLTele1=openFile(ana,"hltEle1FileName");
22     tscaleHLTele2=openFile(ana,"hltEle2FileName");
23 arizzi 1.9 tscaleHLTele1Aug=openFile(ana,"hltEle1AugFileName");
24     tscaleHLTele2Aug=openFile(ana,"hltEle2AugFileName");
25 arizzi 1.5 tscaleID80Ele=openFile(ana,"idEle80FileName");
26     tscaleID95Ele=openFile(ana,"idEle95FileName");
27 arizzi 1.4 tscaleHLTeleJet1=openFile(ana,"hltJetEle1FileName");
28     tscaleHLTeleJet2=openFile(ana,"hltJetEle2FileName");
29 arizzi 1.5 tscaleRecoEle=openFile(ana,"recoEleFileName");
30     // tscalePFMHTele=openFile(ana,"hltPFMHTEleFileName");
31     tscaleSingleEleMay=openFile(ana,"hltSingleEleMayFileName");
32     tscaleSingleEleV4=openFile(ana,"hltSingleEleV4FileName");
33 arizzi 1.6 tscaleHLTmuOr30=openFile(ana,"hltMuOr30FileName");
34 arizzi 1.4
35 arizzi 1.1 if(tscaleHLTmu == 0 || tscaleIDmu == 0)
36     {
37     std::cout << "ERROR: cannot load Muon Trigger efficiencies" << std::endl;
38     }
39 arizzi 1.4
40    
41 arizzi 1.1
42     }
43 arizzi 1.4
44 arizzi 1.10 static TTree * openFile(const edm::ParameterSet& ana, const char * name)
45 arizzi 1.4 {
46 arizzi 1.5 TFile *hltMuFile = new TFile (ana.getParameter<std::string> (name).c_str(),"read");
47 arizzi 1.4 if(hltMuFile) return (TTree*) hltMuFile->Get("tree");
48     else return 0;
49     }
50    
51 arizzi 1.10 static std::pair<float,float> efficiencyFromPtEta(float pt1, float eta1, TTree *t)
52 arizzi 1.4 {
53     float s1 = 1.,err=1.;
54     std::pair<float,float> r(s1,err);
55     if(!t) return r;
56     float ptMin,ptMax,etaMin,etaMax,scale,error;
57     int count = 0;
58     t->SetBranchAddress("ptMin",&ptMin);
59     t->SetBranchAddress("ptMax",&ptMax);
60     t->SetBranchAddress("etaMin",&etaMin);
61     t->SetBranchAddress("etaMax",&etaMax);
62     t->SetBranchAddress("scale",&scale);
63     t->SetBranchAddress("error",&error);
64 arizzi 1.7 float lastPtBin = 200;
65     /* for(int jentry = 0; jentry < t->GetEntries(); jentry++)
66     {
67     t->GetEntry(jentry);
68     if(ptMax >= lastPtBin) lastPtBin =ptMax;
69     }*/
70 arizzi 1.4 for(int jentry = 0; jentry < t->GetEntries(); jentry++)
71     {
72     t->GetEntry(jentry);
73 arizzi 1.7 if(ptMax==lastPtBin) ptMax=1e99;
74 arizzi 1.4 if((pt1 > ptMin) && (pt1 < ptMax) && (eta1 > etaMin) && (eta1 < etaMax))
75     {
76     s1 = scale;
77     err=error;
78     count++;
79     }
80     }
81    
82     if(count == 0 || s1 == 0)
83     {
84     return r;
85     }
86    
87     r.first=s1;
88     r.second = err;
89     return (r);
90     }
91 arizzi 1.1
92     float scaleMuIsoHLT(float pt1, float eta1)
93     {
94 arizzi 1.4 return efficiencyFromPtEta(pt1,eta1,tscaleHLTmu).first;
95 arizzi 1.1 }
96    
97    
98    
99     float scaleMuID(float pt1, float eta1)
100     {
101 arizzi 1.4 return efficiencyFromPtEta(pt1,eta1,tscaleIDmu).first;
102 arizzi 1.1 }
103    
104 arizzi 1.3
105 arizzi 1.9 double scaleDoubleEle17Ele8Aug( std::vector<float> pt, std::vector<float> eta )
106     {
107     std::vector< std::vector<float> > allEleWithEffs;
108     for(unsigned int j=0; j< pt.size(); j++)
109     {
110     std::vector<float> thisEleEffs;
111     thisEleEffs.push_back(efficiencyFromPtEta(pt[j],eta[j],tscaleHLTele1Aug).first);
112     thisEleEffs.push_back(efficiencyFromPtEta(pt[j],eta[j],tscaleHLTele2Aug).first);
113    
114     allEleWithEffs.push_back(thisEleEffs);
115     }
116    
117     return combiner2Thr.weight<Trigger1High2Loose>(allEleWithEffs);
118    
119     }
120    
121    
122 arizzi 1.5 double scaleDoubleEle17Ele8( std::vector<float> pt, std::vector<float> eta )
123     {
124     std::vector< std::vector<float> > allEleWithEffs;
125     for(unsigned int j=0; j< pt.size(); j++)
126     {
127     std::vector<float> thisEleEffs;
128     thisEleEffs.push_back(efficiencyFromPtEta(pt[j],eta[j],tscaleHLTele1).first);
129     thisEleEffs.push_back(efficiencyFromPtEta(pt[j],eta[j],tscaleHLTele2).first);
130 arizzi 1.9
131 arizzi 1.5 allEleWithEffs.push_back(thisEleEffs);
132     }
133    
134     return combiner2Thr.weight<Trigger1High2Loose>(allEleWithEffs);
135    
136     }
137    
138     double scaleSingleEleMay( float pt, float eta){ return efficiencyFromPtEta(pt,eta,tscaleSingleEleMay).first;}
139     double scaleSingleEleV4( float pt, float eta){ return efficiencyFromPtEta(pt,eta,tscaleSingleEleV4).first; }
140     double scaleID80Ele( float pt, float eta) { return efficiencyFromPtEta(pt,eta,tscaleID80Ele).first; }
141     double scaleID95Ele( float pt, float eta) { return efficiencyFromPtEta(pt,eta,tscaleID95Ele).first; }
142     double scaleRecoEle( float pt, float eta){ return efficiencyFromPtEta(pt,eta,tscaleRecoEle).first; }
143     double scalePFMHTEle( float MetPFPt){
144     double weightPFMHTrigger=0.;
145    
146     //FIXME: read from file
147 dlopes 1.8 if(MetPFPt>0. && MetPFPt<5.) weightPFMHTrigger=0.305;
148     if(MetPFPt>5. && MetPFPt<10.) weightPFMHTrigger=0.351;
149     if(MetPFPt>10. && MetPFPt<15.) weightPFMHTrigger=0.461;
150     if(MetPFPt>15. && MetPFPt<20.) weightPFMHTrigger=0.572;
151     if(MetPFPt>20. && MetPFPt<25.) weightPFMHTrigger=0.713;
152     if(MetPFPt>25. && MetPFPt<30.) weightPFMHTrigger=0.844;
153     if(MetPFPt>30. && MetPFPt<35.) weightPFMHTrigger=0.914;
154     if(MetPFPt>35. && MetPFPt<40.) weightPFMHTrigger=0.939;
155     if(MetPFPt>40. && MetPFPt<45.) weightPFMHTrigger=0.981;
156     if(MetPFPt>45. && MetPFPt<50.) weightPFMHTrigger=0.982;
157     if(MetPFPt>50. && MetPFPt<60.) weightPFMHTrigger=0.993;
158     if(MetPFPt>60. && MetPFPt<70.) weightPFMHTrigger=0.995;
159     if(MetPFPt>70. && MetPFPt<100.) weightPFMHTrigger=0.995;
160     if(MetPFPt>100.) weightPFMHTrigger=1.;
161 arizzi 1.5 return weightPFMHTrigger;
162     }
163    
164 arizzi 1.11
165 arizzi 1.5 double scaleJet30Jet25( std::vector<float> pt, std::vector<float> eta)
166 arizzi 1.4 {
167 arizzi 1.5
168     std::vector< std::vector<float> > allJetsWithEffs;
169     for(unsigned int j=0; j< pt.size(); j++)
170     {
171     std::vector<float> thisJetEffs;
172     thisJetEffs.push_back(efficiencyFromPtEta(pt[j],eta[j],tscaleHLTeleJet1).first);
173     thisJetEffs.push_back(efficiencyFromPtEta(pt[j],eta[j],tscaleHLTeleJet2).first);
174 arizzi 1.11 // std::cout << " jet pt " << pt[j] << " eta " << eta[j] << " eff1 " << thisJetEffs[0] << " eff2 " << thisJetEffs[1] << std::endl;
175 arizzi 1.5 allJetsWithEffs.push_back(thisJetEffs);
176 arizzi 1.11
177     }
178     float res = combiner2Thr.weight<Trigger1High2Loose>(allJetsWithEffs);
179     // std::cout << "Result is " << res << std::endl;
180     return res;
181     // return combiner2Thr.weight<Trigger1High2Loose>(allJetsWithEffs);
182    
183     }
184     /*
185     TF1 fpt("f","1-exp(-0.157*(x-19.3))", 0., 9999999.);
186    
187     MET80:
188     TF1 fmet80("f","1/ (1 + exp( -0.0709 * (x - 100.7)))", 0., 9999999.);
189    
190     MET100:
191     TF1 fmet100("f","1/ (1 + exp( -0.0679 * (x - 128.8)))", 0., 9999999.);
192     */
193    
194     //LP curve used for MET
195     double scaleMetHLT( double met){
196     return 1. / (1. + ( exp( 0.059486 * ( 123.27 - met ))));
197     }
198    
199     //MET80 component of the factorized JET+MET trigger
200     double scaleMET80(double et)
201     {
202     return 1. / (1. + exp( -0.0709 * (et - 100.7)));
203     }
204    
205     //MET100 component
206     double scaleMET100(double et)
207     {
208     return 1. / (1. + exp( -0.0679 * (et - 128.8)));
209     }
210    
211     //Single jet20 efficiency for MET+2CJet20
212     double jet20efficiency( double pt)
213     {
214     if(pt < 10 ) return 0;
215     return 1. - exp(-0.157*(pt-19.3));
216     }
217    
218     //combined 2 jets efficiency out of N jets, using jet20 efficiency curve
219     double scale2CentralJet( std::vector<float> pt, std::vector<float> eta)
220     {
221    
222     std::vector< std::vector<float> > allJetsWithEffs;
223     for(unsigned int j=0; j< pt.size(); j++)
224     {
225     if(fabs(eta[j]) < 2.5)
226     {
227     std::vector<float> thisJetEffs;
228     thisJetEffs.push_back(jet20efficiency(pt[j]));
229     allJetsWithEffs.push_back(thisJetEffs);
230     }
231    
232 arizzi 1.5 }
233    
234 arizzi 1.11 return combiner1Thr.weight<Trigger2SingleThr>(allJetsWithEffs);
235     }
236    
237     //New MET 150
238     double scaleMET150(double et)
239     {
240     return 1./ (1. + exp( -0.129226 * (et - 156.699)));
241 arizzi 1.4 }
242 arizzi 1.3
243 arizzi 1.6 float scaleMuOr30IsoHLT(float pt1, float eta1)
244     {
245     return efficiencyFromPtEta(pt1,eta1,tscaleHLTmuOr30).first;
246     }
247 arizzi 1.3
248    
249 arizzi 1.1 private:
250 arizzi 1.4 TTree * tscaleHLTele1;
251     TTree * tscaleHLTele2;
252     TTree * tscaleHLTeleJet1;
253     TTree * tscaleHLTeleJet2;
254 arizzi 1.5 TTree * tscaleID80Ele;
255     TTree * tscaleID95Ele;
256     TTree * tscaleRecoEle;
257 arizzi 1.6 TTree * tscaleHLTmuOr30;
258    
259 arizzi 1.5 // TTree * tscalePFMHTele;
260     TTree * tscaleSingleEleMay;
261     TTree * tscaleSingleEleV4;
262 arizzi 1.4
263 arizzi 1.9 TTree * tscaleHLTele1Aug;
264     TTree * tscaleHLTele2Aug;
265    
266 arizzi 1.1 TTree * tscaleHLTmu;
267     TTree * tscaleIDmu;
268 arizzi 1.4 MultiThresholdEfficiency combiner2Thr;
269 arizzi 1.11 MultiThresholdEfficiency combiner1Thr;
270 arizzi 1.1 };
271    
272     #endif