forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathUtils.h
More file actions
134 lines (115 loc) · 4.05 KB
/
Copy pathMathUtils.h
File metadata and controls
134 lines (115 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file MathUtils.h
/// \brief
///
#ifndef O2_ITS_TRACKING_MATHUTILS_H_
#define O2_ITS_TRACKING_MATHUTILS_H_
#include "CommonConstants/MathConstants.h"
#include "ITStracking/Constants.h"
#include "MathUtils/Utils.h"
#include "GPUCommonMath.h"
#include "GPUCommonDef.h"
namespace o2::its::math_utils
{
GPUhdi() constexpr float computePhi(float x, float y)
{
return o2::math_utils::fastATan2(-y, -x) + o2::constants::math::PI;
}
GPUhdi() constexpr float hypot(float x, float y)
{
return o2::gpu::CAMath::Hypot(x, y);
}
GPUhdi() constexpr float getNormalizedPhi(float phi)
{
phi -= o2::constants::math::TwoPI * o2::gpu::CAMath::Floor(phi * (1.f / o2::constants::math::TwoPI));
return phi;
}
GPUhdi() constexpr float computeNormalizedPhi(float x, float y)
{
return getNormalizedPhi(computePhi(x, y));
}
GPUhdi() float computeCurvature(float x1, float y1, float x2, float y2, float x3, float y3)
{
// in case the triangle is degenerate we return infinite curvature.
const float area = ((x2 - x1) * (y3 - y1)) - ((x3 - x1) * (y2 - y1));
if (o2::gpu::CAMath::Abs(area) < constants::Tolerance) {
return o2::constants::math::Almost0;
}
const float dx1 = x2 - x1, dy1 = y2 - y1;
const float dx2 = x3 - x2, dy2 = y3 - y2;
const float dx3 = x1 - x3, dy3 = y1 - y3;
const float d1 = o2::gpu::CAMath::Sqrt((dx1 * dx1) + (dy1 * dy1));
const float d2 = o2::gpu::CAMath::Sqrt((dx2 * dx2) + (dy2 * dy2));
const float d3 = o2::gpu::CAMath::Sqrt((dx3 * dx3) + (dy3 * dy3));
return -2.f * area / (d1 * d2 * d3);
}
GPUhdi() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, float x3, float y3)
{
// in case the triangle is degenerate we return set the centre to infinity.
float dx21 = x2 - x1, dx32 = x3 - x2;
if (o2::gpu::CAMath::Abs(dx21) < o2::its::constants::Tolerance ||
o2::gpu::CAMath::Abs(dx32) < o2::its::constants::Tolerance) { // add small offset
x2 += 1e-4;
dx21 = x2 - x1;
dx32 = x3 - x2;
}
const float k1 = (y2 - y1) / dx21, k2 = (y3 - y2) / dx32;
if (o2::gpu::CAMath::Abs(k2 - k1) < o2::its::constants::Tolerance) {
return o2::constants::math::VeryBig;
}
return 0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1);
}
GPUhdi() float computeTanDipAngle(float x1, float y1, float x2, float y2, float z1, float z2)
{
// in case the points vertically align we go to pos/neg infinity.
const float d = o2::gpu::CAMath::Hypot(x1 - x2, y1 - y2);
if (o2::gpu::CAMath::Abs(d) < o2::its::constants::Tolerance) {
return ((z1 > z2) ? -1.f : 1.f) * o2::constants::math::VeryBig;
}
return (z1 - z2) / d;
}
GPUhdi() float smallestAngleDifference(float a, float b)
{
return o2::gpu::CAMath::Remainderf(b - a, o2::constants::math::TwoPI);
}
GPUhdi() bool isPhiDifferenceBelow(const float phiA, const float phiB, const float phiCut)
{
const float deltaPhi = o2::gpu::CAMath::Abs(phiA - phiB);
return deltaPhi < phiCut || deltaPhi > o2::constants::math::TwoPI - phiCut;
}
GPUhdi() constexpr float Sq(float v)
{
return v * v;
}
GPUhdi() constexpr float SqSum(float v, float w)
{
return Sq(v) + Sq(w);
}
GPUhdi() constexpr float SqSum(float u, float v, float w)
{
return Sq(u) + SqSum(v, w);
}
GPUhdi() constexpr float SqDiff(float x, float y)
{
return Sq(x - y);
}
GPUhdi() float MSangle(float mass, float p, float xX0)
{
if (xX0 <= 0.f) {
return 0.f;
}
float beta = p / o2::gpu::CAMath::Hypot(mass, p);
return 0.0136f * o2::gpu::CAMath::Sqrt(xX0) * (1.f + 0.038f * o2::gpu::CAMath::Log(xX0)) / (beta * p);
}
} // namespace o2::its::math_utils
#endif