Fork me on GitHub

source: git/examples/Example1.py@ 8d7319c

Last change on this file since 8d7319c was 433360f, checked in by Pavel Demin <pavel.demin@…>, 7 years ago

adapt Example1.py to Python 3

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5import ROOT
6
7try:
8 input = raw_input
9except:
10 pass
11
12if len(sys.argv) < 2:
13 print(" Usage: Example1.py input_file")
14 sys.exit(1)
15
16ROOT.gSystem.Load("libDelphes")
17
18try:
19 ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
20 ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
21except:
22 pass
23
24inputFile = sys.argv[1]
25
26# Create chain of root trees
27chain = ROOT.TChain("Delphes")
28chain.Add(inputFile)
29
30# Create object of class ExRootTreeReader
31treeReader = ROOT.ExRootTreeReader(chain)
32numberOfEntries = treeReader.GetEntries()
33
34# Get pointers to branches used in this analysis
35branchJet = treeReader.UseBranch("Jet")
36branchElectron = treeReader.UseBranch("Electron")
37
38# Book histograms
39histJetPT = ROOT.TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0)
40histMass = ROOT.TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0)
41
42# Loop over all events
43for entry in range(0, numberOfEntries):
44 # Load selected branches with data from specified event
45 treeReader.ReadEntry(entry)
46
47 # If event contains at least 1 jet
48 if branchJet.GetEntries() > 0:
49 # Take first jet
50 jet = branchJet.At(0)
51
52 # Plot jet transverse momentum
53 histJetPT.Fill(jet.PT)
54
55 # Print jet transverse momentum
56 print(jet.PT)
57
58 # If event contains at least 2 electrons
59 if branchElectron.GetEntries() > 1:
60 # Take first two electrons
61 elec1 = branchElectron.At(0)
62 elec2 = branchElectron.At(1)
63
64 # Plot their invariant mass
65 histMass.Fill(((elec1.P4()) + (elec2.P4())).M())
66
67# Show resulting histograms
68histJetPT.Draw()
69histMass.Draw()
70
71input("Press Enter to continue...")
Note: See TracBrowser for help on using the repository browser.