-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeltaphi.h
66 lines (53 loc) · 1.52 KB
/
deltaphi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef DataFormats_Math_deltaPhi_h
#define DataFormats_Math_deltaPhi_h
/* function to compute deltaPhi
*
* Ported from original code in RecoJets
* by Fedor Ratnikov, FNAL
*/
#include <cmath>
namespace reco {
inline double deltaPhi(double phi1, double phi2) {
double result = phi1 - phi2;
while (result > M_PI) result -= 2*M_PI;
while (result <= -M_PI) result += 2*M_PI;
return result;
}
inline double deltaPhi(float phi1, double phi2) {
return deltaPhi(static_cast<double>(phi1), phi2);
}
inline double deltaPhi(double phi1, float phi2) {
return deltaPhi(phi1, static_cast<double>(phi2));
}
inline float deltaPhi(float phi1, float phi2) {
float result = phi1 - phi2;
while (result > float(M_PI)) result -= float(2*M_PI);
while (result <= -float(M_PI)) result += float(2*M_PI);
return result;
}
/*
inline double deltaPhi(float phi1, float phi2) {
return deltaPhi(static_cast<double>(phi1),
static_cast<double>(phi2));
}
*/
template<typename T1, typename T2>
inline double deltaPhi(T1& t1, T2 & t2) {
return deltaPhi(t1.phi(), t2.phi());
}
template <typename H>
inline H deltaPhi (H phi1, H phi2) {
H result = phi1 - phi2;
while (result > M_PI) result -= 2*M_PI;
while (result <= -M_PI) result += 2*M_PI;
return result;
}
}
using reco::deltaPhi;
template<typename T1, typename T2 = T1>
struct DeltaPhi {
double operator()(const T1 & t1, const T2 & t2) const {
return reco::deltaPhi(t1, t2);
}
};
#endif