[3a73e6d] | 1 | #!/usr/bin/env python
|
---|
| 2 |
|
---|
| 3 | import sys
|
---|
| 4 |
|
---|
| 5 | import ROOT
|
---|
| 6 |
|
---|
| 7 | if len(sys.argv) < 2:
|
---|
| 8 | print " Usage: Example1.py input_file"
|
---|
| 9 | sys.exit(1)
|
---|
| 10 |
|
---|
| 11 | ROOT.gSystem.Load("libDelphes")
|
---|
| 12 |
|
---|
[4f1b152] | 13 | try:
|
---|
| 14 | ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
|
---|
| 15 | ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
|
---|
| 16 | except:
|
---|
| 17 | pass
|
---|
| 18 |
|
---|
[3a73e6d] | 19 | inputFile = sys.argv[1]
|
---|
| 20 |
|
---|
| 21 | # Create chain of root trees
|
---|
| 22 | chain = ROOT.TChain("Delphes")
|
---|
| 23 | chain.Add(inputFile)
|
---|
| 24 |
|
---|
| 25 | # Create object of class ExRootTreeReader
|
---|
| 26 | treeReader = ROOT.ExRootTreeReader(chain)
|
---|
| 27 | numberOfEntries = treeReader.GetEntries()
|
---|
| 28 |
|
---|
| 29 | # Get pointers to branches used in this analysis
|
---|
| 30 | branchJet = treeReader.UseBranch("Jet")
|
---|
| 31 | branchElectron = treeReader.UseBranch("Electron")
|
---|
| 32 |
|
---|
| 33 | # Book histograms
|
---|
| 34 | histJetPT = ROOT.TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0)
|
---|
| 35 | histMass = ROOT.TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0)
|
---|
| 36 |
|
---|
| 37 | # Loop over all events
|
---|
| 38 | for 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
|
---|
| 63 | histJetPT.Draw()
|
---|
| 64 | histMass.Draw()
|
---|
| 65 |
|
---|
[fbb617b] | 66 | raw_input("Press Enter to continue...")
|
---|