/* NOTE - this is a root6 macro. root5's way of accessing TTrees is a PITA */ #include "TFile.h" #include "TTree.h" #include "TH1D.h" #include "TTreeReader.h" #include "TTreeReaderValue.h" #include "TTreeReaderArray.h" using namespace std; void Readbackup_muons() { // use TChain just to get list of files in directory TChain chain("NtpSt"); std::string infilename; infilename = "muons-*.root"; chain.Add(infilename.c_str()); TObjArray* filelist = chain.GetListOfFiles(); TIter iter(filelist); // make two histograms; TH1D *zenHisto = new TH1D("zenHisto","zen",60,0.0,60.0); TH1D *aziHisto = new TH1D("azi","azi",60,0.0,60.0); // Loop over all files in chain element list until done selecting those TChainElement* element = 0; while ((element = dynamic_cast(iter.Next())) ) { cout<<" new input file "<GetTitle()<GetTitle()); if ( !CondenseFile->IsOpen() || CondenseFile->IsZombie() ) { cerr << "Warning! Failed to open file " << CondenseFile->GetName() << endl; delete CondenseFile; continue; } // make a tree reader instance: get the "data" tree out of CondenseFile TTreeReader muonReader("data", CondenseFile); // Let's look at number of tracks. Things where there are one value per event are accessed like this TTreeReaderValue ntrack(muonReader, "ntrack") // Things where there's an array per event (in our case, could // be a lot of tracks) are accessed like this TTreeReaderArray zen(muonReader, "zen"); TTreeReaderArray azi(muonReader, "azi"); // Loop over all entries of the TTree while (muonReader.Next()) { // TTreeReaderValue's are accessed with the "*" dereference for (UChar_t i = 0; i < *ntrack; i++) { // TTreeReaderArray's are accessed just straight up like this, fills in the data for length zenHisto->Fill(zen[i]); aziHisto->Fill(azi[i]); // free input tree stuff, close input file if (CondenseFile) { delete CondenseFile; CondenseFile = 0; } // also destructs input file tree } // drawing the histograms TCanvas* zenCanvas = new TCanvas("zenCanvas","zen",640,480); gPad->SetLogy(); zenHisto->Draw(); TCanvas* aziCanvas = new TCanvas("aziCanvas","azi",640,480); aziHisto->Draw(); } } }