Re: [ROOT] Draw histo from a tree

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Apr 13 2000 - 19:17:47 MEST


Hi Lionel,
Here is a small macro illustrating how to do what you want.
Run the macro followed by some commands

Root > .x lionel.C
Root > TFile f("lionel.root");
Root > T.Draw("myhisto.GetMean()")
Root > T.Draw("myhisto.GetBinContent(50)")

//file  lionel.C
{
   TH1F *myhisto = new TH1F("h","h",100,-3,3);
   TTree *CELL;

  // Create a ROOT TTree
   TFile *file = new TFile("lionel.root","recreate");
   CELL = new TTree("T","My TTree");
   CELL->Branch("myhisto","TH1F",&myhisto,128000,0);

  //... filling myhisto ...
  // here i fill the Tree 
    for (Int_t i=0;i<1000;i++) {
       myhisto->Fill(gRandom->Gaus(0,1));
       CELL->Fill();
    }
  // ... write CELL in a root file ...
    CELL->Write();
    file->Close();  
} 


Rene Brun



Neukermans Lionel wrote:
> 
> Dear all,
> 
> A basic question,
> I am running on dec/alpha/4, and using root version 2.24/02.
> 
> I have create a tree of which one branch is a TH1F object with the
> following procedure :
> 
> main(int argc, char **argv)
> {
> TH1F *myhisto;
> TTree *CELL;
> 
>   // Create a ROOT TTree
>   CELL = new TTree("T","My TTree");
>   CELL->Branch("myhisto","TH1F",&myhisto,128000,0);
> 
> ... filling myhisto ...
>  // here i fill the Tree
>       CELL->Fill();
> 
>  ... write CELL in a root file ...
> 
> return 0;
> }
> 
> I mean this is the right way to process, but how can I access to myhisto
> (draw it for example)?
> 
> Thanks,
> Lionel Neukermans



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:23 MET