-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathutils.h
More file actions
215 lines (192 loc) · 5.94 KB
/
utils.h
File metadata and controls
215 lines (192 loc) · 5.94 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright 2019-2020 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 utils.h
/// @author ruben.shahoyan@cern.ch, michael.lettrich@cern.ch
/// @since 2021-02-01
/// @brief Collection of auxillary methods
#ifndef UTILS_H
#define UTILS_H
#include "CommonConstants/MathConstants.h"
#include "MathUtils/Utils.h"
#include "ReconstructionDataFormats/Track.h"
namespace o2
{
namespace align
{
using trackParam_t = typename track::TrackParametrizationWithError<double>;
using value_t = typename trackParam_t::value_t;
using dim2_t = typename trackParam_t::dim2_t;
using dim3_t = typename trackParam_t::dim3_t;
using params_t = typename trackParam_t::params_t;
using covMat_t = typename trackParam_t::covMat_t;
namespace utils
{
constexpr double AlmostZeroD = 1e-15;
constexpr float AlmostZeroF = 1e-11;
constexpr double AlmostOneD = 1. - AlmostZeroD;
constexpr float AlmostOneF = 1. - AlmostZeroF;
constexpr double TinyDist = 1.e-7; // ignore distances less that this
//_________________________________________________________________________________
enum { Coll,
Cosm,
NTrackTypes };
//_________________________________________________________________________________
inline constexpr double sectorDAlpha() noexcept
{
return constants::math::PI / 9;
};
//_________________________________________________________________________________
inline constexpr double sector2Alpha(int sect) noexcept
{
// get barrel sector alpha in -pi:pi format
if (sect > 8) {
sect -= 18;
}
return (sect + 0.5) * sectorDAlpha();
};
//_________________________________________________________________________________
inline int phi2Sector(double phi)
{
// get barrel sector from phi in -pi:pi format
int sect = math_utils::nintd((phi * constants::math::Rad2Deg - 10) / 20.);
if (sect < 0) {
sect += 18;
}
return sect;
};
//_________________________________________________________________________________
template <typename F>
inline constexpr void bringTo02Pi(F& phi) noexcept
{
// bring phi to 0-2pi range
if (phi < 0) {
phi += constants::math::TwoPI;
} else if (phi > constants::math::TwoPI) {
phi -= constants::math::TwoPI;
}
};
//_________________________________________________________________________________
template <typename F>
inline constexpr void bringToPiPM(F& phi) noexcept
{
// bring phi to -pi:pi range
if (phi > constants::math::PI) {
phi -= constants::math::TwoPI;
}
};
//_________________________________________________________________________________
template <typename F>
inline constexpr bool okForPhiMin(F phiMin, F phi) noexcept
{
// check if phi is above the phiMin, phi's must be in 0-2pi range
const F dphi = phi - phiMin;
if ((dphi > 0 && dphi < constants::math::PI) || dphi < -constants::math::PI) {
return true;
} else {
return false;
}
};
//_________________________________________________________________________________
template <typename F>
inline constexpr bool okForPhiMax(F phiMax, F phi) noexcept
{
// check if phi is below the phiMax, phi's must be in 0-2pi range
const F dphi = phi - phiMax;
if ((dphi < 0 && dphi > -constants::math::PI) || dphi > constants::math::PI) {
return true;
} else {
return false;
}
};
//_________________________________________________________________________________
template <typename F>
constexpr F meanPhiSmall(F phi0, F phi1)
{
// return mean phi, assume phis in 0:2pi
F phi;
if (!okForPhiMin(phi0, phi1)) {
phi = phi0;
phi0 = phi1;
phi1 = phi;
}
if (phi0 > phi1) {
phi = (phi1 - (constants::math::TwoPI - phi0)) / 2; // wrap
} else {
phi = (phi0 + phi1) / 2;
}
bringTo02Pi(phi);
return phi;
};
//_________________________________________________________________________________
template <typename F>
constexpr F deltaPhiSmall(F phi0, F phi1) noexcept
{
// return delta phi, assume phi is in 0:2pi
F del;
if (!okForPhiMin(phi0, phi1)) {
del = phi0;
phi0 = phi1;
phi1 = del;
}
del = phi1 - phi0;
if (del < 0) {
del += constants::math::TwoPI;
}
return del;
};
//_________________________________________________________________________________
template <typename F>
inline constexpr bool smallerAbs(F d, F tolD) noexcept
{
return std::abs(d) < tolD;
};
//_________________________________________________________________________________
template <typename F>
inline constexpr bool smaller(F d, F tolD) noexcept
{
return d < tolD;
}
inline constexpr bool isZeroAbs(double d) noexcept { return smallerAbs(d, AlmostZeroD); };
inline constexpr bool isZeroAbs(float f) noexcept { return smallerAbs(f, AlmostZeroF); }
inline constexpr bool isZeroPos(double d) noexcept { return smaller(d, AlmostZeroD); }
inline constexpr bool isZeroPos(float f) noexcept { return smaller(f, AlmostZeroF); }
//__________________________________________
inline constexpr int findKeyIndex(int key, const int* arr, int n) noexcept
{
// finds index of key in the array
int imn = 0;
int imx = n - 1;
while (imx >= imn) {
const int mid = (imx + imn) >> 1;
if (arr[mid] == key) {
return mid;
}
if (arr[mid] < key) {
imn = mid + 1;
} else {
imx = mid - 1;
}
}
return -1;
}
//_______________________________________________________________
inline void printBits(size_t patt, int maxBits)
{
// print maxBits of the pattern
maxBits = std::min(64, maxBits);
for (int i = 0; i < maxBits; i++) {
printf("%c", ((patt >> i) & 0x1) ? '+' : '-');
}
};
} // namespace utils
} // namespace align
} // namespace o2
#endif