Re: histograms binning

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Dec 09 1999 - 14:59:39 MET


Colin,
The following few lines are extracted from the TH1 documentation at
    http://root.cern.ch/root/html/TH1.html

*-*   Convention for numbering bins
*-*   =============================
*-*   For all histogram types: nbins, xlow, xup
*-*     bin = 0;       underflow bin
*-*     bin = 1;       first bin with low-edge xlow INCLUDED
*-*     bin = nbins;   last bin with upper-edge xup EXCLUDED
*-*     bin = nbins+1; overflow bin
*-*

In the case of 2-d and 3-d histograms (and consistent with 1-d
histograms)
you can do :
  int globalbin = h->GetBin(binx,biny) ;     // for a 2-d
  int globalbin = h->GetBin(binx,biny,binz); // for a 3-d
In case of 1-d
  int globalbin = h->GetBin(binx) = binx

You can then access the bin contents, errors, etc with
  h->GetBinContent(globalbin);

globalbin is a linearized bin number in one-dim structure.

Rene Brun

C. Bernet wrote:
> 
> Hi,
> 
> It looks like when you create a 2d histogram hist, bins in x and y start
> at 1.
> When you execute the following command :
> 
> hist->GetBin(1,1)
> 
> the result is not 1 (0 would also be ok) but 19 in my case (TH2F, 16*16
> bins).
> 
> Yet :
> hist->GetBin(0,0) gives 0. But if you try to fill this bin
> (hist->SetBinContent(0,1.)) and draw the TH2F, you see that this bin is
> out of range....
> 
> Does anybody know if it's a bug or if the previous bins are used for
> something else ?
> 
> Thanks a lot.
>             Colin



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