Project
Loading...
Searching...
No Matches
MathUtils.h
Go to the documentation of this file.
1// Copyright 2019-2020 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 d = (x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1);
48 if (o2::gpu::CAMath::Abs(d) < o2::its::constants::Tolerance) {
49 return 0.f;
50 }
51 const float a =
52 0.5f * ((y3 - y2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1) - (y2 - y1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2));
53 const float b =
54 0.5f * ((x2 - x1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2) - (x3 - x2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1));
55 const float den = o2::gpu::CAMath::Hypot(d * x1 - a, d * y1 - b);
57 return 0.f;
58 }
59 return -d / den;
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 inifinity.
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() float Sq(float v)
95{
96 return v * v;
97}
98
99GPUhdi() float MSangle(float mass, float p, float xX0)
100{
101 float beta = p / o2::gpu::CAMath::Hypot(mass, p);
102 return 0.0136f * o2::gpu::CAMath::Sqrt(xX0) * (1.f + 0.038f * o2::gpu::CAMath::Log(xX0)) / (beta * p);
103}
104
105} // namespace o2::its::math_utils
106
107#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
constexpr float TwoPI
constexpr float PI
constexpr float VeryBig
constexpr float Tolerance
Definition Constants.h:28
float float x2
Definition MathUtils.h:44
float float xX0
Definition MathUtils.h:100
float float float float float z2
Definition MathUtils.h:80
float float float float float y3
Definition MathUtils.h:45
float float float float x3
Definition MathUtils.h:44
const float den
Definition MathUtils.h:55
GPUhdi() float computePhi(float x
Definition MathUtils.h:38
const float k1
Definition MathUtils.h:72
const float k2
Definition MathUtils.h:72
float float float float z1
Definition MathUtils.h:79
float float float y2
Definition MathUtils.h:44