#!/usr/bin/env python # coding: utf-8 # # Access a TTree with the TTreeReader # In[1]: from ROOTaaS.iPyROOT import ROOT ROOT.toCpp() # Open a file which is located on the web. # Build a TTreeReader and two TTreeReader values, one for the tracks and one for the event number. # In[2]: auto f = TFile::Open("https://indico.cern.ch/event/395198/material/0/0.root"); TTreeReader myReader("events",f); TTreeReaderValue> tracksRV(myReader, "tracks"); TTreeReaderValue eventNumRV(myReader, "evtNum"); # Loop over the events stored in the tree. Analyse the transverse momentum of tracks and identify the maximum one. # Print the result every one hundred events. # In[3]: double maxPt; while(myReader.Next()){ auto evtNum (*eventNumRV); auto tracks = *tracksRV; maxPt = -1; for (auto&& track : tracks){ auto pt = track.Pt(); if (pt>maxPt) maxPt = pt; } if (evtNum %100 == 0) { std::cout << "Processing event number " << evtNum << std::endl; std::cout << "Max pt is " << maxPt << std::endl; } } # In[ ]: