On Wed, 14 May 2003, jrieger wrote: > Thanks for the quick response. But what I would like to do is write the > array of histograms as an array, rather than have each individual > histogram appear separately in the root file. I am trying to preserve the > position in the array so that I can compare it to another array. Is this > something that can be done? Thanks again > > Jason Hi Jason, you can use TList to keep track of your hists: // put hist in a TList { TH1F *myhist; TList * hlist= new TList(); char *histname = new char[10]; for (Int_t h=0; h<5; h++) { sprintf(histname, "h_x_%d",h); myhist = new TH1F(histname,"",100,-0.25,0.25); // add it to the list hlist->Add(myhist); for (Int_t iii=0;iii<100; iii++) { myhist ->SetBinContent(iii,iii*2); } } TFile f("test.root", "RECREATE"); // write out as list hlist->Write("myhists", TObject::kSingleKey); f.Close(); } // to get them back { TFile f("test.root"); f.ls() TList * hlist = (TList*)f.Get("myhists"); TH1 * h = (TH1 *)hlist->At(0); h->Print() } Cheers Otto -- Otto Schaile Sektion Physik, LMU Muenchen Phone: +49 89 289 14070 Am Coulombwall 1, D-85748 Garching, Germany GSM: +49 160 1553598 FAX: +49 89 289 14072 EMail: Otto.Schaile@Physik.Uni-Muenchen.DE
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET