ATLAS Offline Software
Loading...
Searching...
No Matches
phihelper.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
10#ifndef CXXUTILS_PHIHELPER_H
11#define CXXUTILS_PHIHELPER_H
12
13#include <cmath>
14#include <type_traits>
15
16namespace CxxUtils {
17
23 template <typename T>
24 inline T wrapToPi(T phi)
25 {
26 static_assert(std::is_floating_point<T>::value);
27
28 constexpr auto PI = static_cast<T>(M_PI);
29 // For large values this is faster:
30 if (phi < -100 || phi > 100) {
31 return std::remainder(phi, 2 * PI);
32 }
33 while (phi > PI) phi -= 2 * PI;
34 while (phi < -PI) phi += 2 * PI;
35 return phi;
36 }
37
41 template <typename T>
42 inline T deltaPhi(T phiA, T phiB)
43 {
44 static_assert(std::is_floating_point<T>::value);
45 return wrapToPi(phiA - phiB);
46 }
47
59 template <typename T>
60 inline T phiMean(T phiA, T phiB)
61 {
62 static_assert(std::is_floating_point<T>::value);
63 const T diff = wrapToPi(phiA - phiB);
64 return wrapToPi(phiB + 0.5 * diff);
65 }
66
76 template <typename T>
77 inline T phiBisect(T phiA, T phiB)
78 {
79 static_assert(std::is_floating_point<T>::value);
80 T phi = 0.5 * (phiA + phiB);
81 if (phiA > phiB) phi += M_PI;
82 return wrapToPi(phi);
83 }
84
85} // namespace CxxUtils
86
87#endif
#define M_PI
Scalar phi() const
phi method
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
T phiMean(T phiA, T phiB)
Calculate average of two angles.
Definition phihelper.h:60
T phiBisect(T phiA, T phiB)
Bisect (average) the angle spanned by phiA and phiB.
Definition phihelper.h:77
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition phihelper.h:24
T deltaPhi(T phiA, T phiB)
Return difference phiA - phiB in range [-pi, pi].
Definition phihelper.h:42
const float PI