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
21#include "MathUtils/Utils.h"
22#include "GPUCommonMath.h"
23#include "GPUCommonDef.h"
24
26{
27
28GPUhdi() float computePhi(float x, float y)
29{
30 return o2::math_utils::fastATan2(-y, -x) + o2::constants::math::PI;
31}
32
33GPUhdi() constexpr float hypot(float x, float y)
34{
35 return o2::gpu::CAMath::Hypot(x, y);
36}
37
38GPUhdi() constexpr float getNormalizedPhi(float phi)
39{
40 phi -= o2::constants::math::TwoPI * o2::gpu::CAMath::Floor(phi * (1.f / o2::constants::math::TwoPI));
41 return phi;
42}
43
44GPUhdi() float computeCurvature(float x1, float y1, float x2, float y2, float x3, float y3)
45{
46 // in case the triangle is degenerate we return infinite curvature.
47 const float area = ((x2 - x1) * (y3 - y1)) - ((x3 - x1) * (y2 - y1));
48 if (o2::gpu::CAMath::Abs(area) < constants::Tolerance) {
50 }
51 const float dx1 = x2 - x1, dy1 = y2 - y1;
52 const float dx2 = x3 - x2, dy2 = y3 - y2;
53 const float dx3 = x1 - x3, dy3 = y1 - y3;
54 const float d1 = o2::gpu::CAMath::Sqrt((dx1 * dx1) + (dy1 * dy1));
55 const float d2 = o2::gpu::CAMath::Sqrt((dx2 * dx2) + (dy2 * dy2));
56 const float d3 = o2::gpu::CAMath::Sqrt((dx3 * dx3) + (dy3 * dy3));
57 return -2.f * area / (d1 * d2 * d3);
58}
59
60GPUhdi() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, float x3, float y3)
61{
62 // in case the triangle is degenerate we return set the centre to infinity.
63 float dx21 = x2 - x1, dx32 = x3 - x2;
64 if (o2::gpu::CAMath::Abs(dx21) < o2::its::constants::Tolerance ||
65 o2::gpu::CAMath::Abs(dx32) < o2::its::constants::Tolerance) { // add small offset
66 x2 += 1e-4;
67 dx21 = x2 - x1;
68 dx32 = x3 - x2;
69 }
70 const float k1 = (y2 - y1) / dx21, k2 = (y3 - y2) / dx32;
71 if (o2::gpu::CAMath::Abs(k2 - k1) < o2::its::constants::Tolerance) {
73 }
74 return 0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1);
75}
76
77GPUhdi() float computeTanDipAngle(float x1, float y1, float x2, float y2, float z1, float z2)
78{
79 // in case the points vertically align we go to pos/neg infinity.
80 const float d = o2::gpu::CAMath::Hypot(x1 - x2, y1 - y2);
81 if (o2::gpu::CAMath::Abs(d) < o2::its::constants::Tolerance) {
82 return ((z1 > z2) ? -1.f : 1.f) * o2::constants::math::VeryBig;
83 }
84 return (z1 - z2) / d;
85}
86
87GPUhdi() float smallestAngleDifference(float a, float b)
88{
89 return o2::gpu::CAMath::Remainderf(b - a, o2::constants::math::TwoPI);
90}
91
92GPUhdi() bool isPhiDifferenceBelow(const float phiA, const float phiB, const float phiCut)
93{
94 const float deltaPhi = o2::gpu::CAMath::Abs(phiA - phiB);
95 return deltaPhi < phiCut || deltaPhi > o2::constants::math::TwoPI - phiCut;
96}
97
98GPUhdi() constexpr float Sq(float v)
99{
100 return v * v;
101}
102
103GPUhdi() constexpr float SqSum(float v, float w)
104{
105 return Sq(v) + Sq(w);
106}
107
108GPUhdi() constexpr float SqSum(float u, float v, float w)
109{
110 return Sq(u) + SqSum(v, w);
111}
112
113GPUhdi() constexpr float SqDiff(float x, float y)
114{
115 return Sq(x - y);
116}
117
118GPUhdi() float MSangle(float mass, float p, float xX0)
119{
120 float beta = p / o2::gpu::CAMath::Hypot(mass, p);
121 return 0.0136f * o2::gpu::CAMath::Sqrt(xX0) * (1.f + 0.038f * o2::gpu::CAMath::Log(xX0)) / (beta * p);
122}
123
124} // namespace o2::its::math_utils
125
126#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:44
float float xX0
Definition MathUtils.h:119
float float float float float z2
Definition MathUtils.h:78
float float float float float y3
Definition MathUtils.h:45
float float float float x3
Definition MathUtils.h:44
GPUhdi() float computePhi(float x
Definition MathUtils.h:38
const float d3
Definition MathUtils.h:56
const float d1
Definition MathUtils.h:54
const float dx3
Definition MathUtils.h:53
const float dx1
Definition MathUtils.h:51
const float k1
Definition MathUtils.h:70
const float dy3
Definition MathUtils.h:53
const float dy2
Definition MathUtils.h:52
const float phiB
Definition MathUtils.h:92
const float k2
Definition MathUtils.h:70
return f * area(d1 *d2 *d3)
const float dy1
Definition MathUtils.h:51
float float float float z1
Definition MathUtils.h:77
float float float y2
Definition MathUtils.h:44
const float dx2
Definition MathUtils.h:52
const float d2
Definition MathUtils.h:55
const float const float phiCut
Definition MathUtils.h:93