Skip to content

Commit dbf0fbf

Browse files
committed
Port alpaka phi functions to DataFormats
1 parent 1ff4d57 commit dbf0fbf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef DataFormats_Math_alpaka_deltaPhi_h
2+
#define DataFormats_Math_alpaka_deltaPhi_h
3+
4+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
5+
6+
namespace cms::alpakatools {
7+
8+
// reduce to [-pi,pi]
9+
template <typename TAcc, typename T>
10+
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T reduceRange(TAcc const& acc, T x) {
11+
constexpr T o2pi = 1. / (2. * M_PI);
12+
if (alpaka::math::abs(acc, x) <= T(M_PI))
13+
return x;
14+
T n = alpaka::math::round(acc, x * o2pi);
15+
return x - n * T(2. * M_PI);
16+
}
17+
18+
template <typename TAcc, typename T>
19+
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T phi(TAcc const& acc, T x, T y) {
20+
return reduceRange(acc, M_PI + alpaka::math::atan2(acc, -y, -x));
21+
}
22+
23+
template <typename TAcc, typename T>
24+
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T deltaPhi(TAcc const& acc, T x1, T y1, T x2, T y2) {
25+
return reduceRange(acc, alpaka::math::atan2(acc, -y2, -x2) - alpaka::math::atan2(acc, -y1, -x1));
26+
}
27+
28+
template <typename TAcc, typename T>
29+
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T deltaPhi(T phi1, T phi2) {
30+
return reduceRange(phi1 - phi2);
31+
}
32+
33+
} // namespace cms::alpakatools
34+
35+
#endif

0 commit comments

Comments
 (0)