File indexing completed on 2024-04-06 12:04:42
0001 #ifndef Math_notmalizedPhi_h
0002 #define Math_notmalizedPhi_h
0003 #include "DataFormats/Math/interface/deltaPhi.h"
0004 #include <algorithm>
0005
0006
0007 template <typename T>
0008 constexpr T normalizedPhi(T phi) {
0009 return reco::reduceRange(phi);
0010 }
0011
0012
0013 template <typename T>
0014 constexpr T proxim(T b, T a) {
0015 constexpr T c1 = 2. * M_PI;
0016 constexpr T c2 = 1 / c1;
0017 return b + c1 * std::round(c2 * (a - b));
0018 }
0019
0020 #include <iostream>
0021
0022
0023 template <typename T>
0024 constexpr bool checkPhiInSymRange(T phi, T phi1, T phi2, float maxDphi = float(M_PI)) {
0025
0026 if (phi2 < phi1)
0027 std::swap(phi1, phi2);
0028 return checkPhiInRange(phi, phi1, phi2, maxDphi);
0029 }
0030
0031
0032 template <typename T>
0033 constexpr bool checkPhiInRange(T phi, T phi1, T phi2, float maxDphi = float(M_PI)) {
0034 phi2 = proxim(phi2, phi1);
0035 constexpr float c1 = 2. * M_PI;
0036 if (phi2 < phi1)
0037 phi2 += c1;
0038 auto dphi = std::min(maxDphi, 0.5f * (phi2 - phi1));
0039 auto phiA = phi1 + dphi;
0040 phi = proxim(phi, phiA);
0041 return std::abs(phiA - phi) < dphi;
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 }
0054
0055 #endif