Re: [ROOT] drawing form empty tree and ntuple with one variable

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Dec 18 2000 - 11:51:37 MET


Hi Miro,

Miroslav Helbich wrote:
> 
> Hi,
> 
>  I think this two features should be changed.
> 
> 1; when creating a TNtuple object with only one variable it gives me
> error in filling time. It works fine with more variables.
> 
> root [0]  TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px");
> root [1]  ntuple->Fill(1.);
> 
>  *** Break *** segmentation violation
> Root >
> 

There are two TNtuple::Fill functions. In case you use the form above,
CINT is confused with the second form TNtuple::Fill(float *x).
To remove the ambiguity, you can call ntuple->Fill(1,0).
Note that calling the second form TNtuple::Fill(float *x) is more efficient
and also support teh case with more than 15 variables.


> 2; When drawing histogram from an empty TTree or TNtuple object directly to
> histogram, it doesn't fill nor create this histogram. I think it should
> create some default empty histogram, otherwise I get errors when trying to
> work with it. I tried to use empty trees, when there were not any
> particles passing detector in the simulation.
> 
> Here is interpreter output and corresponding macro
> 
> root [2] .x ttree-bug.C
> Error: No symbol histo in current scope  FILE:ttree-bug.C LINE:12
> Error: Failed to evaluate histo->SetTitle("my histo") FILE:ttree-bug.C
> LINE:12
> Possible candidates are...
> filename       line:size busy function type and name
> 

yes, this is expected. If the variable does not exist or there are no entries,
the function cannot create an histogram (with which range ?).
In your script, you should test that the histogram exists with:
  TH1F *histo = (TH1F*)gDirectory->Get("histo");
  if (histo)...

Rene Brun


> // macro demonstrating use of empty ntuple
> {
>  gROOT->Reset();
>  Int_t nevent=0; // don't generate any events!
>  TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py");
> 
> for(Int_t i=0;i<nevent;i++) {
>   ntuple->Fill(gRandom->Gaus(10.,2.5),gRandom->Gaus(0.,0.7));
> }
> 
> ntuple->Draw("px>>histo");
> // I want to work with histogram (here just one example)
> histo->SetTitle("my histo");
> }
> 
>  I use version 2.25/03 on Suse Linux.
> 
>                                         Miro



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