Skip to content

Commit 3851877

Browse files
committed
ITS: try to optimize math+utils
1 parent f4e51af commit 3851877

File tree

1 file changed

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

1 file changed

+14
-19
lines changed

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,34 @@
2424
namespace o2::its::math_utils
2525
{
2626

27-
GPUhdi() float computePhi(const float x, const float y)
27+
GPUhdi() float computePhi(float x, float y)
2828
{
2929
return o2::math_utils::fastATan2(-y, -x) + o2::constants::math::PI;
3030
}
3131

32-
GPUhdi() float hypot(const float x, const float y)
32+
GPUhdi() constexpr float hypot(float x, float y)
3333
{
34-
return o2::gpu::CAMath::Sqrt(x * x + y * y);
34+
return o2::gpu::CAMath::Hypot(x, y);
3535
}
3636

37-
GPUhdi() constexpr float getNormalizedPhi(const float phi)
37+
GPUhdi() constexpr float getNormalizedPhi(float phi)
3838
{
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)};
39+
phi -= o2::constants::math::TwoPI * o2::gpu::CAMath::Floor(phi * (1.f / o2::constants::math::TwoPI));
40+
return phi;
4841
}
4942

5043
GPUhdi() float computeCurvature(float x1, float y1, float x2, float y2, float x3, float y3)
5144
{
5245
const float d = (x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1);
46+
if (o2::gpu::CAMath::Abs(d) < o2::constants::math::Almost0) {
47+
return 0.f;
48+
}
5349
const float a =
5450
0.5f * ((y3 - y2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1) - (y2 - y1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2));
5551
const float b =
5652
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;
53+
const float den = o2::gpu::CAMath::Hypot(d * x1 - a, d * y1 - b);
54+
return -d / den;
5955
}
6056

6157
GPUhdi() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, float x3, float y3)
@@ -67,18 +63,17 @@ GPUhdi() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, f
6763
dx32 = x3 - x2;
6864
}
6965
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;
66+
return (k1 != k2) ? 0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1) : 1e5f;
7167
}
7268

7369
GPUhdi() float computeTanDipAngle(float x1, float y1, float x2, float y2, float z1, float z2)
7470
{
75-
return (z1 - z2) / o2::gpu::CAMath::Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
71+
return (z1 - z2) / o2::gpu::CAMath::Hypot(x1 - x2, y1 - y2);
7672
}
7773

7874
GPUhdi() float smallestAngleDifference(float a, float b)
7975
{
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);
76+
return o2::gpu::CAMath::Remainderf(b - a, o2::constants::math::TwoPI);
8277
}
8378

8479
GPUhdi() float Sq(float v)

0 commit comments

Comments
 (0)