From bca0a300ca24fa9440e892f02145eecc60eef418 Mon Sep 17 00:00:00 2001 From: Felix Schlepper Date: Sun, 31 May 2026 20:53:50 +0200 Subject: [PATCH] ITS: constexpr computePhi Signed-off-by: Felix Schlepper --- Common/MathUtils/include/MathUtils/Utils.h | 4 ++-- Common/MathUtils/include/MathUtils/detail/basicMath.h | 2 +- Common/MathUtils/include/MathUtils/detail/trigonometric.h | 4 ++-- Detectors/ITSMFT/ITS/tracking/include/ITStracking/MathUtils.h | 4 +--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Common/MathUtils/include/MathUtils/Utils.h b/Common/MathUtils/include/MathUtils/Utils.h index 79263b4142216..3c51245fc6c29 100644 --- a/Common/MathUtils/include/MathUtils/Utils.h +++ b/Common/MathUtils/include/MathUtils/Utils.h @@ -210,12 +210,12 @@ inline double angle2Alphad(double phi) return detail::angle2Alpha(phi); } -GPUhdi() float fastATan2(float y, float x) +GPUhdi() constexpr float fastATan2(float y, float x) { return detail::fastATan2(y, x); } -GPUhdi() double fastATan2d(double y, double x) +GPUhdi() constexpr double fastATan2d(double y, double x) { return detail::fastATan2(y, x); } diff --git a/Common/MathUtils/include/MathUtils/detail/basicMath.h b/Common/MathUtils/include/MathUtils/detail/basicMath.h index 1abe6ee878c39..059dd4cca66fb 100644 --- a/Common/MathUtils/include/MathUtils/detail/basicMath.h +++ b/Common/MathUtils/include/MathUtils/detail/basicMath.h @@ -34,7 +34,7 @@ namespace detail { template -GPUhdi() T copysign(T x, T y) +GPUhdi() constexpr T copysign(T x, T y) { return o2::gpu::GPUCommonMath::Copysign(x, y); } diff --git a/Common/MathUtils/include/MathUtils/detail/trigonometric.h b/Common/MathUtils/include/MathUtils/detail/trigonometric.h index 457210202ca54..68d002320df2e 100644 --- a/Common/MathUtils/include/MathUtils/detail/trigonometric.h +++ b/Common/MathUtils/include/MathUtils/detail/trigonometric.h @@ -269,7 +269,7 @@ GPUhdi() constexpr T deltaPhiSmall(T phi0, T phi1) } template -GPUhdi() T fastATan2(T y, T x) +GPUhdi() constexpr T fastATan2(T y, T x) { // Fast atan2(y,x) for any angle [-Pi,Pi] // Average inaccuracy: 0.00048 @@ -283,7 +283,7 @@ GPUhdi() T fastATan2(T y, T x) // https://stackoverflow.com/questions/42537957/fast-accurate-atan-arctan-approximation-algorithm constexpr T A = 0.0776509570923569; constexpr T B = -0.287434475393028; - constexpr T C = (Pi / 4 - A - B); + constexpr T C = ((Pi / 4) - A - B); const T a2 = a * a; return ((A * a2 + B) * a2 + C) * a; }; diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/MathUtils.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/MathUtils.h index 950d8c0a9117f..7b586df2108b9 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/MathUtils.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/MathUtils.h @@ -16,8 +16,6 @@ #ifndef O2_ITS_TRACKING_MATHUTILS_H_ #define O2_ITS_TRACKING_MATHUTILS_H_ -#include - #include "CommonConstants/MathConstants.h" #include "ITStracking/Constants.h" #include "MathUtils/Utils.h" @@ -27,7 +25,7 @@ namespace o2::its::math_utils { -GPUhdi() float computePhi(float x, float y) +GPUhdi() constexpr float computePhi(float x, float y) { return o2::math_utils::fastATan2(-y, -x) + o2::constants::math::PI; }