Damir Buskulic wrote: > > A series of histograms have been filled with hbook and converted with > h2root. Their names are now h1..h9 (for example) How can I access histo > hi in a loop over all the histograms ? > For instance, how would you translate this PAW sequence to ROOT ? > > DO I=1,9 > H/PL [i] > ENDDO > > Of course, creating histos from scratch is obvious, just have to define > an array. The problem is for histos converted with h2root. > On the other hand, what should I do to keep this "array" arrangement when > I save the histos to a file ? Put them in different branches of a Tree ? > > Several solutions to this problem, depending what you want to do. I will mention only two: - solution1. Use sprintf to create the histogram name from the loop index - solution2. Create an interator. Example { gROOT->Reset(); TFile f("marek.root"); f.Read(); // read all objects in memory TIter next(f.GetList()); //create an iterator to loop on list of objects TH1 *h; while (h=(TH1*)next()) { h->Print(); } } An extension of solution 2 to generate a PostScript file for each histogram in a ROOT file. Each file will get the corresponding histogram name: { gROOT->Reset(); TFile f("marek.root"); f.Read(); // read all objects in memory c1 = new TCanvas("c1"); TIter next(f.GetList()); //create an iterator to loop on list of objects TH1 *h; while (h=(TH1*)next()) { h->Draw(); c1->Print(h->GetName()); } } Rene Brun
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET