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