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>
10 
11 // cernlib V306
12 template<typename T>
13 constexpr
14 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>
25 bool checkPhiInSymRange(T phi, T phi1, T phi2, float maxDphi=float(M_PI)) {
26  // symmetrize
27  if (phi2<phi1) std::swap(phi1,phi2);
28  return checkPhiInRange(phi,phi1,phi2,maxDphi);
29 }
30 
31 // counterclock-wise range
32 template<typename T>
34 bool checkPhiInRange(T phi, T phi1, T phi2, float maxDphi=float(M_PI)) {
35  phi2 = proxim(phi2,phi1);
36  constexpr float c1 = 2.*M_PI;
37  if (phi2<phi1) 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:15
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:9
#define constexpr
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]
T min(T a, T b)
Definition: MathUtil.h:58
constexpr bool checkPhiInSymRange(T phi, T phi1, T phi2, float maxDphi=float(M_PI))
Definition: normalizedPhi.h:25
#define M_PI
double b
Definition: hdecay.h:120
constexpr bool checkPhiInRange(T phi, T phi1, T phi2, float maxDphi=float(M_PI))
Definition: normalizedPhi.h:34
double a
Definition: hdecay.h:121
long double T