Skip to content

Commit d585909

Browse files
committed
Use central phi functions instead LST ones
1 parent 3139210 commit d585909

File tree

9 files changed

+162
-190
lines changed

9 files changed

+162
-190
lines changed

RecoTracker/LSTCore/src/alpaka/Hit.h

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,17 @@
11
#ifndef RecoTracker_LSTCore_src_alpaka_Hit_h
22
#define RecoTracker_LSTCore_src_alpaka_Hit_h
33

4+
#include "DataFormats/Math/interface/deltaPhi.h"
5+
#include "HeterogeneousCore/AlpakaMath/interface/deltaPhi.h"
46
#include "RecoTracker/LSTCore/interface/alpaka/Common.h"
57
#include "RecoTracker/LSTCore/interface/ModulesSoA.h"
68
#include "RecoTracker/LSTCore/interface/alpaka/HitsDeviceCollection.h"
79

810
namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
911

10-
template <typename TAcc>
11-
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float eta(TAcc const& acc, float x, float y, float z) {
12-
float r3 = alpaka::math::sqrt(acc, x * x + y * y + z * z);
13-
float rt = alpaka::math::sqrt(acc, x * x + y * y);
14-
float eta = ((z > 0) - (z < 0)) * alpaka::math::acosh(acc, r3 / rt);
15-
return eta;
16-
}
17-
18-
template <typename TAcc>
19-
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float phi_mpi_pi(TAcc const& acc, float x) {
20-
if (alpaka::math::abs(acc, x) <= kPi)
21-
return x;
22-
23-
constexpr float o2pi = 1.f / (2.f * kPi);
24-
float n = alpaka::math::round(acc, x * o2pi);
25-
return x - n * float(2.f * kPi);
26-
}
27-
28-
template <typename TAcc>
29-
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float phi(TAcc const& acc, float x, float y) {
30-
return phi_mpi_pi(acc, kPi + alpaka::math::atan2(acc, -y, -x));
31-
}
32-
33-
template <typename TAcc>
34-
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float deltaPhi(TAcc const& acc, float x1, float y1, float x2, float y2) {
35-
float phi1 = phi(acc, x1, y1);
36-
float phi2 = phi(acc, x2, y2);
37-
return phi_mpi_pi(acc, (phi2 - phi1));
38-
}
39-
4012
template <typename TAcc>
4113
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float deltaPhiChange(TAcc const& acc, float x1, float y1, float x2, float y2) {
42-
return deltaPhi(acc, x1, y1, x2 - x1, y2 - y1);
43-
}
44-
45-
ALPAKA_FN_ACC ALPAKA_FN_INLINE float calculate_dPhi(float phi1, float phi2) {
46-
// Calculate dPhi
47-
float dPhi = phi1 - phi2;
48-
49-
// Normalize dPhi to be between -pi and pi
50-
if (dPhi > kPi) {
51-
dPhi -= 2 * kPi;
52-
} else if (dPhi < -kPi) {
53-
dPhi += 2 * kPi;
54-
}
55-
56-
return dPhi;
14+
return cms::alpakatools::deltaPhi(acc, x1, y1, x2 - x1, y2 - y1);
5715
}
5816

5917
struct ModuleRangesKernel {
@@ -103,7 +61,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
10361
int iDetId = hits.detid()[ihit];
10462

10563
hits.rts()[ihit] = alpaka::math::sqrt(acc, ihit_x * ihit_x + ihit_y * ihit_y);
106-
hits.phis()[ihit] = phi(acc, ihit_x, ihit_y);
64+
hits.phis()[ihit] = cms::alpakatools::phi(acc, ihit_x, ihit_y);
10765
hits.etas()[ihit] =
10866
((ihit_z > 0) - (ihit_z < 0)) *
10967
alpaka::math::acosh(

RecoTracker/LSTCore/src/alpaka/Kernels.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
164164
float eta2 = __H2F(quintuplets.eta()[jx]);
165165
float phi2 = __H2F(quintuplets.phi()[jx]);
166166
float dEta = alpaka::math::abs(acc, eta1 - eta2);
167-
float dPhi = calculate_dPhi(phi1, phi2);
167+
float dPhi = reco::deltaPhi(phi1, phi2);
168168
float score_rphisum2 = __H2F(quintuplets.score_rphisum()[jx]);
169169

170170
if (dEta > 0.1f)
@@ -244,7 +244,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
244244
float score_rphisum2 = __H2F(quintuplets.score_rphisum()[jx]);
245245

246246
float dEta = alpaka::math::abs(acc, eta1 - eta2);
247-
float dPhi = calculate_dPhi(phi1, phi2);
247+
float dPhi = reco::deltaPhi(phi1, phi2);
248248

249249
if (dEta > 0.1f)
250250
continue;
@@ -413,7 +413,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
413413
}
414414
if (secondpass) {
415415
float dEta = alpaka::math::abs(acc, eta_pix1 - eta_pix2);
416-
float dPhi = calculate_dPhi(phi_pix1, phi_pix2);
416+
float dPhi = reco::deltaPhi(phi_pix1, phi_pix2);
417417

418418
float dR2 = dEta * dEta + dPhi * dPhi;
419419
if ((npMatched >= 1) || (dR2 < 1e-5f)) {

RecoTracker/LSTCore/src/alpaka/MiniDoublet.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -428,22 +428,22 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
428428
shiftedZ = zUpper;
429429
shiftedRt2 = xn * xn + yn * yn;
430430

431-
dPhi = deltaPhi(acc, xLower, yLower, shiftedX, shiftedY); //function from Hit.cc
432-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
431+
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY); //function from Hit.cc
432+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
433433
} else {
434434
shiftedX = xn;
435435
shiftedY = yn;
436436
shiftedZ = zLower;
437437
shiftedRt2 = xn * xn + yn * yn;
438-
dPhi = deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
439-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
438+
dPhi = cms::alpakatools::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
439+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
440440
}
441441
} else {
442442
shiftedX = 0.f;
443443
shiftedY = 0.f;
444444
shiftedZ = 0.f;
445445
shiftedRt2 = 0.f;
446-
dPhi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
446+
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
447447
noShiftedDphi = dPhi;
448448
}
449449

@@ -556,21 +556,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
556556
shiftedX = xn;
557557
shiftedY = yn;
558558
shiftedZ = zUpper;
559-
dPhi = deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
560-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
559+
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
560+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
561561
} else {
562562
shiftedX = xn;
563563
shiftedY = yn;
564564
shiftedZ = zLower;
565-
dPhi = deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
566-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
565+
dPhi = cms::alpakatools::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
566+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
567567
}
568568
} else {
569569
shiftedX = xn;
570570
shiftedY = yn;
571571
shiftedZ = zUpper;
572-
dPhi = deltaPhi(acc, xLower, yLower, xn, yn);
573-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
572+
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xn, yn);
573+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
574574
}
575575

576576
// dz needs to change if it is a PS module where the strip hits are shifted in order to properly account for the case when a tilted module falls under "endcap logic"

RecoTracker/LSTCore/src/alpaka/NeuralNetwork.h

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RecoTracker_LSTCore_src_alpaka_NeuralNetwork_h
22
#define RecoTracker_LSTCore_src_alpaka_NeuralNetwork_h
33

4+
#include "DataFormats/Math/interface/deltaPhi.h"
45
#include "FWCore/Utilities/interface/CMSUnrollLoop.h"
56

67
#include "RecoTracker/LSTCore/interface/alpaka/Common.h"
@@ -38,18 +39,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
3839
}
3940
}
4041

41-
ALPAKA_FN_ACC ALPAKA_FN_INLINE float delta_phi(const float phi1, const float phi2) {
42-
float delta = phi1 - phi2;
43-
// Adjust delta to be within the range [-M_PI, M_PI]
44-
if (delta > kPi) {
45-
delta -= 2 * kPi;
46-
} else if (delta < -kPi) {
47-
delta += 2 * kPi;
48-
}
49-
50-
return delta;
51-
}
52-
5342
template <typename TAcc>
5443
ALPAKA_FN_ACC ALPAKA_FN_INLINE bool runInference(TAcc const& acc,
5544
MiniDoubletsConst mds,
@@ -96,25 +85,25 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
9685
z1 / kZ_max, // inner T3: First hit z normalized
9786
r1 / kR_max, // inner T3: First hit r normalized
9887

99-
eta2 - eta1, // inner T3: Difference in eta between hit 2 and 1
100-
delta_phi(phi2, phi1) / kPhi_norm, // inner T3: Difference in phi between hit 2 and 1
101-
(z2 - z1) / kZ_max, // inner T3: Difference in z between hit 2 and 1 normalized
102-
(r2 - r1) / kR_max, // inner T3: Difference in r between hit 2 and 1 normalized
103-
104-
eta3 - eta2, // inner T3: Difference in eta between hit 3 and 2
105-
delta_phi(phi3, phi2) / kPhi_norm, // inner T3: Difference in phi between hit 3 and 2
106-
(z3 - z2) / kZ_max, // inner T3: Difference in z between hit 3 and 2 normalized
107-
(r3 - r2) / kR_max, // inner T3: Difference in r between hit 3 and 2 normalized
108-
109-
eta4 - eta3, // outer T3: Difference in eta between hit 4 and 3
110-
delta_phi(phi4, phi3) / kPhi_norm, // inner T3: Difference in phi between hit 4 and 3
111-
(z4 - z3) / kZ_max, // outer T3: Difference in z between hit 4 and 3 normalized
112-
(r4 - r3) / kR_max, // outer T3: Difference in r between hit 4 and 3 normalized
113-
114-
eta5 - eta4, // outer T3: Difference in eta between hit 5 and 4
115-
delta_phi(phi5, phi4) / kPhi_norm, // inner T3: Difference in phi between hit 5 and 4
116-
(z5 - z4) / kZ_max, // outer T3: Difference in z between hit 5 and 4 normalized
117-
(r5 - r4) / kR_max, // outer T3: Difference in r between hit 5 and 4 normalized
88+
eta2 - eta1, // inner T3: Difference in eta between hit 2 and 1
89+
reco::deltaPhi(phi2, phi1) / kPhi_norm, // inner T3: Difference in phi between hit 2 and 1
90+
(z2 - z1) / kZ_max, // inner T3: Difference in z between hit 2 and 1 normalized
91+
(r2 - r1) / kR_max, // inner T3: Difference in r between hit 2 and 1 normalized
92+
93+
eta3 - eta2, // inner T3: Difference in eta between hit 3 and 2
94+
reco::deltaPhi(phi3, phi2) / kPhi_norm, // inner T3: Difference in phi between hit 3 and 2
95+
(z3 - z2) / kZ_max, // inner T3: Difference in z between hit 3 and 2 normalized
96+
(r3 - r2) / kR_max, // inner T3: Difference in r between hit 3 and 2 normalized
97+
98+
eta4 - eta3, // outer T3: Difference in eta between hit 4 and 3
99+
reco::deltaPhi(phi4, phi3) / kPhi_norm, // inner T3: Difference in phi between hit 4 and 3
100+
(z4 - z3) / kZ_max, // outer T3: Difference in z between hit 4 and 3 normalized
101+
(r4 - r3) / kR_max, // outer T3: Difference in r between hit 4 and 3 normalized
102+
103+
eta5 - eta4, // outer T3: Difference in eta between hit 5 and 4
104+
reco::deltaPhi(phi5, phi4) / kPhi_norm, // inner T3: Difference in phi between hit 5 and 4
105+
(z5 - z4) / kZ_max, // outer T3: Difference in z between hit 5 and 4 normalized
106+
(r5 - r4) / kR_max, // outer T3: Difference in r between hit 5 and 4 normalized
118107

119108
alpaka::math::log10(acc, innerRadius), // T5 inner radius (t5_innerRadius)
120109
alpaka::math::log10(acc, bridgeRadius), // T5 bridge radius (t5_bridgeRadius)

0 commit comments

Comments
 (0)