Re: Eta() of TVector3 affects comparison of variables

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Wed, 28 Jun 2006 08:48:28 +0200


Hi Sebastian,

This looks like a gcc3 problem. I have tested your example on all our supported platforms.
It works correctly everywhere with CINT and everywhere with compiled code except
with gcc3.2.3 and gcc3.4.3 (it works correctly with gcc3.4.5, gcc4.0.2

If you print a-b, it is really 0. Anyhow, it is know that one should never test equality
of 2 floating point numbers.

Rene Brun

Sebastian Naumann wrote:
> Hello everybody!
>
> A colleague of mine and I stumbled across the following problem: When we
> calculated an expression with a call to the Eta() function of TVector3
> (or
> TLorentzVector) *twice* and stored the result in two variables, they
> would not always be recognized as being the same.
>
> An example to illustrate my point:
>
> ##########################
>
> #include "Riostream.h"
> #include <TSystem.h>
> #include <TVector3.h>
>
>
> void test(){
>
> Double_t a;
> Double_t b;
> TVector3 vec1;
> TVector3 vec2;
> vec2.SetXYZ(1.,1.,1.);
> vec1.SetXYZ(10.,1.,1.);
> a = 0.5 * (vec1.PseudoRapidity()-vec2.PseudoRapidity());
> b = 0.5 * (vec1.PseudoRapidity()-vec2.PseudoRapidity());
> if (a == b) {
> cout << "identical:" << " a: " << a << " b: " << b << endl;
> }
> else {
> cout << "NOT identical:" << " a: " << a << " b: " << b << endl;
> }
>
> } // test()
> #####################
>
> To run use:
>
> gSystem->Load("libPhysics.so")
> .x test.C+
>
> This will output: "NOT identical: a: -0.279569 b: -0.279569"
> It DOES however work, if I replace "vec1.SetXYZ(10.,1.,1.);" with
> "vec1.SetXYZ(9.,1.,1.);" OR insert a statement like "gSystem->Sleep(0);",
> or any kind of "cout" between "b = ..." and "if ...". Replacing Eta()
> with Phi() did not cause this behavior.
>
> This shows up with root versions 3.10.02, 4.04 and 5.11 on linux.
>
> If you could shed some light on this issue, we'll be able to sleep better
> again! ;-)
>
> Sincerely yours,
>
> Sebastian Naumann
Received on Wed Jun 28 2006 - 08:48:37 MEST

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