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 [1]:
auto f = TFile::Open("http://indico.cern.ch/event/395198/material/0/0.root");
TTreeReader myReader("events",f);
TTreeReaderValue<vector<ROOT::Math::PxPyPzEVector>> tracksRV(myReader, "tracks");
TTreeReaderValue<int> 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 [2]:
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;
}
}