Re: TH1 as TTree branch??

Rene Brun (Rene.Brun@cern.ch)
Thu, 16 Apr 1998 16:34:15 +0200


William J Deninger wrote:
>
> Rene,
> How is one able to view via the TBrowser the "sum" of all histograms stored
> in a tree tree. Is it even possible?
>
> Thanks again, William
>
> //______________________
> // incorrect attempt
> //______________________
> {
> // open root file
> TFile f= new TFile("test.root", "recreate");
> f->SetCompressionLevel(1);
>
> // create canvas.. for viewing stuff
> TCanvas *c1 = new TCanvas("c1","canvas");
> c1->cd();
>
> // create tree
> TTree *tree = new TTree("tree","test");
> tree->SetAutoSave(64000000); // 64MB autosave
>
> // create event tree branch
> TSimple *simple = new TSimple;
> TH1F *hist = new TH1F("hist","test histogram",100,0,100);
> simple->hist = hist;
>
> tree->Branch("simple","TSimple",&simple,16000,1);
>
> // loop filling tree with 100 items
> Int_t i;
> for (i=0; i<100; i++) { hist->Fill( (Float_t) i); tree->Fill(); }
>
> // create browser
> bb = new TBrowser;
> tree->Draw("hist");
> }

You can execute commands like:
tree->Draw("hist.GetEntries()")
tree->Draw("hist.GetMean()")
tree->Draw("hist.GetBinContent(5)")

you can invoke any member function of the object in the branch.

Rene Brun