Re: Bug in TH::GetRandom() family?

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 31 Jan 2006 13:16:10 +0100 (MET)


Hi Ruben,

Interesting!
The probability for this case happening must be very very small. Which generator are you using: TRandom or TRandom3? Anyhow, I have protected the code as you suggest. Now in CVS. Thanks for this report.

Rene Brun

On Tue, 31
Jan 2006, Ruben Shahoyan wrote:

> Dear Rene,
> sometimes we get FPE (or nan assignment) in TH3::GetRandom3.
> I think the reason is the following: if there are empty bins in the
> histogram, then a few neighbouring elements of the fIntegral array will
> have the same value. If in the TH3::GetRandom3 the random "r1" happens
> to be exactly equal to such a value and as a result of
> Int_t ibin = TMath::BinarySearch(nbins,fIntegral,r1)
> the lower of such elements is found,
> then in the lines (915:916 of TH3.cxx for root.5.08)
> x = fXaxis.GetBinLowEdge(binx+1)
> +fXaxis.GetBinWidth(binx+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
> division by 0 happens.
> To avoid this on should change these lines to
> x = fXaxis.GetBinLowEdge(binx+1);
> if (r1>fIntegral[ibin]) x += fXaxis.GetBinWidth(binx+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
>
> The same should be true for TH2.cxx, lines 1060:1061, and
> in TH1.cxx one should change the lines 3268:3269 to
> double x = GetBinLowEdge(ibin+1);
> if (r1>fIntegral[ibin]) x += GetBinWidth(ibin+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
> return x;
>
> Best regards,
> Ruben
>
Received on Tue Jan 31 2006 - 13:16:18 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET