Re: extracting bin contents (fwd)

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Mar 27 1997 - 12:28:28 MET


Laurent Mirabito wrote:
> 
>         Hello,
> 
> I found a strange behaviour with the functions Fill, GetBinContent and
> SetBinContent.
> Using the following macro
> {
> gROOT.Reset();
> UShort_t cnt[3];
> cnt[0]= 1001;
> cnt[1]= 1002;
> cnt[2]= 1003;
> TH1S toto("t","Test",3,-0.1,2.9);
> TH1S toto1("t1","Test",3,-0.1,2.9);
> for (Int_t j=0;j<3;j++)
>   { toto.SetBinContent(j,cnt[j]);
>   printf("toto: channel %d content %d \n",j,toto.GetBinContent(j));
> toto1.Fill(j,cnt[j]);
>   printf("toto1: channel %d content %d \n",j,toto1.GetBinContent(j));
>   printf("toto1+: channel %d content %d \n",j,toto1.GetBinContent(j+1));}
> 
> }
> 
> I obtain:
> 
> toto: channel 0 content 1001
> toto1: channel 0 content 0
> toto1+: channel 0 content 1001
> toto: channel 1 content 1002
> toto1: channel 1 content 1001
> toto1+: channel 1 content 1002
> toto: channel 2 content 1003
> toto1: channel 2 content 1002
> toto1+: channel 2 content 1003
> 
> Is the bin range running between 0,nbins-1 or 1,nbins?
> Why in this particular case Fill and SetBinContent does not give
> identical results?
> 

With histograms, bin number 0 is underflow bin and bin 1 the first
normal bin. SetBinContent(0,..) sets the underflow bin.
Fill(0,..) will fill bin corresponding to abscissa 0, in your case
this is not the underflow bin, but the first bin.
So results are as expected.

Rene Brun



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