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