10#ifndef CXXUTILS_PHIHELPER_H
11#define CXXUTILS_PHIHELPER_H
30 template <std::
floating_po
int T>
33 constexpr T TWOPI = 2*std::numbers::pi_v<T>;
34 constexpr T INV2PI = std::numbers::inv_pi_v<T>/2;
39 static_assert (std::numeric_limits<T>::digits/2 <=
sizeof (
long int) * CHAR_BIT);
42 constexpr T TOINT = 0x1.8p0 *
43 (1ull<<(std::numeric_limits<T>::digits/2)) *
44 (1ull<<(std::numeric_limits<T>::digits-1-std::numeric_limits<T>::digits/2));
45 T ix = (
x + TOINT) - TOINT;
52 if (std::abs(
diff) == 0.5) {
54 else if (ix < 0) ++ix;
57 return phi - TWOPI*ix;
63 template <std::
floating_po
int T>
80 template <std::
floating_po
int T>
81 inline constexpr T
phiMean(T phiA, T phiB)
96 template <std::
floating_po
int T>
99 T
phi = 0.5 * (phiA + phiB);
100 if (phiA > phiB)
phi += std::numbers::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.
constexpr T deltaPhi(T phiA, T phiB)
Return difference phiA - phiB in range [-pi, pi].
constexpr T phiBisect(T phiA, T phiB)
Bisect (average) the angle spanned by phiA and phiB.
constexpr T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
constexpr T phiMean(T phiA, T phiB)
Calculate average of two angles.