-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_test.C
403 lines (313 loc) · 12 KB
/
new_test.C
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/Delphes/classes/DelphesClasses.h"
#include "/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/Delphes/external/ExRootAnalysis/ExRootTreeReader.h"
#endif
#include <iostream>
#include <TClonesArray.h>
#include <TMath.h>
#include <TH1.h>
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <iostream>
#include <fstream>
#include "TLorentzVector.h"
#include <vector>
using std::vector;
//------------------------------------------------------------------------------
void new_test()
{
gSystem->Load("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/Delphes/libDelphes");
// Create chain of root trees
TChain chain("Delphes");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/charged_higgs_signal/Events/run_01/tag_1_delphes_events.root");
chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/ttbar_jets/Events/run_01/tag_1_delphes_events.root");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/tjets/Events/run_01/tag_1_delphes_events.root");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/zz_jets/Events/run_01/tag_1_delphes_events.root");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/wz_jets/Events/run_01/tag_1_delphes_events.root");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/ww_jets/Events/run_01/tag_1_delphes_events.root");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/zjets/Events/run_01/tag_1_delphes_events.root");
// chain.Add("/home/kanhaiya/Madgraph/MG5_aMC_v2_5_5/wjets/Events/run_01/tag_1_delphes_events.root");
// Create object of class ExRootTreeReader
ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
Long64_t nEntries = treeReader->GetEntries();
// Get pointers to branches used in this analysis
TClonesArray *branchEvent = treeReader->UseBranch("Event");
TClonesArray *branchParticle = treeReader->UseBranch("Particle");
TClonesArray *branchMissingET = treeReader->UseBranch("MissingET");
TClonesArray *branchScalarHT = treeReader->UseBranch("ScalarHT");
TClonesArray *branchPhoton = treeReader->UseBranch("Photon");
TClonesArray *branchElectron = treeReader->UseBranch("Electron");
TClonesArray *branchMuon = treeReader->UseBranch("Muon");
TClonesArray *branchJet = treeReader->UseBranch("Jet");
TClonesArray *branchTrack = treeReader->UseBranch("Track");
TClonesArray *branchTower = treeReader->UseBranch("Tower");
// TClonesArray *branchVertex = treeReader->UseBranch("Vertex");
// TClonesArray *branchHectorHit = treeReader->UseBranch("HectorHit");
// creating the root file as output
// TFile outf("new_charged_higgs.root","RECREATE");
TFile outf("new_ttbar_jets.root","RECREATE");
// TFile outf("tjets.root","RECREATE");
// TFile outf("zz_jets.root","RECREATE");
// TFile outf("wz_jets.root","RECREATE");
// TFile outf("ww_jets.root","RECREATE");
// TFile outf("zjets.root","RECREATE");
// TFile outf("wjets.root","RECREATE");
std::cout << "creating output ..." <<std::endl;
// creating a tree named delphes
TTree delphes("delphes","a simple tree for analysis");
// Initialize the parameters for the branches
Event *event;
GenParticle *particle;
Electron *electron;
Muon *muon;
Photon *photon;
MissingET *MeT;
ScalarHT *Scalar_HT;
Jet *jet1, *jet2, *jet3, *jet4;
TObject *object;
Int_t events, event_number, elec_n, muon_n, phot_n, jet_n, bjet_n;
Float_t weight, met, met_eta, met_phi, HT;
Double_t random;
Float_t elec_pt, elec_eta, elec_phi, elec_E, elec_sumpt_charged;
Float_t muon_pt, muon_eta, muon_phi, muon_E, muon_sumpt_charged;
Float_t phot_pt, phot_eta, phot_phi, phot_E;
Float_t jet1_pt, jet1_eta, jet1_phi, jet1_E;
Float_t jet2_pt, jet2_eta, jet2_phi, jet2_E;
Float_t jet3_pt, jet3_eta, jet3_phi, jet3_E;
Float_t jet4_pt, jet4_eta, jet4_phi, jet4_E;
Float_t bjet1_pt, bjet1_eta, bjet1_phi, bjet1_E;
Float_t bjet2_pt, bjet2_eta, bjet2_phi, bjet2_E;
Float_t bjet3_pt, bjet3_eta, bjet3_phi, bjet3_E;
Float_t ptj1j2, etaj1j2, mj1j2;
Float_t ptbj1j2, etabj1j2, mbj1j2;
Float_t ptj1j3, etaj1j3, mj1j3;
Float_t ptbj1j3, etabj1j3, mbj1j3;
Float_t ptj2j3, etaj2j3, mj2j3;
Float_t ptbj2j3, etabj2j3, mbj2j3;
// creating the branches
delphes.Branch("weight", &weight , "weight/F");
delphes.Branch("events", &events , "events/I");
delphes.Branch("elec_n", &elec_n , "elec_n/I");
delphes.Branch("elec_pt", &elec_pt);
delphes.Branch("elec_eta", &elec_eta);
delphes.Branch("elec_phi", &elec_phi);
delphes.Branch("elec_E", &elec_E);
delphes.Branch("elec_sumpt_charged", &elec_sumpt_charged);
delphes.Branch("muon_n", &muon_n , "muon_n/I");
delphes.Branch("muon_pt", &muon_pt);
delphes.Branch("muon_eta", &muon_eta);
delphes.Branch("muon_phi", &muon_phi);
delphes.Branch("muon_E", &muon_E);
delphes.Branch("muon_sumpt_charged", &muon_sumpt_charged);
delphes.Branch("phot_n", &phot_n , "phot_n/I");
delphes.Branch("phot_pt", &phot_pt);
delphes.Branch("phot_eta", &phot_eta);
delphes.Branch("phot_phi", &phot_phi);
delphes.Branch("phot_E", &phot_E);
delphes.Branch("met", &met , "met/F");
delphes.Branch("met_phi", &met_phi , "met_phi/F");
delphes.Branch("met_eta", &met_eta , "met_eta/F");
delphes.Branch("HT", &HT , "HT/F");
delphes.Branch("jet_n", &jet_n , "jet_n/I");
delphes.Branch("jet1_pt", &jet1_pt);
delphes.Branch("jet1_eta", &jet1_eta);
delphes.Branch("jet1_phi", &jet1_phi);
delphes.Branch("jet1_E", &jet1_E);
delphes.Branch("jet2_pt", &jet2_pt);
delphes.Branch("jet2_eta", &jet2_eta);
delphes.Branch("jet2_phi", &jet2_phi);
delphes.Branch("jet2_E", &jet2_E);
delphes.Branch("jet3_pt", &jet3_pt);
delphes.Branch("jet3_eta", &jet3_eta);
delphes.Branch("jet3_phi", &jet3_phi);
delphes.Branch("jet3_E", &jet3_E);
delphes.Branch("jet4_pt", &jet4_pt);
delphes.Branch("jet4_eta", &jet4_eta);
delphes.Branch("jet4_phi", &jet4_phi);
delphes.Branch("jet4_E", &jet4_E);
delphes.Branch("bjet1_pt", &bjet1_pt);
delphes.Branch("bjet1_eta", &bjet1_eta);
delphes.Branch("bjet1_phi", &bjet1_phi);
delphes.Branch("bjet1_E", &bjet1_E);
delphes.Branch("bjet2_pt", &bjet2_pt);
delphes.Branch("bjet2_eta", &bjet2_eta);
delphes.Branch("bjet2_phi", &bjet2_phi);
delphes.Branch("bjet2_E", &bjet2_E);
delphes.Branch("bjet3_pt", &bjet3_pt);
delphes.Branch("bjet3_eta", &bjet3_eta);
delphes.Branch("bjet3_phi", &bjet3_phi);
delphes.Branch("bjet3_E", &bjet3_E);
delphes.Branch("bjet_n", &bjet_n , "bjet_n/I");
delphes.Branch("pt_j1j2", &ptj1j2);
delphes.Branch("eta_j1j2", &etaj1j2);
delphes.Branch("m_j1j2", &mj1j2);
delphes.Branch("pt_j1j3", &ptj1j3);
delphes.Branch("eta_j1j3", &etaj1j3);
delphes.Branch("m_j1j3", &mj1j3);
delphes.Branch("pt_j2j3", &ptj2j3);
delphes.Branch("eta_j2j3", &etaj2j3);
delphes.Branch("m_j2j3", &mj2j3);
delphes.Branch("pt_bj1j2", &ptbj1j2);
delphes.Branch("eta_bj1j2", &etabj1j2);
delphes.Branch("m_bj1j2", &mbj1j2);
delphes.Branch("pt_bj1j3", &ptbj1j3);
delphes.Branch("eta_bj1j3", &etabj1j3);
delphes.Branch("m_bj1j3", &mbj1j3);
delphes.Branch("pt_bj2j3", &ptbj2j3);
delphes.Branch("eta_bj2j3", &etabj2j3);
delphes.Branch("m_bj2j3", &mbj2j3);
// Loop over all events
for(Int_t entry = 0; entry < nEntries; ++entry)
{
// Load selected branches with data from specified event
treeReader->ReadEntry(entry);
events = 0;
for(Int_t i = 0; i < branchEvent->GetEntries(); ++i)
{
event = (Event*) branchEvent->At(i);
events++;
event_number = event->Number;
// weight generation
weight = gRandom->Gaus(20,8);
weight = 0.001*weight;
}
elec_n = 0;
// Loop over all electrons in event
for(Int_t i = 0; i < branchElectron->GetEntries(); ++i)
{
electron = (Electron*) branchElectron->At(i);
elec_n++;
elec_pt = electron->PT;
elec_eta = electron->Eta;
elec_phi = electron->Phi;
elec_E = (electron->P4()).E();
elec_sumpt_charged = electron->SumPtCharged;
}
muon_n = 0;
for(Int_t i = 0; i < branchMuon->GetEntries(); ++i)
{
muon = (Muon*) branchMuon->At(i);
muon_n++;
muon_pt = muon->PT;
muon_eta = muon->Eta;
muon_phi = muon->Phi;
muon_E = (muon->P4()).E();
muon_sumpt_charged = muon->SumPtCharged;
}
phot_n = 0;
for(Int_t i = 0; i < branchPhoton->GetEntries(); ++i)
{
photon = (Photon*) branchPhoton->At(i);
phot_n++;
phot_pt = photon->PT;
phot_eta = photon->Eta;
phot_phi = photon->Phi;
phot_E = photon->E;
}
if(branchMissingET->GetEntries() > 0)
{
// Take MET
MeT = (MissingET*) branchMissingET->At(0);
met = MeT->MET;
met_phi = MeT->Phi;
met_eta = MeT->Eta;
}
for(Int_t i = 0; i < branchScalarHT->GetEntries(); ++i)
{
Scalar_HT = (ScalarHT*) branchScalarHT->At(i);
HT = Scalar_HT->HT;
}
jet_n = 0;
bjet_n = 0;
for(Int_t i = 0; i < branchJet->GetEntriesFast(); ++i)
{
// Take the jet
jet1 = (Jet*) branchJet->At(i);
jet2 = (Jet*) branchJet->At(i);
jet3 = (Jet*) branchJet->At(i);
jet4 = (Jet*) branchJet->At(i);
jet_n++;
// count the b-jets
if (jet1->BTag!=1){
jet1_pt = jet1->PT;
jet1_eta = jet1->Eta;
jet1_phi = jet1->Phi;
jet1_E = (jet1->P4()).E();
}
if(jet1->BTag==1){
bjet_n++;
bjet1_pt = jet1->PT;
bjet1_eta = jet1->Eta;
bjet1_phi = jet1->Phi;
bjet1_E = (jet1->P4()).E();
}
if (jet2->BTag!=1){
jet2_pt = jet2->PT;
jet2_eta = jet2->Eta;
jet2_phi = jet2->Phi;
jet2_E = (jet2->P4()).E();
}
if(jet2->BTag==1){
bjet_n++;
bjet2_pt = jet2->PT;
bjet2_eta = jet2->Eta;
bjet2_phi = jet2->Phi;
bjet2_E = (jet2->P4()).E();
}
if (jet3->BTag!=1){
jet3_pt = jet3->PT;
jet3_eta = jet3->Eta;
jet3_phi = jet3->Phi;
jet3_E = (jet3->P4()).E();
}
if(jet3->BTag==1){
bjet_n++;
bjet3_pt = jet3->PT;
bjet3_eta = jet3->Eta;
bjet3_phi = jet3->Phi;
bjet3_E = (jet3->P4()).E();
}
jet4_pt = jet4->PT;
jet4_eta = jet4->Eta;
jet4_phi = jet4->Phi;
jet4_E = (jet4->P4()).E();
if (jet1->BTag!=1 && jet2->BTag!=1){
ptj1j2 = (((jet1->P4()) + (jet2->P4()))).Pt();
etaj1j2 = (((jet1->P4()) + (jet2->P4()))).Eta();
mj1j2 = (((jet1->P4()) + (jet2->P4()))).M();
}
if (jet1->BTag==1 && jet2->BTag==1){
ptbj1j2 = (((jet1->P4()) + (jet2->P4()))).Pt();
etabj1j2 = (((jet1->P4()) + (jet2->P4()))).Eta();
mbj1j2 = (((jet1->P4()) + (jet2->P4()))).M();
}
if (jet1->BTag!=1 && jet3->BTag!=1){
ptj1j3 = (((jet1->P4()) + (jet3->P4()))).Pt();
etaj1j3 = (((jet1->P4()) + (jet3->P4()))).Eta();
mj1j3 = (((jet1->P4()) + (jet3->P4()))).M();
}
if (jet1->BTag==1 && jet3->BTag==1){
ptbj1j3 = (((jet1->P4()) + (jet2->P4()))).Pt();
etabj1j3 = (((jet1->P4()) + (jet2->P4()))).Eta();
mbj1j3 = (((jet1->P4()) + (jet2->P4()))).M();
}
if (jet2->BTag!=1 && jet3->BTag!=1){
ptj2j3 = (((jet1->P4()) + (jet3->P4()))).Pt();
etaj2j3 = (((jet1->P4()) + (jet3->P4()))).Eta();
mj2j3 = (((jet1->P4()) + (jet3->P4()))).M();
}
if (jet2->BTag==1 && jet3->BTag==1){
ptbj2j3 = (((jet2->P4()) + (jet3->P4()))).Pt();
etabj2j3 = (((jet2->P4()) + (jet3->P4()))).Eta();
mbj2j3 = (((jet2->P4()) + (jet3->P4()))).M();
}
}
// Fill inside the tree to all the created branches
delphes.Fill();
}
delphes.Write("",TObject::kWriteDelete); // TObject::kWriteDelete to remove the old snapshot and save the latest copy
//
// save the Tree ; the file will be automatically closed when going out oth function scope
}