Re: if (htotal <= 0.0) return -1.0E32; causes problems

Rene Brun (Rene.Brun@cern.ch)
Mon, 20 Apr 1998 16:03:22 +0200


Chris Jillings wrote:
>
> Hi all,
> I am working in the interpreter in Linux with version 2.00/00
> (9 March 1998). I do the following
> .L ../tools/fifty80.C
> .L correlation.C
> correlation("rootfile.root"); // this makes a histogram and calls
> // th function fifty80 below.
>
> Float_t fifty80(TH1 *hi, Float_t fraction = 0.8) {
> Double_t total = 0.0;
> Int_t nBins = hi->GetNbinsX();
> Int_t i = 0;
> Stat_t htotal = hi->GetIntegral();
> printf("%f\n",htotal);
> // if (htotal <= 0.0) return -1.0E32;
> Double_t cutoff;
> cutoff = (1.0-fraction)*htotal;
> Double_t answer;
> printf("%f\n",cutoff);
> printf("Warning: Using a grainy 50/80. Only as good as bin width.\n");
>
> for( i=1 ; i<=nBins ; i++) {
> total += hi->GetBinContent(i);
> printf("%d\t%f\t%f\n",i,total,cutoff);
> if (total>cutoff) break;
> }
> answer = hi->GetBinCenter(i);
> printf("Value of %f point on histogram is %f.\n",fraction,answer);
> return answer;
> }
>
> The first problem is the line (now commented out) with the condition
> followed by a return statement gives the interpreter amnesia. That is to
> say the interpreter can not find the value of cutoff so the routine fails.
>

Hi Chris,
I have reported this problem to Masa. It looks like CINT
does not like a variable declaration following this kind
of if statement. Meanwhile, if you move the declaration
Double_t cutoff
at the top of the function, your function works correctly.

> The second problem concerns bin numbering. This routine only works when I
> count from 1 to nBins. I would have excpected 0 to nBins-1. Is there
> documention about where unit-offset counting is performed as opposed to
> zero-offset counting?

In ROOT, we have tried to be consistent everywhere with the C/C++
convention of start counting at 0. This is also true in the case
of histogram bins. BUT, note that the UNDERFLOW bin is bin 0
and OVERFLOW bin is bin NBINS+1. So you get:
underflow bin with hist->GetBinContent(0);
1st real bin with hist->GetBinContent(1)

Rene Brun