Skip to content

Commit d96311e

Browse files
committed
ITS: try to optimize math+utils
1 parent 5fc90f8 commit d96311e

File tree

1 file changed

+15
-19
lines changed
  • Detectors/ITSMFT/ITS/tracking/include/ITStracking

1 file changed

+15
-19
lines changed

Detectors/ITSMFT/ITS/tracking/include/ITStracking/MathUtils.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef O2_ITS_TRACKING_MATHUTILS_H_
1717
#define O2_ITS_TRACKING_MATHUTILS_H_
1818

19+
#include <cmath>
1920
#include "CommonConstants/MathConstants.h"
2021
#include "MathUtils/Utils.h"
2122
#include "GPUCommonMath.h"
@@ -24,38 +25,34 @@
2425
namespace o2::its::math_utils
2526
{
2627

27-
GPUhdi() float computePhi(const float x, const float y)
28+
GPUhdi() float computePhi(float x, float y)
2829
{
2930
return o2::math_utils::fastATan2(-y, -x) + o2::constants::math::PI;
3031
}
3132

32-
GPUhdi() float hypot(const float x, const float y)
33+
GPUhdi() constexpr float hypot(float x, float y)
3334
{
34-
return o2::gpu::CAMath::Sqrt(x * x + y * y);
35+
return o2::gpu::CAMath::Hypot(x, y);
3536
}
3637

37-
GPUhdi() constexpr float getNormalizedPhi(const float phi)
38+
GPUhdi() constexpr float getNormalizedPhi(float phi)
3839
{
39-
return (phi < 0) ? phi + o2::constants::math::TwoPI : (phi > o2::constants::math::TwoPI) ? phi - o2::constants::math::TwoPI
40-
: phi;
41-
}
42-
43-
GPUhdi() constexpr float3 crossProduct(const float3& firstVector, const float3& secondVector)
44-
{
45-
return float3{(firstVector.y * secondVector.z) - (firstVector.z * secondVector.y),
46-
(firstVector.z * secondVector.x) - (firstVector.x * secondVector.z),
47-
(firstVector.x * secondVector.y) - (firstVector.y * secondVector.x)};
40+
phi -= o2::constants::math::TwoPI * std::floor(phi * (1.f / o2::constants::math::TwoPI));
41+
return phi;
4842
}
4943

5044
GPUhdi() float computeCurvature(float x1, float y1, float x2, float y2, float x3, float y3)
5145
{
5246
const float d = (x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1);
47+
if (o2::gpu::CAMath::Abs(d) < o2::constants::math::Almost0) {
48+
return 0.f;
49+
}
5350
const float a =
5451
0.5f * ((y3 - y2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1) - (y2 - y1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2));
5552
const float b =
5653
0.5f * ((x2 - x1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2) - (x3 - x2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1));
57-
const float den2 = (d * x1 - a) * (d * x1 - a) + (d * y1 - b) * (d * y1 - b);
58-
return den2 > 0.f ? -1.f * d / o2::gpu::CAMath::Sqrt(den2) : 0.f;
54+
const float den = o2::gpu::CAMath::Hypot(d * x1 - a, d * y1 - b);
55+
return -d / den;
5956
}
6057

6158
GPUhdi() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, float x3, float y3)
@@ -67,18 +64,17 @@ GPUhdi() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, f
6764
dx32 = x3 - x2;
6865
}
6966
float k1 = (y2 - y1) / dx21, k2 = (y3 - y2) / dx32;
70-
return (k1 != k2) ? 0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1) : 1e5;
67+
return (k1 != k2) ? 0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1) : 1e5f;
7168
}
7269

7370
GPUhdi() float computeTanDipAngle(float x1, float y1, float x2, float y2, float z1, float z2)
7471
{
75-
return (z1 - z2) / o2::gpu::CAMath::Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
72+
return (z1 - z2) / o2::gpu::CAMath::Hypot(x1 - x2, y1 - y2);
7673
}
7774

7875
GPUhdi() float smallestAngleDifference(float a, float b)
7976
{
80-
float diff = fmod(b - a + o2::constants::math::PI, o2::constants::math::TwoPI) - o2::constants::math::PI;
81-
return (diff < -o2::constants::math::PI) ? diff + o2::constants::math::TwoPI : ((diff > o2::constants::math::PI) ? diff - o2::constants::math::TwoPI : diff);
77+
return std::remainder(b - a, o2::constants::math::TwoPI);
8278
}
8379

8480
GPUhdi() float Sq(float v)

0 commit comments

Comments
 (0)