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

From: Nick van Eijndhoven (Nick@phys.uu.nl)
Date: Mon Feb 05 2001 - 09:49:35 MET


Hi Rene,
I agree with Yannick that for TH1 derived objects a memberfunction
GetNbins(), returning the total number of bins, would be very convenient.
This would prevent people from making the mistake of counting the
underflow and overflow bins as well.

                                                  Cheers,
                                                   Nick.

-- 
Dr. Nick van Eijndhoven mailto:nick@phys.uu.nl http://www.phys.uu.nl/~nick
--------------------------------------------------------------------------
Org.:    Utrecht University/Nikhef, Department of Subatomic Physics
Address: P.O. Box 80.000, NL-3508 TA Utrecht, The Netherlands
Phone:   +31-30-2532331(direct) +31-30-2531492(secr.)  Fax: +31-30-2518689
NIKHEF:  +31-20-5922028(direct) +31-20-5922000(secr.)  Fax: +31-20-5925155
CERN:    +41-22-7679751(direct) +41-22-7675857(secr.)  Fax: +41-22-7679480
Offices: Buys Ballot lab. 710 (Utrecht)   H350 (Nikhef)   B23 1-020 (CERN)
--------------------------------------------------------------------------


Rene Brun wrote:
> 
> 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