Fork me on GitHub

Changes between Version 7 and Version 8 of WorkBook/Tutorials/Student


Ignore:
Timestamp:
Sep 8, 2019, 1:12:34 PM (5 years ago)
Author:
Michele Selvaggi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WorkBook/Tutorials/Student

    v7 v8  
    5757TFile *f = TFile::Open("data.root");
    5858TBrowser browser;
    59 f->Get("Delphes")->Draw("Electron.PT");
     59f->Get("Delphes")->Draw("Muon.PT");
    6060}}}
    6161
     
    6565
    6666{{{
    67 f->Get("Delphes")->Draw("Jet.P4().P()");
     67f->Get("Delphes")->Draw("Electron.P4().P()");
    6868f->Get("Delphes")->Draw("Jet.P4().M()");
    6969}}}
    7070
     71
     72In 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}}}.
     73The {{{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
     79import sys
     80import ROOT
     81
     82if len(sys.argv) < 2:
     83  print " Usage: python macro.py data.root histograms.root"
     84  sys.exit(1)
     85
     86ROOT.gSystem.Load("libDelphes")
     87
     88try:
     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"')
     92except:
     93  pass
     94
     95inputFile = sys.argv[1]
     96outputFile = sys.argv[2]
     97
     98# Create chain of root trees
     99chain = ROOT.TChain("Delphes")
     100chain.Add(inputFile)
     101
     102# Create object of class ExRootTreeReader
     103treeReader = ROOT.ExRootTreeReader(chain)
     104numberOfEntries = treeReader.GetEntries()
     105
     106# Get pointers to branches used in this analysis
     107branchMuon = treeReader.UseBranch("Muon")
     108branchJet = treeReader.UseBranch("Jet")
     109
     110# Book histograms
     111histMuonMultiplicity = ROOT.TH1F("histMuonMultiplicity", "M_{recoil} [GeV]", 60, 100.0, 160.0)
     112
     113ptot = ROOT.TLorentzVector(0.,0.,0.,240.)
     114# Loop over all events
     115for 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
     130out_root = ROOT.TFile(outputFile,"RECREATE")
     131histMass.Write()
     132}}}