loopdir.C for Pyroot

Hi,

I am starting to learn how to plot with python and I was wondering if this loop can be done with python. My input is a simple root file with several branches containing histograms.

loopdir.C

void loopdir() {
   // example of script to loop on all the objects of a ROOT file directory
   // and print on Postscript all TH1 derived objects
   // This script uses the file generated by tutorial hsimple.C
   //Author: Rene Brun

   TFile *f1 = TFile::Open("hsimple.root");
   TIter next(f1->GetListOfKeys());
   TKey *key;
   TCanvas c1;
   c1.Print("hsimple.ps[");
   while ((key = (TKey*)next())) {
      TClass *cl = gROOT->GetClass(key->GetClassName());
      if (!cl->InheritsFrom("TH1")) continue;
      TH1 *h = (TH1*)key->ReadObj();
      h->Draw();
      c1.Print("hsimple.ps");
   }
   c1.Print("hsimple.ps]");
}

I would like to be able to rootfile.Get(“branchhistoname”) and then plot them in a loop like in the
script above.

Thank you in advance!
Uzziel

Hi,

I think I got what I need from this link.

Sharing it just in case google search leads people here.

Cheers,
Uzzie

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.