-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSVEfficiencies.cc
More file actions
244 lines (213 loc) · 9.88 KB
/
Copy pathCSVEfficiencies.cc
File metadata and controls
244 lines (213 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <TH1F.h>
#include <TH2F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
#include <TChain.h>
#include <TLorentzVector.h>
#include <TLegend.h>
#include <TCanvas.h>
#include <TProfile.h>
#include <iostream>
#include <stdlib.h>
double bTagCSV_tightCut=0.898;
double bTagCSV_mediumCut=0.679;
double bTagCSV_looseCut=0.244;
double bTagCSV_noCut=0.;
double cut_CSV=bTagCSV_tightCut;
double jetpT_cut=40.;
double jeteta_cut=2.5;
// QCD scale factors
double totalLuminosity=13242; // /pb
double xsec_QCDHT250To500=276000; // pb
double xsec_QCDHT500To1000=8426; // pb
double xsec_QCDHT1000ToInf=204; // pb
double init_QCDHT250To500=4669914;
double init_QCDHT500To1000=4779910;
double init_QCDHT1000ToInf=5192110;
double scale_QCDHT250To500=totalLuminosity*xsec_QCDHT250To500/init_QCDHT250To500;
double scale_QCDHT500To1000=totalLuminosity*xsec_QCDHT500To1000/init_QCDHT500To1000;
double scale_QCDHT1000ToInf=totalLuminosity*xsec_QCDHT1000ToInf/init_QCDHT1000ToInf;
void CSVEfficiencies(std::string sample0,
std::string sample1,
std::string sample2,
std::string PUWeight0,
std::string PUWeight1,
std::string PUWeight2,
std::string csvTag="M")
{
if (csvTag=="T") cut_CSV=bTagCSV_tightCut;
if (csvTag=="M") cut_CSV=bTagCSV_mediumCut;
if (csvTag=="L") cut_CSV=bTagCSV_looseCut;
TH1F *h_udsg_JetpT_den=new TH1F("h_udsg_JetpT_den", "h_udsg_JetpT_den", 30, 0., 300.); h_udsg_JetpT_den->Sumw2();
TH1F *h_udsg_Jeteta_den=new TH1F("h_udsg_Jeteta_den", "h_udsg_Jeteta_den", 30, 0., 2.5); h_udsg_Jeteta_den->Sumw2();
TH2F *h_udsg_JetpTeta_den=new TH2F("h_udsg_JetpTeta_den", "h_udsg_JetpTeta_den", 30, 0., 300., 30, 0., 2.5); h_udsg_JetpTeta_den->Sumw2();
TH1F *h_udsg_JetpT_num=new TH1F("h_udsg_JetpT_num", "h_udsg_JetpT_num", 30, 0., 300.); h_udsg_JetpT_num->Sumw2();
TH1F *h_udsg_Jeteta_num=new TH1F("h_udsg_Jeteta_num", "h_udsg_Jeteta_num", 30, 0., 2.5); h_udsg_Jeteta_num->Sumw2();
TH2F *h_udsg_JetpTeta_num=new TH2F("h_udsg_JetpTeta_num", "h_udsg_JetpTeta_num", 30, 0., 300., 30, 0., 2.5); h_udsg_JetpTeta_num->Sumw2();
TH1F *h_c_JetpT_den=new TH1F("h_c_JetpT_den", "h_c_JetpT_den", 30, 0., 300.); h_c_JetpT_den->Sumw2();
TH1F *h_c_Jeteta_den=new TH1F("h_c_Jeteta_den", "h_c_Jeteta_den", 30, 0., 2.5); h_c_Jeteta_den->Sumw2();
TH2F *h_c_JetpTeta_den=new TH2F("h_c_JetpTeta_den", "h_c_JetpTeta_den", 30, 0., 300., 30, 0., 2.5); h_c_JetpTeta_den->Sumw2();
TH1F *h_c_JetpT_num=new TH1F("h_c_JetpT_num", "h_c_JetpT_num", 30, 0., 300.); h_c_JetpT_num->Sumw2();
TH1F *h_c_Jeteta_num=new TH1F("h_c_Jeteta_num", "h_c_Jeteta_num", 30, 0., 2.5); h_c_Jeteta_num->Sumw2();
TH2F *h_c_JetpTeta_num=new TH2F("h_c_JetpTeta_num", "h_c_JetpTeta_num", 30, 0., 300., 30, 0., 2.5); h_c_JetpTeta_num->Sumw2();
TH1F *h_b_JetpT_den=new TH1F("h_b_JetpT_den", "h_b_JetpT_den", 30, 0., 300.); h_b_JetpT_den->Sumw2();
TH1F *h_b_Jeteta_den=new TH1F("h_b_Jeteta_den", "h_b_Jeteta_den", 30, 0., 2.5); h_b_Jeteta_den->Sumw2();
TH2F *h_b_JetpTeta_den=new TH2F("h_b_JetpTeta_den", "h_b_JetpTeta_den", 30, 0., 300., 30, 0., 2.5); h_b_JetpTeta_den->Sumw2();
TH1F *h_b_JetpT_num=new TH1F("h_b_JetpT_num", "h_b_JetpT_num", 30, 0., 300.); h_b_JetpT_num->Sumw2();
TH1F *h_b_Jeteta_num=new TH1F("h_b_Jeteta_num", "h_b_Jeteta_num", 30, 0., 2.5); h_b_Jeteta_num->Sumw2();
TH2F *h_b_JetpTeta_num=new TH2F("h_b_JetpTeta_num", "h_b_JetpTeta_num", 30, 0., 300., 30, 0., 2.5); h_b_JetpTeta_num->Sumw2();
std::vector <std::string> samples;
std::vector <std::string> PUWeights;
samples.push_back(sample0);
samples.push_back(sample1);
samples.push_back(sample2);
PUWeights.push_back(PUWeight0);
PUWeights.push_back(PUWeight1);
PUWeights.push_back(PUWeight2);
// Book variables
int vType;
bool triggerFlags[500];
int nPV;
int nhJets, naJets;
int nJets;
float hJetE[100], hJetpT[100], hJeteta[100], hJetphi[100], hJetCSV[100], hJetflavor[100], hJet_genPt[100];
float aJetE[100], aJetpT[100], aJeteta[100], aJetphi[100], aJetCSV[100], aJetflavor[100], aJet_genPt[100];
float jetE[100], jetpT[100], jeteta[100], jetphi[100], jetCSV[100], jetflavor[100], jet_genPt[100];
for (unsigned int sample=0; sample<3; ++sample)
{
std::string inputfilename="/Users/souvik/HbbHbb/8TeV/OfficialStep2_"+samples.at(sample)+".root";
TChain *tree=new TChain("tree");
tree->Add(inputfilename.c_str());
std::cout<<"Opened input file "<<inputfilename<<std::endl;
std::string pufilename="/Users/souvik/HbbHbb/Analysis/"+PUWeights.at(sample);
TFile *file_PUWeight=new TFile(pufilename.c_str());
std::cout<<"Opened PU weight file = "<<pufilename<<std::endl;
TH1F *h_PUWeight=(TH1F*)file_PUWeight->Get("h_PUWeight");
// Retrieve variables
tree->SetBranchAddress("Vtype", &(vType));
tree->SetBranchAddress("triggerFlags", &(triggerFlags));
tree->SetBranchAddress("nPVs", &(nPV));
tree->SetBranchAddress("nhJets", &(nhJets));
tree->SetBranchAddress("hJet_e", &(hJetE));
tree->SetBranchAddress("hJet_pt", &(hJetpT));
tree->SetBranchAddress("hJet_eta", &(hJeteta));
tree->SetBranchAddress("hJet_phi", &(hJetphi));
tree->SetBranchAddress("hJet_csv", &(hJetCSV));
tree->SetBranchAddress("hJet_flavour", &(hJetflavor));
tree->SetBranchAddress("hJet_genPt", &(hJet_genPt));
tree->SetBranchAddress("naJets", &(naJets));
tree->SetBranchAddress("aJet_e", &(aJetE));
tree->SetBranchAddress("aJet_pt", &(aJetpT));
tree->SetBranchAddress("aJet_eta", &(aJeteta));
tree->SetBranchAddress("aJet_phi", &(aJetphi));
tree->SetBranchAddress("aJet_csv", &(aJetCSV));
tree->SetBranchAddress("aJet_flavour", &(aJetflavor));
tree->SetBranchAddress("aJet_genPt", &(aJet_genPt));
double scale_QCD;
if (sample==0) scale_QCD=scale_QCDHT250To500;
if (sample==1) scale_QCD=scale_QCDHT500To1000;
if (sample==2) scale_QCD=scale_QCDHT1000ToInf;
std::cout<<"Scale QCD = "<<scale_QCD<<std::endl;
// Loop over events
int nEvents=tree->GetEntries();
for (int i=0; i<nEvents; ++i)
{
tree->GetEvent(i);
double weightPU=h_PUWeight->GetBinContent(h_PUWeight->FindBin(nPV));
weightPU=weightPU*scale_QCD;
// Collate hJets and aJets into Jets
nJets=nhJets+naJets;
for (int j=0; j<nhJets; ++j)
{
jetE[j]=hJetE[j];
jetpT[j]=hJetpT[j];
jeteta[j]=hJeteta[j];
jetphi[j]=hJetphi[j];
jetCSV[j]=hJetCSV[j];
jetflavor[j]=hJetflavor[j];
jet_genPt[j]=hJet_genPt[j];
}
for (int j=0; j<naJets; ++j)
{
jetE[j+nhJets]=aJetE[j];
jetpT[j+nhJets]=aJetpT[j];
jeteta[j+nhJets]=aJeteta[j];
jetphi[j+nhJets]=aJetphi[j];
jetCSV[j+nhJets]=aJetCSV[j];
jetflavor[j+nhJets]=aJetflavor[j];
jet_genPt[j+nhJets]=aJet_genPt[j];
}
int nCJets=0;
for (int j=0; j<nJets; ++j)
{
if (fabs(jeteta[j])<jeteta_cut && jetpT[j]>jetpT_cut) ++nCJets;
}
if (vType==5 && nCJets>3)
{
for (int j=0; j<nJets; ++j)
{
if (fabs(jetflavor[j])==1 || fabs(jetflavor[j])==2 || fabs(jetflavor[j])==3 || fabs(jetflavor[j])==21) // d, u, s, g
{
if (fabs(jeteta[j])<jeteta_cut) h_udsg_JetpT_den->Fill(jet_genPt[j], weightPU); // h_udsg_JetpT_den->Fill(jetpT[j]);
if (jetpT[j]>jetpT_cut) h_udsg_Jeteta_den->Fill(jeteta[j], weightPU);
h_udsg_JetpTeta_den->Fill(jetpT[j], jeteta[j], weightPU);
if (jetCSV[j]>cut_CSV)
{
if (fabs(jeteta[j])<jeteta_cut) h_udsg_JetpT_num->Fill(jet_genPt[j], weightPU); // h_udsg_JetpT_num->Fill(jetpT[j]);
if (jetpT[j]>jetpT_cut) h_udsg_Jeteta_num->Fill(jeteta[j], weightPU);
h_udsg_JetpTeta_num->Fill(jetpT[j], jeteta[j], weightPU);
}
}
if (fabs(jetflavor[j])==4) // c
{
if (fabs(jeteta[j])<jeteta_cut) h_c_JetpT_den->Fill(jetpT[j], weightPU);
if (jetpT[j]>jetpT_cut) h_c_Jeteta_den->Fill(jeteta[j], weightPU);
h_c_JetpTeta_den->Fill(jetpT[j], jeteta[j], weightPU);
if (jetCSV[j]>cut_CSV)
{
if (fabs(jeteta[j])<jeteta_cut) h_c_JetpT_num->Fill(jetpT[j], weightPU);
if (jetpT[j]>jetpT_cut) h_c_Jeteta_num->Fill(jeteta[j], weightPU);
h_c_JetpTeta_num->Fill(jetpT[j], jeteta[j], weightPU);
}
}
if (fabs(jetflavor[j])==5) // b
{
if (fabs(jeteta[j])<jeteta_cut) h_b_JetpT_den->Fill(jetpT[j], weightPU);
if (jetpT[j]>jetpT_cut) h_b_Jeteta_den->Fill(jeteta[j], weightPU);
h_b_JetpTeta_den->Fill(jetpT[j], jeteta[j], weightPU);
if (jetCSV[j]>cut_CSV)
{
if (fabs(jeteta[j])<jeteta_cut) h_b_JetpT_num->Fill(jetpT[j], weightPU);
if (jetpT[j]>jetpT_cut) h_b_Jeteta_num->Fill(jeteta[j], weightPU);
h_b_JetpTeta_num->Fill(jetpT[j], jeteta[j], weightPU);
}
}
} // For loop over jets in the event
} // If vType==5 && nCJets > 3
} // For loop over events in this sample
} // For loop over the 3 QCD samples
std::string outputfilename="CSVFlavorEfficiencies_"+csvTag+".root";
TFile *tFile=new TFile(outputfilename.c_str(), "RECREATE");
h_udsg_JetpT_den->Write();
h_udsg_Jeteta_den->Write();
h_udsg_JetpTeta_den->Write();
h_udsg_JetpT_num->Write();
h_udsg_Jeteta_num->Write();
h_udsg_JetpTeta_num->Write();
h_c_JetpT_den->Write();
h_c_Jeteta_den->Write();
h_c_JetpTeta_den->Write();
h_c_JetpT_num->Write();
h_c_Jeteta_num->Write();
h_c_JetpTeta_num->Write();
h_b_JetpT_den->Write();
h_b_Jeteta_den->Write();
h_b_JetpTeta_den->Write();
h_b_JetpT_num->Write();
h_b_Jeteta_num->Write();
h_b_JetpTeta_num->Write();
tFile->Write();
tFile->Close();
}