DataFormats
Math
interface
deltaR.h
Go to the documentation of this file.
1
#ifndef DataFormats_Math_deltaR_h
2
#define DataFormats_Math_deltaR_h
3
/* functions to compute deltaR
4
*
5
* Ported from original code in RecoJets
6
* by Fedor Ratnikov, FNAL
7
*/
8
#include "
DataFormats/Math/interface/deltaPhi.h
"
9
#include <cmath>
10
11
namespace
reco
{
12
13
// assumption is that eta and phi are cached AND phi is computed using std::atan2
14
// type is the type of T1::eta();
15
template
<
typename
T1,
typename
T2>
16
constexpr
auto
deltaR2
(
const
T1&
t1
,
const
T2&
t2
) -> decltype(
t1
.eta()) {
17
typedef
decltype(
t1
.eta()) Float;
18
Float
p1
=
t1
.phi();
19
Float
p2
=
t2
.phi();
20
Float
e1
=
t1
.eta();
21
Float e2 =
t2
.eta();
22
auto
dp
=
std::abs
(
p1
-
p2
);
23
if
(
dp
> Float(
M_PI
))
24
dp
-= Float(2 *
M_PI
);
25
return
(
e1
- e2) * (
e1
- e2) +
dp
*
dp
;
26
}
27
28
// do not use it: always cut in deltaR2!
29
template
<
typename
T1,
typename
T2>
30
constexpr
auto
deltaR
(
const
T1&
t1
,
const
T2&
t2
) -> decltype(
t1
.eta()) {
31
return
std::sqrt
(
deltaR2
(
t1
,
t2
));
32
}
33
34
//prefer the above...
35
template
<
class
T1,
class
T2,
class
T3,
class
T4>
36
constexpr T1
deltaR2
(T1
eta1
, T2 phi1, T3
eta2
, T4 phi2) {
37
T1 deta =
eta1
-
eta2
;
38
T1 dphi =
std::abs
(phi1 - phi2);
39
if
(dphi > T1(
M_PI
))
40
dphi -= T1(2 *
M_PI
);
41
return
deta * deta + dphi * dphi;
42
}
43
44
// to be avoided
45
template
<
class
T1,
class
T2,
class
T3,
class
T4>
46
constexpr T1
deltaR
(T1
eta1
, T2 phi1, T3
eta2
, T4 phi2) {
47
return
std::sqrt
(
deltaR2
(
eta1
, phi1,
eta2
, phi2));
48
}
49
50
}
// namespace reco
51
52
// woderful! VI
53
using
reco::deltaR
;
54
using
reco::deltaR2
;
55
56
// obsolete use lambdas (and cut in deltaR2!)
57
template
<
typename
T1,
typename
T2 = T1>
58
struct
DeltaR
{
59
constexpr
double
operator()
(
const
T1&
t1
,
const
T2&
t2
)
const
{
return
reco::deltaR
(
t1
,
t2
); }
60
};
61
#endif
RandomServiceHelper.t2
t2
Definition:
RandomServiceHelper.py:257
deltaPhi.h
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:46
RandomServiceHelper.t1
t1
Definition:
RandomServiceHelper.py:256
Calorimetry_cff.dp
dp
Definition:
Calorimetry_cff.py:158
mathSSE::sqrt
T sqrt(T t)
Definition:
SSEVec.h:19
HLT_FULL_cff.eta2
eta2
Definition:
HLT_FULL_cff.py:9551
p2
double p2[4]
Definition:
TauolaWrapper.h:90
HLT_FULL_cff.eta1
eta1
Definition:
HLT_FULL_cff.py:9550
DeltaR
Definition:
DeltaR.py:1
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition:
deltaR.h:16
StorageManager_cfg.e1
e1
Definition:
StorageManager_cfg.py:16
M_PI
#define M_PI
Definition:
BXVectorInputProducer.cc:49
p1
double p1[4]
Definition:
TauolaWrapper.h:89
DeltaR::operator()
constexpr double operator()(const T1 &t1, const T2 &t2) const
Definition:
deltaR.h:59
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition:
deltaR.h:30
funct::abs
Abs< T >::type abs(const T &t)
Definition:
Abs.h:22
Generated for CMSSW Reference Manual by
1.8.16