Skip to content

Commit 3300278

Browse files
authored
[Common] RecoDecay::constrainAngle: Support harmonics (AliceO2Group#8816)
1 parent 422f890 commit 3300278

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Common/Core/RecoDecay.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,23 @@ struct RecoDecay {
208208
/// Constrains angle to be within a range.
209209
/// \note Inspired by TVector2::Phi_0_2pi in ROOT.
210210
/// \param angle angle
211-
/// \param min minimum of the range
212-
/// \return value within [min, min + 2π).
211+
/// \param minimum minimum of the range
212+
/// \param harmonic harmonic number
213+
/// \return value of angle within [minimum, minimum + 2π / harmonic).
213214
template <typename T, typename U = float>
214-
static T constrainAngle(T angle, U min = 0.)
215+
static T constrainAngle(T angle, U minimum = 0.0F, unsigned int harmonic = 1U)
215216
{
216-
while (angle < min) {
217-
angle += o2::constants::math::TwoPI;
217+
auto period = o2::constants::math::TwoPI;
218+
if (harmonic != 1U) {
219+
period /= harmonic;
218220
}
219-
while (angle >= min + o2::constants::math::TwoPI) {
220-
angle -= o2::constants::math::TwoPI;
221+
while (angle < minimum) {
222+
angle += period;
221223
}
222-
return (T)angle;
224+
while (angle >= minimum + period) {
225+
angle -= period;
226+
}
227+
return angle;
223228
}
224229

225230
/// Calculates cosine of pointing angle.

0 commit comments

Comments
 (0)