forked from delphes/delphes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExample1.py
71 lines (52 loc) · 1.68 KB
/
Example1.py
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
#!/usr/bin/env python
import sys
import ROOT
try:
input = raw_input
except:
pass
if len(sys.argv) < 2:
print(" Usage: Example1.py input_file")
sys.exit(1)
ROOT.gSystem.Load("libDelphes")
try:
ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
except:
pass
inputFile = sys.argv[1]
# Create chain of root trees
chain = ROOT.TChain("Delphes")
chain.Add(inputFile)
# Create object of class ExRootTreeReader
treeReader = ROOT.ExRootTreeReader(chain)
numberOfEntries = treeReader.GetEntries()
# Get pointers to branches used in this analysis
branchJet = treeReader.UseBranch("Jet")
branchElectron = treeReader.UseBranch("Electron")
# Book histograms
histJetPT = ROOT.TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0)
histMass = ROOT.TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0)
# Loop over all events
for entry in range(0, numberOfEntries):
# Load selected branches with data from specified event
treeReader.ReadEntry(entry)
# If event contains at least 1 jet
if branchJet.GetEntries() > 0:
# Take first jet
jet = branchJet.At(0)
# Plot jet transverse momentum
histJetPT.Fill(jet.PT)
# Print jet transverse momentum
print(jet.PT)
# If event contains at least 2 electrons
if branchElectron.GetEntries() > 1:
# Take first two electrons
elec1 = branchElectron.At(0)
elec2 = branchElectron.At(1)
# Plot their invariant mass
histMass.Fill(((elec1.P4()) + (elec2.P4())).M())
# Show resulting histograms
histJetPT.Draw()
histMass.Draw()
input("Press Enter to continue...")