# Number of bins in histogram

What is the meaning of SetBinContent(0) ?
Is it a bug to use this?
for example:

void bug2()
{
TH1D *h=new TH1D(“aaa”,“bbb”,10,1,11);

h->SetBinContent(1,2);
cout<<"bin 1 => "<GetBinContent(1)<<endl;
h->SetBinContent(0,4);
cout<<"bin 0 => "<GetBinContent(0)<<endl;
h->SetBinContent(-18,8);
cout<<"bin -18 => "<GetBinContent(-18)<<endl;
cout<<"bin 0 => "<GetBinContent(0)<<endl;
cout<<"bin 1 => "<GetBinContent(1)<<endl;
}

the output is:

bin 1 => 2
bin 0 => 4
bin -18 => 4
bin 0 => 4
bin 1 => 2

so SetBinContent(0) works properly!
Is this means that histogram has 11 bins, not 10 ?!

I’m asking becouse I have used many times before SetBinContetn(0), everythings seems to work properly, so I wonder if I must change everywhere SetBinContent(i) to SetbinContent(i+1);

regards
jimmij

See documentation of class TH1:
root.cern.ch/root/htmldoc/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 case of 2-D or 3-D histograms, a "global bin" number is defined.
For example, assuming a 3-D histogram with binx,biny,binz, the function
Int_t bin = h->GetBin(binx,biny,binz);
returns a global/linearized bin number. This global bin is useful
to access the bin information independently of the dimension.
``````

Rene