Fork me on GitHub

source: git/examples/Example1.py@ 2628d2b

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 2628d2b was fbb617b, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

improve formatting and remove trailing spaces

  • Property mode set to 100644
File size: 1.5 KB
Line 
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
13inputFile = sys.argv[1]
14
15# Create chain of root trees
16chain = ROOT.TChain("Delphes")
17chain.Add(inputFile)
18
19# Create object of class ExRootTreeReader
20treeReader = ROOT.ExRootTreeReader(chain)
21numberOfEntries = treeReader.GetEntries()
22
23# Get pointers to branches used in this analysis
24branchJet = treeReader.UseBranch("Jet")
25branchElectron = treeReader.UseBranch("Electron")
26
27# Book histograms
28histJetPT = ROOT.TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0)
29histMass = ROOT.TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0)
30
31# Loop over all events
32for entry in range(0, numberOfEntries):
33 # Load selected branches with data from specified event
34 treeReader.ReadEntry(entry)
35
36 # If event contains at least 1 jet
37 if branchJet.GetEntries() > 0:
38 # Take first jet
39 jet = branchJet.At(0)
40
41 # Plot jet transverse momentum
42 histJetPT.Fill(jet.PT)
43
44 # Print jet transverse momentum
45 print jet.PT
46
47 # If event contains at least 2 electrons
48 if branchElectron.GetEntries() > 1:
49 # Take first two electrons
50 elec1 = branchElectron.At(0)
51 elec2 = branchElectron.At(1)
52
53 # Plot their invariant mass
54 histMass.Fill(((elec1.P4()) + (elec2.P4())).M())
55
56# Show resulting histograms
57histJetPT.Draw()
58histMass.Draw()
59
60raw_input("Press Enter to continue...")
Note: See TracBrowser for help on using the repository browser.