Re: [ROOT] getting the total number of bins of an histo ?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Feb 02 2001 - 17:55:43 MET


Hi Yannick,

Misteries of inheritance ::)

a TH1F, TH2F, etc all derive from TH1 and TArrayxx
You can do
 Int_t ncells = h->GetSize()
where Getsize will be TArray::GetSize

For example, if you have a TH1F *h1 with 100 bins
 h1->GetSize() will return 102 (100 bins + Underflow + Overflow)

Rene Brun

Patois Yannick wrote:
> 
> Hi,
> 
> ROOT provide a mechanism to access each bins of an histo as a 1
> dimension array whatever the histo dimension is.
> 
> But surprisingly, there seems not to be any function that return the
> total number of bins for an histo. I have GetNbinsX,Y and Z, but not a
> 'GetBins' that would allow me to process the histo bins in a single loop
> whatever the dimension is, eg:
> int nbins=histo.GetNbins();
> for (int i=1;i<nbins;i++)
> histo.SetBinContent(sqrt(histo.GetBinContent(i));
> 
> That could work easily for any histo, whatever dimension it has.
> 
> Did I miss something ?
> 
>         Yannick



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:35 MET