From b526b9de4bb7c71e9f9d8d9e368addaff9bba522 Mon Sep 17 00:00:00 2001 From: Takashi Yamanaka <takashi.yamanaka@cern.ch> Date: Thu, 16 Mar 2017 15:18:11 +0100 Subject: [PATCH] Merge branch 'update_atan2' into 'master' Move to std::atan2, fix ATLASRECTS-3945 Closes ATLASRECTS-3945 See merge request !416 Former-commit-id: 86d170807d73cc3c2b001c77338254534ea0f218 --- .../MagFieldServices/src/AtlasFieldSvc.cxx | 65 +------------------ 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/MagneticField/MagFieldServices/src/AtlasFieldSvc.cxx b/MagneticField/MagFieldServices/src/AtlasFieldSvc.cxx index ee1a1deaeea..3f3c615b326 100644 --- a/MagneticField/MagFieldServices/src/AtlasFieldSvc.cxx +++ b/MagneticField/MagFieldServices/src/AtlasFieldSvc.cxx @@ -31,10 +31,6 @@ #include "TFile.h" #include "TTree.h" -namespace { - inline double atan2fast(double y, double x); -} - /** Constructor **/ MagField::AtlasFieldSvc::AtlasFieldSvc(const std::string& name,ISvcLocator* svc) : AthService(name,svc), @@ -438,8 +434,8 @@ void MagField::AtlasFieldSvc::getField(const double *xyz, double *bxyz, double * const double &x(xyz[0]); const double &y(xyz[1]); const double &z(xyz[2]); - double r = sqrt(x * x + y * y); - double phi = atan2fast(y, x); + double r = std::sqrt(x * x + y * y); + double phi = std::atan2(y, x); // test if the cache is valid if (!m_cache.inside(z, r, phi)) { @@ -1420,60 +1416,3 @@ int MagField::AtlasFieldSvc::memSize() const return size; } -// -// Fast (less accurate) atan2() -// -namespace { - -double atan2fast(double y, double x) -{ - const double halfpi(M_PI / 2.); - const double sixthpi(M_PI / 6.); - const double tansixthpi(tan(M_PI / 6.)); - const double tantwelfthpi(tan(M_PI / 12.)); - - bool complement(false); - bool sign(false); - bool region(false); - - // test zeros - if (y == 0.0) return 0.0; - if (x == 0.0) return halfpi; - - // normalize range to -pi/12 to pi/12 - double z = y / x; - if (z < 0) { - z = -z; - sign = true; - } - if (z > 1.0) { - z = 1.0 / z; - complement = true; - } - if (z > tantwelfthpi) { - z = (z - tansixthpi) / (1 + tansixthpi * z); - region = true; - } - - // compute approximate atan - const double c1 = 1.6867629106; - const double c2 = 0.4378497304; - const double c3 = 1.6867633134; - - double zz = z * z; - double v = (z * (c1 + zz * c2) / (c3 + zz)); - - // go back to the original range - if (region) v += sixthpi; - if (complement) v = halfpi - v; - if (sign) v = -v; - if (x < 0.0) { - if (v < 0.0) v += M_PI; - else v -= M_PI; - } - - return v; -} - -} - -- GitLab