CMS 3D CMS Logo

normalizedPhi.h
Go to the documentation of this file.
1 #ifndef Math_notmalizedPhi_h
2 #define Math_notmalizedPhi_h
4 #include <algorithm>
5 
6 // return a value of phi into interval [-pi,+pi]
7 template <typename T>
8 constexpr T normalizedPhi(T phi) {
9  return reco::reduceRange(phi);
10 }
11 
12 // cernlib V306
13 template <typename T>
14 constexpr T proxim(T b, T a) {
15  constexpr T c1 = 2. * M_PI;
16  constexpr T c2 = 1 / c1;
17  return b + c1 * std::round(c2 * (a - b));
18 }
19 
20 #include <iostream>
21 
22 // smallest range
23 template <typename T>
24 constexpr bool checkPhiInSymRange(T phi, T phi1, T phi2, float maxDphi = float(M_PI)) {
25  // symmetrize
26  if (phi2 < phi1)
27  std::swap(phi1, phi2);
28  return checkPhiInRange(phi, phi1, phi2, maxDphi);
29 }
30 
31 // counterclock-wise range
32 template <typename T>
33 constexpr bool checkPhiInRange(T phi, T phi1, T phi2, float maxDphi = float(M_PI)) {
34  phi2 = proxim(phi2, phi1);
35  constexpr float c1 = 2. * M_PI;
36  if (phi2 < phi1)
37  phi2 += c1;
38  auto dphi = std::min(maxDphi, 0.5f * (phi2 - phi1));
39  auto phiA = phi1 + dphi;
40  phi = proxim(phi, phiA);
41  return std::abs(phiA - phi) < dphi;
42 
43  /* old "alternative algo"
44  constexpr T c1 = 2.*M_PI;
45  phi1 = normalizedPhi(phi1);
46  phi2 = proxim(phi2,phi1);
47  if (phi2<phi1) phi2+=c1;
48  // phi & phi1 are in [-pi,pi] range...
49  return ( (phi1 <= phi) & (phi <= phi2) )
50 // || ( (phi1 <= phi-c1) & (phi-c1 <= phi2) )
51  || ( (phi1 <= phi+c1) & (phi+c1 <= phi2) );
52  */
53 }
54 
55 #endif
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
constexpr T proxim(T b, T a)
Definition: normalizedPhi.h:14
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
constexpr bool checkPhiInSymRange(T phi, T phi1, T phi2, float maxDphi=float(M_PI))
Definition: normalizedPhi.h:24
#define M_PI
double b
Definition: hdecay.h:118
constexpr bool checkPhiInRange(T phi, T phi1, T phi2, float maxDphi=float(M_PI))
Definition: normalizedPhi.h:33
double a
Definition: hdecay.h:119
long double T