Access TTree in Python using PyROOT and fill a histogram

In [1]:
from ROOTaaS.iPyROOT import ROOT
Welcome to ROOTaas Beta

Open a file which is located on the web. No type is to be specified for "f".

In [2]:
f = ROOT.TFile.Open("https://indico.cern.ch/event/395198/material/0/0.root");

Loop over the TTree called "events" in the file. It is accessed with the dot operator. Same holds for the access to the branches: no need to set them up - they are just accessed by name, again with the dot operator.

In [3]:
h = ROOT.TH1F("TracksPt","Tracks;Pt [GeV/c];#",128,0,64)
for event in f.events:
    for track in event.tracks:
        h.Fill(track.Pt())
h.Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
In [ ]: