Re: [ROOT] Tree analysis

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Oct 13 2000 - 11:42:22 MEST


hi Bernhard .

Bernhard Ketzer wrote:
> 
> Hi Rooters,
> 
> I created a tree with two branches, each containing several arrays of
> floats and ints. In order to loop over the entries, I used MakeClass to
> create the skeleton analysis class (->Hits.C, Hits.h). Now instead of
> opening each ROOT file by hand and typing
>         Root > .L Hits.C
>         Root > Hits t
>         Root > t.GetEntry(12); // Fill t data members with entry number
> 12
>         Root > t.Show();       // Show values of entry 12
>         Root > t.Show(16);     // Read and show values of entry 16
>         Root > t.Loop();       // Loop on all entries,
> I wrote a little macro (analHits.C) to do that, which I append to this
> mail. The methods Hcreate and Hplot were added to the skeleton Hits.C to
> create and plot some histograms.
> 
> However, I ran into two problems:
> 
> 1. The Histograms are plotted on a canvas, which, however, gets cleared
> immediately after the macro exits. I understand that this is due to the
> loacl scope of the histograms created within Hits.C, but is there a way
> of saving them to the global scope?
> 

When you close your TFile, all associated histograms are automatically
deleted. If you do not want to have the automatic association, at the beginning
of your macro, add the statement:
   TH1::AddDirectory(0);
and your histograms will still be alive when the macro ends.

> 2. The macro runs without problems the first time it is executed, but
> the second time I do it, I get an error message like
> >>>>Function analHits() busy. loaded after
> >>>>"/afs/cern.ch/user/k/ketzer/compass/2000/analysis/./Hits.C"
> >>>>Error: G__unloadfile() Can not unload
> >>>>"/afs/cern.ch/user/k/ketzer/compass/2000/analysis/./Hits.C", file busy
> >>>>FILE:analHits.C LINE:11
> Do I really have to type .U Hits.C before I reexecute the macro?
> 

In a named macro, you should never put the statement gROOT->Reset();
Remove this line and you should be able to execute n times.
I think you would gain in proceeding like indicated in the code generated
by TTree::MakeClass
  root > .L Hits.C
  root > Hits h
  root > h.Loop()  or Process...

Rene Brun
> Any help would be greatly appreciated.
> 
> Cheers,
> 
> Bernhard
> 
> --
> -----------------------------------------------------------------------------
> Bernhard Ketzer                       Tel.: +41 22 76-76002  FAX: -77100
> CERN, EP Division                     GSM : +41 79 201 4404 (CERN
> 164404)
> CH-1211 Geneve 23                     Email: Bernhard.Ketzer@cern.ch
> 
>   --------------------------------------------------------------------------------
> 
>                     Name: analHits.C
>    analHits.C       Type: Plain Text (text/plain)
>                 Encoding: 7bit



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