Fork me on GitHub

source: git/examples/Example1.py@ 78a2d4c

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 78a2d4c was 4f1b152, checked in by Pavel Demin <pavel.demin@…>, 8 years ago

add includes to Example1.py

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