1 | # example event loop macro
|
---|
2 | #!/usr/bin/env python
|
---|
3 |
|
---|
4 | import sys
|
---|
5 | import ROOT
|
---|
6 |
|
---|
7 | if len(sys.argv) < 2:
|
---|
8 | print " Usage: python macro.py data.root hist_data.root"
|
---|
9 | sys.exit(1)
|
---|
10 |
|
---|
11 | ROOT.gSystem.Load("libDelphes")
|
---|
12 |
|
---|
13 | try:
|
---|
14 | ROOT.gInterpreter.Declare('#include "classes/SortableObject.h"')
|
---|
15 | ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
|
---|
16 | ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
|
---|
17 | except:
|
---|
18 | pass
|
---|
19 |
|
---|
20 | inputFile = sys.argv[1]
|
---|
21 | outputFile = sys.argv[2]
|
---|
22 |
|
---|
23 | # Create chain of root trees
|
---|
24 | chain = ROOT.TChain("Delphes")
|
---|
25 | chain.Add(inputFile)
|
---|
26 |
|
---|
27 | # Create object of class ExRootTreeReader
|
---|
28 | treeReader = ROOT.ExRootTreeReader(chain)
|
---|
29 | numberOfEntries = treeReader.GetEntries()
|
---|
30 |
|
---|
31 | # Get pointers to branches used in this analysis
|
---|
32 | branchMuon = treeReader.UseBranch("Muon")
|
---|
33 | branchMissingET = treeReader.UseBranch("MissingET")
|
---|
34 | branchElectron = treeReader.UseBranch("Electron")
|
---|
35 |
|
---|
36 | # Book histograms
|
---|
37 | histMuonMultiplicity = ROOT.TH1F("histMuonMultiplicity", "histMuonMultiplicity", 5, -0.5, 4.5)
|
---|
38 | histLeadingMuonPt = ROOT.TH1F("histLeadingMuonPt", "histLeadingMuonPt", 50, 0., 100.)
|
---|
39 | histMissingET = ROOT.TH1F("histMissingET", "histMissingET", 50, 0., 100.)
|
---|
40 |
|
---|
41 | # Loop over all events
|
---|
42 | for entry in range(0, numberOfEntries):
|
---|
43 | # Load selected branches with data from specified event
|
---|
44 | treeReader.ReadEntry(entry)
|
---|
45 |
|
---|
46 | # loop over lepton collections
|
---|
47 | # store in an array only isolated muons above some pT
|
---|
48 | selected_muons = []
|
---|
49 | for muon in branchMuon:
|
---|
50 | if muon.PT < 15. or abs(muon.Eta)>4.0 or muon.IsolationVar > 0.25:
|
---|
51 | continue
|
---|
52 | selected_muons.append(muon)
|
---|
53 |
|
---|
54 | selected_electrons = []
|
---|
55 | for elec in branchElectron:
|
---|
56 | if elec.PT < 15. or abs(elec.Eta)>4.0 or elec.IsolationVar > 0.12:
|
---|
57 | continue
|
---|
58 | selected_electrons.append(elec)
|
---|
59 |
|
---|
60 | histMuonMultiplicity.Fill(len(selected_muons))
|
---|
61 |
|
---|
62 | if len(selected_muons) > 0:
|
---|
63 | histLeadingMuonPt.Fill(selected_muons[0].P4().Pt())
|
---|
64 |
|
---|
65 | # fill missing tranvserse energy
|
---|
66 |
|
---|
67 | met = branchMissingET[0].MET
|
---|
68 | histMissingET.Fill(met)
|
---|
69 |
|
---|
70 |
|
---|
71 | out_root = ROOT.TFile(outputFile,"RECREATE")
|
---|
72 |
|
---|
73 | histMuonMultiplicity.Write()
|
---|
74 | histLeadingMuonPt.Write()
|
---|
75 | histMissingET.Write()
|
---|