Re: TAxis bug

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Apr 07 1998 - 09:23:32 MEST


William J Deninger wrote:
> 
> -----Original Message-----
> From: Rene Brun <Rene.Brun@cern.ch>
> To: William J Deninger <deninger@uiuc.edu>
> Cc: roottalk <roottalk@hpsalo.cern.ch>
> Date: Monday, April 06, 1998 2:07 AM
> Subject: Re: TAxis bug
> 
> >William J Deninger wrote:
> >>
> >> Hello,
> >>
> >> There is a strange bug in 1.03/09 TAxis on my WinNT w/sp3 which can be
> >> illustrated in the following.
> >>
> >> TH1F *h = new TH1F("h","test",300,0,300);
> >> Int_t i;
> >> TAxis *a = h->GetXaxis();
> >> Float_t x = 55.0;
> >> Float_t fXmin = a->GetXmin();
> >> Float_t fXmax = a->GetXmax();
> >> Int_t fNbins = a->GetNbins();
> >>
> >> Int_t bin = a->FindBin(x); // result is incorrect
> >> Int_t bin1 = 1 + (Int_t) fNbins*(x - fXmin)/(fXmax-fXmin); // result
> >> is correct
> >>
> >> for (i=0; i<600; i++) h->Fill( i/2.0 );
> >> h->Draw();
> >>
> >> Has this been corrected on version 2.0?
> >>
> >
> >I am sorry. I cannot reproduce what you call "a bug".
> >I am getting the expected value bin=bin1=56
> >
> >When you want to see the list of changes in a new version,
> >read the version release notes available from the
> >Root "Availability and Status" page. For example
> >   http://root.cern.ch/root/html/examples/V2.00.txt.html
> >
> >Rene Brun
> >
> 
> Rene,
> 
> Perhaps this is a problem with the WinNT port of ROOT.  In the above example
> I find bin = 55,
> bin1 = 56, for v2.00/03 and v.1.03/08.  In fact, the incorrect TAxis bin
> calculation occurs several times over the interval [0,300) consistently.
> 
> www.npl.uiuc.edu/incoming/snap1.gif // console snap of above on WinNT w/sp3
> root v2.00/03
> www.npl.uiuc.edu/incoming/snap2.gif // histogram canvas on WinNT w/sp3 root
> 2.00/03
> 
> I use histograms commonly for data storage of straw tube drift time spectrum
> which are intern used to reconstruct particle trajectories...so it's
> important that binning is done in a consistent manner.  Certainly I'm able
> to use (and do) SetBinContent and override the bug, but it seems VERY
> peculiar that the code as published should result in this incorrect floating
> point result.  I cant reproduce it by recompiling that particular section of
> TAxis::FindBin code which worries me.  If the floating point error is do to
> a flaw in the version 4 Microsoft Compiler or because of a mistake in
> compiler settings while building the root NT port libraries, it may impact
> my analysis results..e.g, I rely heavily on TShape objects to return their
> global coordinates after a series of translations and orientation
> adjustments.
> 
> Does anyone else out in root land using NT get the same result?
> 
> William J Deninger


I have investigated your problem on all Unix platforms and NT.
NT is effectively given the "wrong" result. All Unix platforms are OK.
The problem on NT is simply a rounding error problem. It is not a bug.
May be there is an option (Valery please could you check) to optimize
floating point rounding with VC++.
Anyway, it is well know, that you should never fill histograms
with values corresponding exactly to the limits of the bins.
In your example, since you are looping on bin numbers, make sure
that the value passed to TH1::Fill is the center of the bin
and not one of the bin boundaries. If you make this trivial change
your program will behave correctly on NT.

Rene Brun



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