ROOT and Python start-up exercises

  • You can find example ROOT files: /afs/
  • See documentation on the basic structure inside the ROOT file, the TTree.


Checked checkbox, round Open a root file with the TBrowser and look at the contents:

-bash-4.1$ root -l /afs/
root [1] new TBrowser

Checked checkbox, round See the contents of the file from the command line; e.g.:

root [2]
root [3] tree= _file0.Get(“susy”)
root [4] tree.Print()
root [5] tree.Print("mc*”)


Checked checkbox, round You can use python (PyROOT) to look into the root files. E.g. /afs/

-bash-4.1$ python


Checked checkbox, round Loop over the entries (just 10 entries) of the tree; Look at the pT, eta and phi of the jets in the events. /afs/

-bash-4.1$ python


Checked checkbox, round Loop over both files: /afs/ E.g. /afs/

-bash-4.1$ python /afs/


Checked checkbox, round Plot the pT, eta and phi of central jets only.


    for jet in range(tree.jet_AntiKt4LCTopo_n):
        if abs(tree.jet_AntiKt4LCTopo_eta[jet])<2.8:
    central_jets = sorted(central_jets_unsorted,reverse=True)


Checked checkbox, round Plot the DR between the two central leading jets > 80 GeV. DR is defined as: DR = sqrt(Deta^2 + Dphi^2).


Checked checkbox, round What is the efficiency of a 100 GeV truth cut? Ie. how is the shape of tree.jet_AntiKt4LCTopo_pt affected after a cut on tree.jet_AntiKt4TruthJets_pt[0] > 100 GeV?


  • plot hpT (the pT of the variable without any cut)
  • plot hpT_truthCut (the pT of the variable after the truth cut)
  • the efficiency is defined as eff = hpT_truthCut / hpT.
  • in PyROOT: efficiency = TGraphAsymmErrors(hpT_truthCut,hpT)


Checked checkbox, round Do 7 but for a 120GeV truth cut. Plot both efficiency plots in the same canvas, one in red and the other in green. Write a legend that indicates what each plot shows and add appropriate legends in the axis titles.

tip.gif /afs/ can be used as a coding example - though it doesn’t give the solution of the above questions.
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2013-06-24 - AnnaSfyrla
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback