Skip to content

Commit 59c5d67

Browse files
authored
Merge pull request #47208 from SegmentLinking/CMSSW_14_2_0_pre4_workflowsAndGeneralFunctions_squashed
Use central phi functions instead LST ones
2 parents a621796 + 717caf8 commit 59c5d67

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,62 +1,20 @@
11
#ifndef RecoTracker_LSTCore_src_alpaka_Hit_h
22
#define RecoTracker_LSTCore_src_alpaka_Hit_h
33

4+
#include "DataFormats/Math/interface/deltaPhi.h"
45
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
56
#include "HeterogeneousCore/AlpakaInterface/interface/alpakastdAlgorithm.h"
7+
#include "HeterogeneousCore/AlpakaMath/interface/deltaPhi.h"
68

79
#include "RecoTracker/LSTCore/interface/alpaka/Common.h"
810
#include "RecoTracker/LSTCore/interface/ModulesSoA.h"
911
#include "RecoTracker/LSTCore/interface/alpaka/HitsDeviceCollection.h"
1012

1113
namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
1214

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

6220
struct ModuleRangesKernel {
@@ -99,7 +57,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
9957
int iDetId = hits.detid()[ihit];
10058

10159
hits.rts()[ihit] = alpaka::math::sqrt(acc, ihit_x * ihit_x + ihit_y * ihit_y);
102-
hits.phis()[ihit] = phi(acc, ihit_x, ihit_y);
60+
hits.phis()[ihit] = cms::alpakatools::phi(acc, ihit_x, ihit_y);
10361
hits.etas()[ihit] =
10462
((ihit_z > 0) - (ihit_z < 0)) *
10563
alpaka::math::acosh(

RecoTracker/LSTCore/src/alpaka/Kernels.h

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

168168
if (dEta > 0.1f)
@@ -237,7 +237,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
237237
float score_rphisum2 = __H2F(quintuplets.score_rphisum()[jx]);
238238

239239
float dEta = alpaka::math::abs(acc, eta1 - eta2);
240-
float dPhi = calculate_dPhi(phi1, phi2);
240+
float dPhi = reco::deltaPhi(phi1, phi2);
241241

242242
if (dEta > 0.1f)
243243
continue;
@@ -394,7 +394,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
394394
}
395395
if (secondpass) {
396396
float dEta = alpaka::math::abs(acc, eta_pix1 - eta_pix2);
397-
float dPhi = calculate_dPhi(phi_pix1, phi_pix2);
397+
float dPhi = reco::deltaPhi(phi_pix1, phi_pix2);
398398

399399
float dR2 = dEta * dEta + dPhi * dPhi;
400400
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
@@ -429,22 +429,22 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
429429
shiftedZ = zUpper;
430430
shiftedRt2 = xn * xn + yn * yn;
431431

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

@@ -557,21 +557,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
557557
shiftedX = xn;
558558
shiftedY = yn;
559559
shiftedZ = zUpper;
560-
dPhi = deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
561-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
560+
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
561+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
562562
} else {
563563
shiftedX = xn;
564564
shiftedY = yn;
565565
shiftedZ = zLower;
566-
dPhi = deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
567-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
566+
dPhi = cms::alpakatools::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
567+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
568568
}
569569
} else {
570570
shiftedX = xn;
571571
shiftedY = yn;
572572
shiftedZ = zUpper;
573-
dPhi = deltaPhi(acc, xLower, yLower, xn, yn);
574-
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
573+
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xn, yn);
574+
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
575575
}
576576

577577
// 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)