-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadLowPtSUSY_Tree_WithMETTrigger.cc
377 lines (344 loc) · 11.7 KB
/
ReadLowPtSUSY_Tree_WithMETTrigger.cc
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#include <TH1F.h>
#include <TH2F.h>
#include <TH3F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
#include <TChain.h>
#include <TLorentzVector.h>
#include <TLegend.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <TGraphAsymmErrors.h>
TLorentzVector fillTLorentzVector(double pT, double eta, double phi, double E)
{
TLorentzVector object_p4;
object_p4.SetPtEtaPhiE(pT, eta, phi, E);
return object_p4;
}
double mdeltaR(double eta1, double phi1, double eta2, double phi2) { //this function only works if both phi1 and phi2 are defined from -pi to pi or 0 to 2*pi
double delta_eta = fabs(eta1-eta2);
double delta_phi = fabs(phi1-phi2);
if(delta_phi > 3.14159265) delta_phi = delta_phi - 2*3.14159265;
return std::sqrt((delta_eta)*(delta_eta) + (delta_phi)*(delta_phi));
}
typedef struct
{
float pT;
float eta;
float phi;
float energy;
int charge;
bool isTight;
float isolation;
} LeptonInfo;
typedef struct
{
float pT;
float eta;
float phi;
float energy;
int charge;
bool isTight;
float chIsolation;
float nuIsolation;
float phIsolation;
bool phIsoTight;
bool phIsoMedium;
bool phIsoLoose;
} PhotonInfo;
typedef struct
{
float pT;
float eta;
float phi;
float energy;
int PU_mva_loose;
int PU_mva_tight;
int PU_mva_medium;
int PU_cut_loose;
int PU_cut_tight;
int PU_cut_medium;
} JetInfo;
typedef struct
{
float Px;
float Py;
float Pz;
float E;
} TriggerInfo;
bool sortLeptonsInDescendingpT(LeptonInfo lep1, LeptonInfo lep2)
{
return (lep1.pT > lep2.pT);
}
bool sortJetsInDescendingpT(JetInfo jet1, JetInfo jet2)
{
return (jet1.pT > jet2.pT);
}
bool sortJetVectorsInDescendingpT(TLorentzVector jet1, TLorentzVector jet2)
{
return (jet1.Pt() > jet2.Pt());
}
bool sortPhotonsInDescendingpT(PhotonInfo pho1, PhotonInfo pho2)
{
return (pho1.pT > pho2.pT);
}
int TriggerEfficiency(std::string infile, std::string outfile){
std::string inputfilename=(infile+".root").c_str();
TChain *tree=new TChain("LowPtSUSY_Tree");
tree->Add(inputfilename.c_str());
std::cout<<"Opened input file "<<inputfilename<<std::endl;
Int_t nVertices;
vector<float> *mu_pt;
vector<float> *mu_phi;
vector<float> *mu_eta;
vector<float> *mu_energy;
vector<int> *mu_charge;
vector<bool> *mu_isTight;
vector<float> *mu_iso;
vector<float> *jet_pt;
vector<float> *jet_phi;
vector<float> *jet_eta;
vector<float> *jet_energy;
vector<int> *jet_mva_loose;
vector<int> *jet_mva_tight;
vector<int> *jet_mva_medium;
vector<int> *jet_cut_loose;
vector<int> *jet_cut_tight;
vector<int> *jet_cut_medium;
Bool_t fired_HLTPho;
Bool_t fired_HLTPhoId;
Bool_t fired_HLTPhoIdMet;
Bool_t fired_HLTMET100;
vector<float> *ph_pt;
vector<float> *ph_phi;
vector<float> *ph_eta;
vector<float> *ph_energy;
vector<bool> *ph_phIsoTight;
vector<bool> *ph_phIsoMedium;
vector<bool> *ph_phIsoLoose;
vector<float> *ph_chIso;
vector<float> *ph_nuIso;
vector<float> *ph_phIso;
vector<bool> *ph_isTight;
Float_t MET;
float trigObj1Px;
float trigObj1Py;
float trigObj1Pz;
float trigObj1E;
float trigObj2Px;
float trigObj2Py;
float trigObj2Pz;
float trigObj2E;
tree->SetBranchAddress("nVertices", &(nVertices));
tree->SetBranchAddress("fired_HLTPho", &(fired_HLTPho));
tree->SetBranchAddress("fired_HLTPhoId", &(fired_HLTPhoId));
tree->SetBranchAddress("fired_HLTPhoIdMet", &(fired_HLTPhoIdMet));
tree->SetBranchAddress("fired_HLTPhoIdMet", &(fired_HLTPhoIdMet));
tree->SetBranchAddress("fired_HLTMET100", &(fired_HLTMET100));
tree->SetBranchAddress("ph_pt", &(ph_pt));
tree->SetBranchAddress("ph_phi", &(ph_phi));
tree->SetBranchAddress("ph_eta", &(ph_eta));
tree->SetBranchAddress("ph_energy", &(ph_energy));
tree->SetBranchAddress("ph_chIso", &(ph_chIso));
tree->SetBranchAddress("ph_nuIso", &(ph_nuIso));
tree->SetBranchAddress("ph_phIso", &(ph_phIso));
tree->SetBranchAddress("ph_isTight", &(ph_isTight));
tree->SetBranchAddress("ph_phIsoTight", &(ph_phIsoTight));
tree->SetBranchAddress("ph_phIsoMedium", &(ph_phIsoMedium));
tree->SetBranchAddress("ph_phIsoLoose", &(ph_phIsoLoose));
tree->SetBranchAddress("MET", &(MET));
tree->SetBranchAddress("jet_pt", &(jet_pt));
tree->SetBranchAddress("jet_phi", &(jet_phi));
tree->SetBranchAddress("jet_eta", &(jet_eta));
tree->SetBranchAddress("jet_energy", &(jet_energy));
tree->SetBranchAddress("jet_mva_loose", &(jet_mva_loose));
tree->SetBranchAddress("jet_mva_tight", &(jet_mva_tight));
tree->SetBranchAddress("jet_mva_medium", &(jet_mva_medium));
tree->SetBranchAddress("jet_cut_loose", &(jet_cut_loose));
tree->SetBranchAddress("jet_cut_tight", &(jet_cut_tight));
tree->SetBranchAddress("jet_cut_medium", &(jet_cut_medium));
tree->SetBranchAddress("mu_pt", &(mu_pt));
tree->SetBranchAddress("mu_eta", &(mu_eta));
tree->SetBranchAddress("mu_phi", &(mu_phi));
tree->SetBranchAddress("mu_energy", &(mu_energy));
tree->SetBranchAddress("mu_charge", &(mu_charge));
tree->SetBranchAddress("mu_isTight", &(mu_isTight));
tree->SetBranchAddress("mu_iso", &(mu_iso));
tree->SetBranchAddress("trigObj1Px", &(trigObj1Px));
tree->SetBranchAddress("trigObj1Py", &(trigObj1Py));
tree->SetBranchAddress("trigObj1Pz", &(trigObj1Pz));
tree->SetBranchAddress("trigObj1E", &(trigObj1E));
tree->SetBranchAddress("trigObj2Px", &(trigObj2Px));
tree->SetBranchAddress("trigObj2Py", &(trigObj2Py));
tree->SetBranchAddress("trigObj2Pz", &(trigObj2Pz));
tree->SetBranchAddress("trigObj2E", &(trigObj2E));
mu_pt = 0;
mu_phi = 0;
mu_eta = 0;
mu_energy = 0;
mu_charge = 0;
mu_isTight = 0;
mu_iso = 0;
ph_pt = 0;
ph_phi = 0;
ph_eta = 0;
ph_energy = 0;
ph_chIso = 0;
ph_nuIso = 0;
ph_phIso = 0;
ph_isTight = 0;
ph_phIsoTight = 0;
ph_phIsoMedium = 0;
ph_phIsoLoose = 0;
jet_pt = 0;
jet_phi = 0;
jet_eta = 0;
jet_energy = 0;
jet_mva_loose = 0;
jet_mva_tight = 0;
jet_mva_medium = 0;
jet_cut_loose = 0;
jet_cut_tight = 0;
jet_cut_medium = 0;
TH1F *h_PHO_HLT_METTrig=new TH1F("h_PHO_HLT_METTrig", "Photon pT; photon pT [GeV]; Events/GeV", 600, 0, 600); h_PHO_HLT_METTrig->Sumw2();
TH1F *h_PHO_HLTPho_METTrig=new TH1F("h_PHO_HLTPho_METTrig", "Photon pT; photon pT [GeV]; Events/GeV", 600, 0, 600); h_PHO_HLTPho_METTrig->Sumw2();
TH1F *h_PHO_HLT_METTrig_RemoveJets=new TH1F("h_PHO_HLT_METTrig_RemoveJets", "Photon pT; photon pT [GeV]; Events/GeV", 600, 0, 600); h_PHO_HLT_METTrig_RemoveJets->Sumw2();
TH1F *h_PHO_HLTPho_METTrig_RemoveJets=new TH1F("h_PHO_HLTPho_METTrig_RemoveJets", "Photon pT; photon pT [GeV]; Events/GeV", 600, 0, 600); h_PHO_HLTPho_METTrig_RemoveJets->Sumw2();
TH1F *h_DeltaR_Ph_Jet = new TH1F("h_DeltaR_Ph_Jet", "#Delta R between the photon and the jet; #Delta R; Events", 4000, 0, 4.0);h_DeltaR_Ph_Jet->Sumw2();
int nEvents=tree->GetEntries();
std::cout << "nEvents= " << nEvents << std::endl;
for (int i=0; i<nEvents; ++i)
{
tree->GetEvent(i);
TriggerInfo trigger1;
trigger1.Px = trigObj1Px;
trigger1.Py = trigObj1Py;
trigger1.Pz = trigObj1Pz;
trigger1.E = trigObj1E;
TriggerInfo trigger2;
trigger2.Px = trigObj2Px;
trigger2.Py = trigObj2Py;
trigger2.Pz = trigObj2Pz;
trigger2.E = trigObj2E;
std::vector<LeptonInfo> muons;
for (unsigned int j=0; j<mu_pt->size(); ++j)
{
LeptonInfo muon;
muon.pT=mu_pt->at(j);
muon.eta=mu_eta->at(j);
muon.phi=mu_phi->at(j);
muon.energy=mu_energy->at(j);
muon.charge=mu_charge->at(j);
muon.isTight=mu_isTight->at(j);
muon.isolation=mu_iso->at(j);
muons.push_back(muon);
}
std::vector<PhotonInfo> photons;
for (unsigned int j=0; j<ph_pt->size(); ++j)
{
PhotonInfo photon;
photon.pT=ph_pt->at(j);
photon.eta=ph_eta->at(j);
photon.phi=ph_phi->at(j);
photon.energy=ph_energy->at(j);
photon.isTight=ph_isTight->at(j);
photon.chIsolation=ph_chIso->at(j);
photon.nuIsolation=ph_nuIso->at(j);
photon.phIsolation=ph_phIso->at(j);
photon.phIsoTight=ph_phIsoTight->at(j);
photon.phIsoMedium=ph_phIsoMedium->at(j);
photon.phIsoLoose=ph_phIsoLoose->at(j);
photons.push_back(photon);
}
// Now sorting this vector of structs
std::sort (photons.begin(), photons.end(), sortPhotonsInDescendingpT);
TLorentzVector ph1_p4;
int foundHLTPhoton1 = 0;
int foundHLTPhoton2 = 0;
if (photons.size() > 0){
ph1_p4=fillTLorentzVector(photons.at(0).pT, photons.at(0).eta, photons.at(0).phi, photons.at(0).energy);
TLorentzVector trigger1_p4;
trigger1_p4.SetPxPyPzE(trigger1.Px, trigger1.Py, trigger1.Pz, trigger1.E);
double deltaR1 = ph1_p4.DeltaR(trigger1_p4);
if(deltaR1 < 0.3 and fired_HLTPhoId){
foundHLTPhoton1=1;
}
TLorentzVector trigger2_p4;
trigger2_p4.SetPxPyPzE(trigger2.Px, trigger2.Py, trigger2.Pz, trigger2.E);
double deltaR2 = ph1_p4.DeltaR(trigger2_p4);
if(deltaR2 < 0.3 and fired_HLTPho){
foundHLTPhoton2=1;
}
}//only execute this loop if a photon exists.
std::vector<JetInfo> jets;
for (unsigned int j=0; j<jet_pt->size(); ++j)
{
JetInfo jet;
jet.pT = jet_pt->at(j);
jet.eta = jet_eta->at(j);
jet.phi = jet_phi->at(j);
jet.energy = jet_energy->at(j);
jet.PU_mva_loose = jet_mva_loose->at(j);
jet.PU_mva_tight = jet_mva_tight->at(j);
jet.PU_mva_medium = jet_mva_medium->at(j);
jet.PU_cut_loose = jet_cut_loose->at(j);
jet.PU_cut_tight = jet_cut_tight->at(j);
jet.PU_cut_medium = jet_cut_medium->at(j);
jets.push_back(jet);
}
// Now sorting this vector of structs
std::sort (jets.begin(), jets.end(), sortJetsInDescendingpT);
double minDR_PhJ = 9999;
int foundJetNearPhoton=0;
if(photons.size() > 0)
{
if(photons.at(0).pT>30.0 and photons.at(0).isTight==1 and photons.at(0).phIsoTight==1)
{
TLorentzVector Photon;
Photon.SetPtEtaPhiE(photons.at(0).pT, photons.at(0).eta, photons.at(0).phi, photons.at(0).energy);
for(unsigned int k=0; k<jets.size(); ++k)
{
TLorentzVector Jet;
if(fabs(jets.at(k).eta)<2.4 and jets.at(k).pT>25.0 and jets.at(k).PU_mva_loose==1)
{
Jet.SetPtEtaPhiE(jets.at(k).pT, jets.at(k).eta, jets.at(k).phi, jets.at(k).energy);
double dRjet_ph=Jet.DeltaR(Photon);
if (dRjet_ph<minDR_PhJ) minDR_PhJ=dRjet_ph;
}
}
h_DeltaR_Ph_Jet->Fill(minDR_PhJ);
if (minDR_PhJ<0.5) foundJetNearPhoton=1;
}
}
if(photons.size() > 0){
if(fired_HLTMET100==1 and photons.at(0).pT>30.0 and photons.at(0).isTight==1 and photons.at(0).phIsoTight==1){
h_PHO_HLT_METTrig->Fill(photons.at(0).pT);
if(fired_HLTPhoIdMet==1){
h_PHO_HLTPho_METTrig->Fill(photons.at(0).pT);
}
}
}
if(photons.size() > 0){
if(fired_HLTMET100==1 and photons.at(0).pT>30.0 and photons.at(0).isTight==1 and photons.at(0).phIsoTight==1 and foundJetNearPhoton==0){
h_PHO_HLT_METTrig_RemoveJets->Fill(photons.at(0).pT);
if(fired_HLTPhoIdMet==1){
h_PHO_HLTPho_METTrig_RemoveJets->Fill(photons.at(0).pT);
}
}
}
}//end of event loop
std::string histfilename=(outfile+".root").c_str();
TFile *tFile=new TFile(histfilename.c_str(), "RECREATE");
h_DeltaR_Ph_Jet->Write();
h_PHO_HLTPho_METTrig->Write();
h_PHO_HLT_METTrig->Write();
h_PHO_HLT_METTrig_RemoveJets->Write();
h_PHO_HLTPho_METTrig_RemoveJets->Write();
tFile->Close();
std::cout<<"Wrote output file "<<histfilename<<std::endl;
return 0;
}