sphenix-software-l AT lists.bnl.gov
Subject: sPHENIX discussion of software
List archive
- From: pinkenburg <pinkenburg AT bnl.gov>
- To: "sphenix-software-l AT lists.bnl.gov" <sphenix-software-l AT lists.bnl.gov>
- Subject: [Sphenix-software-l] why not to use TMath
- Date: Wed, 8 Jan 2020 21:34:31 -0500
Hi folks,
in the tutorial the question came why one should avoid TMath as much as possible. Have a look at TMath::ACos(double x):
inline Double_t TMath::ACos(Double_t x)
{
if (x < -1.) return TMath::Pi();
if (x < -1.) return TMath::Pi();
if (x > 1.)
return 0;
return acos(x);
}
You feed it an out of range argument and lo and behold it returns a valid value. Just start ROOT and try
root [0] double d = 1.;
root [1] double c = TMath::ACos(d);
root [2] cout << c << endl;
0
looks reasonable, now try
root [3] d = 2.;
root [4] c = TMath::ACos(d);
root [5] cout << c << endl;
0
then use the regular math acos function:
root [6] c = acos(d);
root [7] cout << c << endl;
nan
Just do not use TMath (blindly - check the source to see if it is doing what you would expect), bad input should lead to recognizably bad output, not valid values which can go unnoticed and create a peak if you have a few of them.
I rest my case
Chris
You feed it an out of range argument and lo and behold it returns a valid value. Just start ROOT and try
root [0] double d = 1.;
root [1] double c = TMath::ACos(d);
root [2] cout << c << endl;
0
looks reasonable, now try
root [3] d = 2.;
root [4] c = TMath::ACos(d);
root [5] cout << c << endl;
0
then use the regular math acos function:
root [6] c = acos(d);
root [7] cout << c << endl;
nan
Just do not use TMath (blindly - check the source to see if it is doing what you would expect), bad input should lead to recognizably bad output, not valid values which can go unnoticed and create a peak if you have a few of them.
I rest my case
Chris
-- ************************************************************* Christopher H. Pinkenburg ; pinkenburg AT bnl.gov ; http://www.phenix.bnl.gov/~pinkenbu Brookhaven National Laboratory ; phone: (631) 344-5692 Physics Department Bldg 510 C ; fax: (631) 344-3253 Upton, NY 11973-5000 *************************************************************
- [Sphenix-software-l] why not to use TMath, pinkenburg, 01/08/2020
Archive powered by MHonArc 2.6.24.