Re: Histogramming an ntuple, tree ..

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jul 28 1998 - 15:43:52 MEST


lijowski@cosray2.wustl.edu wrote:
> 
>   Hello,
> 
>  Instead using Draw to plot histograms of the individual entries
>  in the root ntuple I would like to create histograms and fill them
>  with selected entries in the ntuple. I am not quite sure how to do it
>  after reading the existing documentation. In the next version of
>  the included macro I would create 2 x 27 x 27 histograms of the
>  same quantities and save them into a file.
> 
>  Thanks in advance for help.
> 
>   Michal Lijowski
> 

The TTree::Draw function is convenient to make a quick pass
through a Tree and generate one histogram. In general, a real
analysis requires filling many histograms in a loop.
In your case, you should make the loop yourself on all the entries
in the Tree.
   Int_t nentries = tree->GetEntries();
   for (Int_t i=0;i<nentries;i++) {
      tree->GetEvent(i); // read this event in memory
      //fill your histograms
   }
   // save/print your histograms

Look at $ROOTSYS/test/Event for an example.
A skeleton code for this kind of loop may be automatically
generated by TTree::MakeCode.

Rene Brun





> ------------------------------------------------------------------------
> Michal Lijowski                  Washington University
> Research Associate               St. Louis, MO 63130-4899, USA
> Department of Physics            phone:   314-935-6285
> Campus Box 1105                  email:   lijowski@cosray2.wustl.edu
> ------------------------------------------------------------------------
> 
>  //  read HBOOK generated ntuple and produce histograms of dx2 and dy2
> 
> void  make_dxdy_hists()
> 
> {
>    gROOT->Reset();
> 
>   // Connect CRIS ROOT ntuple file generated by h2root
>    //  from the HBOOK make_cris_ntuple.rz file
> 
>    TFile *f1 = new TFile("/data3/users/lijowski/make_cris_ntuple.root.1");
>    f1 -> ls();
> 
> // connect a tree to an ntuple in the input file
>    TTree *t9000 = (TTree*)f1 -> Get("h9000;1");
>    t9000 -> Print();
> 
> // create a new Root file
>     TFile *top = new TFile("dxdy_hists.root", "recreate");
> 
>    // create a new subdirectory in this file
>    TDirectory *cdTOP = top -> mkdir("TOP");
>    cdTOP -> cd();
> 
> // create two histograms one for dx2 and another for dy2
> 
>    char hname[20];
>    char htitle[80];
>    Float_t xmin = -1.2, xmax = 1.2;
>    Int_t  nbins = 120;
> 
>    sprintf(hname, "H2X-plane-dx2");
>    sprintf(htitle,"H2 X plane dx2");
>    TH1F *h2x = new TH1F(hname, htitle, nbins, xmin, xmax);
> 
> //   h2x -> Fill(dx2);
> 
>    sprintf(hname, "H2Y-plane-dy2");
>    sprintf(htitle,"H2 Y plane dy2");
>    TH1F *h2y = new TH1F(hname, htitle, nbins, xmin, xmax);
> 
> //   h2y -> Fill(dy2);
> 
>   // save histogram hierarchy in the file
>    top -> Write();
> }



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET