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 TRACKINGITSU_INCLUDE_CAUTILS_H_
17#define TRACKINGITSU_INCLUDE_CAUTILS_H_
18
19#ifndef GPUCA_GPUCODE_DEVICE
20#include <array>
21#include <cmath>
22#include <cassert>
23#include <iostream>
24#endif
25
26#include "MathUtils/Utils.h"
28#include "GPUCommonMath.h"
29#include "GPUCommonDef.h"
30
31namespace o2
32{
33namespace its
34{
35
36namespace math_utils
37{
38GPUhdni() float computePhi(const float, const float);
39GPUhdni() float hypot(const float, const float);
40GPUhdni() constexpr float getNormalizedPhi(const float);
41GPUhdni() constexpr float3 crossProduct(const float3&, const float3&);
42GPUhdni() float computeCurvature(float x1, float y1, float x2, float y2, float x3, float y3);
43GPUhdni() float computeCurvatureCentreX(float x1, float y1, float x2, float y2, float x3, float y3);
44GPUhdni() float computeTanDipAngle(float x1, float y1, float x2, float y2, float z1, float z2);
45
46} // namespace math_utils
47
48GPUhdi() float math_utils::computePhi(const float x, const float y)
49{
50 //return o2::gpu::CAMath::ATan2(-yCoordinate, -xCoordinate) + constants::math::Pi;
51 return o2::math_utils::fastATan2(-y, -x) + constants::math::Pi;
52}
53
54GPUhdi() float math_utils::hypot(const float x, const float y)
55{
56 return o2::gpu::CAMath::Sqrt(x * x + y * y);
57}
58
59GPUhdi() constexpr float math_utils::getNormalizedPhi(const float phi)
60{
61 return (phi < 0) ? phi + constants::math::TwoPi : (phi > constants::math::TwoPi) ? phi - constants::math::TwoPi
62 : phi;
63}
64
65GPUhdi() constexpr float3 math_utils::crossProduct(const float3& firstVector, const float3& secondVector)
66{
67
68 return float3{(firstVector.y * secondVector.z) - (firstVector.z * secondVector.y),
69 (firstVector.z * secondVector.x) - (firstVector.x * secondVector.z),
70 (firstVector.x * secondVector.y) - (firstVector.y * secondVector.x)};
71}
72
73GPUhdi() float math_utils::computeCurvature(float x1, float y1, float x2, float y2, float x3, float y3)
74{
75 const float d = (x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1);
76 const float a =
77 0.5f * ((y3 - y2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1) - (y2 - y1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2));
78 const float b =
79 0.5f * ((x2 - x1) * (y3 * y3 - y2 * y2 + x3 * x3 - x2 * x2) - (x3 - x2) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1));
80 const float den2 = (d * x1 - a) * (d * x1 - a) + (d * y1 - b) * (d * y1 - b);
81 return den2 > 0.f ? -1.f * d / o2::gpu::CAMath::Sqrt(den2) : 0.f;
82}
83
84GPUhdi() float math_utils::computeCurvatureCentreX(float x1, float y1, float x2, float y2, float x3, float y3)
85{
86 float dx21 = x2 - x1, dx32 = x3 - x2;
87 if (dx21 == 0.f || dx32 == 0.f) { // add small offset
88 x2 += 1e-4;
89 dx21 = x2 - x1;
90 dx32 = x3 - x2;
91 }
92 float k1 = (y2 - y1) / dx21, k2 = (y3 - y2) / dx32;
93 return (k1 != k2) ? 0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1) : 1e5;
94}
95
96GPUhdi() float math_utils::computeTanDipAngle(float x1, float y1, float x2, float y2, float z1, float z2)
97{
98 return (z1 - z2) / o2::gpu::CAMath::Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
99}
100
101} // namespace its
102} // namespace o2
103
104#endif /* TRACKINGITSU_INCLUDE_CAUTILS_H_ */
General auxilliary methods.
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
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 Pi
Definition Constants.h:43
constexpr float TwoPi
Definition Constants.h:44
const float3 float float x2
Definition MathUtils.h:42
GPUhdni() float computePhi(const float
float float float float float z2
Definition MathUtils.h:44
const float3 float float float float float y3
Definition MathUtils.h:42
const float3 float float float float x3
Definition MathUtils.h:42
const float3 float y1
Definition MathUtils.h:42
float float float float z1
Definition MathUtils.h:44
const float3 float float float y2
Definition MathUtils.h:42
GPUhdi() Cell
Definition Cell.h:55
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...