forked from delphes/delphes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example1.C
80 lines (61 loc) · 2.24 KB
/
Example1.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
/*
Simple macro showing how to access branches from the delphes output root file,
loop over events, and plot simple quantities such as the jet pt and the di-electron invariant
mass.
root -l examples/Example1.C'("delphes_output.root")'
*/
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#endif
//------------------------------------------------------------------------------
void Example1(const char *inputFile)
{
gSystem->Load("libDelphes");
// Create chain of root trees
TChain chain("Delphes");
chain.Add(inputFile);
// Create object of class ExRootTreeReader
ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
Long64_t numberOfEntries = treeReader->GetEntries();
// Get pointers to branches used in this analysis
TClonesArray *branchJet = treeReader->UseBranch("Jet");
TClonesArray *branchElectron = treeReader->UseBranch("Electron");
TClonesArray *branchEvent = treeReader->UseBranch("Event");
// Book histograms
TH1 *histJetPT = new TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0);
TH1 *histMass = new TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0);
// Loop over all events
for(Int_t entry = 0; entry < numberOfEntries; ++entry)
{
// Load selected branches with data from specified event
treeReader->ReadEntry(entry);
//HepMCEvent *event = (HepMCEvent*) branchEvent -> At(0);
//LHEFEvent *event = (LHEFEvent*) branchEvent -> At(0);
//Float_t weight = event->Weight;
// If event contains at least 1 jet
if(branchJet->GetEntries() > 0)
{
// Take first jet
Jet *jet = (Jet*) branchJet->At(0);
// Plot jet transverse momentum
histJetPT->Fill(jet->PT);
// Print jet transverse momentum
cout << "Jet pt: "<<jet->PT << endl;
}
Electron *elec1, *elec2;
// If event contains at least 2 electrons
if(branchElectron->GetEntries() > 1)
{
// Take first two electrons
elec1 = (Electron *) branchElectron->At(0);
elec2 = (Electron *) branchElectron->At(1);
// Plot their invariant mass
histMass->Fill(((elec1->P4()) + (elec2->P4())).M());
}
}
// Show resulting histograms
histJetPT->Draw();
histMass->Draw();
}