| 71 | |
| 72 | In order to perform an event-loop with a more sophisticated event selection you will have to write a small python macro. This macro takes as input the {{{data.root}}} and produce an output file that contains a couple of histograms. Copy paste inside a file called {{{macro.py}}}, and run it via the command {{{python example.py histograms.root}}}. |
| 73 | The {{{histograms.root}}} file can then be browsed as done before with the data file. |
| 74 | |
| 75 | {{{ |
| 76 | # example event loop macro |
| 77 | #!/usr/bin/env python |
| 78 | |
| 79 | import sys |
| 80 | import ROOT |
| 81 | |
| 82 | if len(sys.argv) < 2: |
| 83 | print " Usage: python macro.py data.root histograms.root" |
| 84 | sys.exit(1) |
| 85 | |
| 86 | ROOT.gSystem.Load("libDelphes") |
| 87 | |
| 88 | try: |
| 89 | ROOT.gInterpreter.Declare('#include "classes/SortableObject.h"') |
| 90 | ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"') |
| 91 | ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"') |
| 92 | except: |
| 93 | pass |
| 94 | |
| 95 | inputFile = sys.argv[1] |
| 96 | outputFile = sys.argv[2] |
| 97 | |
| 98 | # Create chain of root trees |
| 99 | chain = ROOT.TChain("Delphes") |
| 100 | chain.Add(inputFile) |
| 101 | |
| 102 | # Create object of class ExRootTreeReader |
| 103 | treeReader = ROOT.ExRootTreeReader(chain) |
| 104 | numberOfEntries = treeReader.GetEntries() |
| 105 | |
| 106 | # Get pointers to branches used in this analysis |
| 107 | branchMuon = treeReader.UseBranch("Muon") |
| 108 | branchJet = treeReader.UseBranch("Jet") |
| 109 | |
| 110 | # Book histograms |
| 111 | histMuonMultiplicity = ROOT.TH1F("histMuonMultiplicity", "M_{recoil} [GeV]", 60, 100.0, 160.0) |
| 112 | |
| 113 | ptot = ROOT.TLorentzVector(0.,0.,0.,240.) |
| 114 | # Loop over all events |
| 115 | for entry in range(0, numberOfEntries): |
| 116 | # Load selected branches with data from specified event |
| 117 | treeReader.ReadEntry(entry) |
| 118 | |
| 119 | # If event contains at least 2 muons |
| 120 | if branchMuon.GetEntries() > 1: |
| 121 | |
| 122 | mu1 = branchMuon.At(0) |
| 123 | mu2 = branchMuon.At(1) |
| 124 | |
| 125 | pll = mu1.P4() + mu2.P4() |
| 126 | ph = ptot - pll |
| 127 | |
| 128 | histMass.Fill(ph.M()) |
| 129 | |
| 130 | out_root = ROOT.TFile(outputFile,"RECREATE") |
| 131 | histMass.Write() |
| 132 | }}} |