Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use central phi functions instead LST ones #47208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 4 additions & 46 deletions RecoTracker/LSTCore/src/alpaka/Hit.h
Original file line number Diff line number Diff line change
@@ -1,62 +1,20 @@
#ifndef RecoTracker_LSTCore_src_alpaka_Hit_h
#define RecoTracker_LSTCore_src_alpaka_Hit_h

#include "DataFormats/Math/interface/deltaPhi.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
#include "HeterogeneousCore/AlpakaInterface/interface/alpakastdAlgorithm.h"
#include "HeterogeneousCore/AlpakaMath/interface/deltaPhi.h"

#include "RecoTracker/LSTCore/interface/alpaka/Common.h"
#include "RecoTracker/LSTCore/interface/ModulesSoA.h"
#include "RecoTracker/LSTCore/interface/alpaka/HitsDeviceCollection.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

template <typename TAcc>
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float eta(TAcc const& acc, float x, float y, float z) {
float r3 = alpaka::math::sqrt(acc, x * x + y * y + z * z);
float rt = alpaka::math::sqrt(acc, x * x + y * y);
float eta = ((z > 0) - (z < 0)) * alpaka::math::acosh(acc, r3 / rt);
return eta;
}

template <typename TAcc>
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float phi_mpi_pi(TAcc const& acc, float x) {
if (alpaka::math::abs(acc, x) <= kPi)
return x;

constexpr float o2pi = 1.f / (2.f * kPi);
float n = alpaka::math::round(acc, x * o2pi);
return x - n * float(2.f * kPi);
}

template <typename TAcc>
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float phi(TAcc const& acc, float x, float y) {
return phi_mpi_pi(acc, kPi + alpaka::math::atan2(acc, -y, -x));
}

template <typename TAcc>
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float deltaPhi(TAcc const& acc, float x1, float y1, float x2, float y2) {
float phi1 = phi(acc, x1, y1);
float phi2 = phi(acc, x2, y2);
return phi_mpi_pi(acc, (phi2 - phi1));
}

template <typename TAcc>
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float deltaPhiChange(TAcc const& acc, float x1, float y1, float x2, float y2) {
return deltaPhi(acc, x1, y1, x2 - x1, y2 - y1);
}

ALPAKA_FN_ACC ALPAKA_FN_INLINE float calculate_dPhi(float phi1, float phi2) {
// Calculate dPhi
float dPhi = phi1 - phi2;

// Normalize dPhi to be between -pi and pi
if (dPhi > kPi) {
dPhi -= 2 * kPi;
} else if (dPhi < -kPi) {
dPhi += 2 * kPi;
}

return dPhi;
return cms::alpakatools::deltaPhi(acc, x1, y1, x2 - x1, y2 - y1);
}

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

hits.rts()[ihit] = alpaka::math::sqrt(acc, ihit_x * ihit_x + ihit_y * ihit_y);
hits.phis()[ihit] = phi(acc, ihit_x, ihit_y);
hits.phis()[ihit] = cms::alpakatools::phi(acc, ihit_x, ihit_y);
hits.etas()[ihit] =
((ihit_z > 0) - (ihit_z < 0)) *
alpaka::math::acosh(
Expand Down
6 changes: 3 additions & 3 deletions RecoTracker/LSTCore/src/alpaka/Kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
float eta2 = __H2F(quintuplets.eta()[jx]);
float phi2 = __H2F(quintuplets.phi()[jx]);
float dEta = alpaka::math::abs(acc, eta1 - eta2);
float dPhi = calculate_dPhi(phi1, phi2);
float dPhi = reco::deltaPhi(phi1, phi2);
float score_rphisum2 = __H2F(quintuplets.score_rphisum()[jx]);

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

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

if (dEta > 0.1f)
continue;
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
}
if (secondpass) {
float dEta = alpaka::math::abs(acc, eta_pix1 - eta_pix2);
float dPhi = calculate_dPhi(phi_pix1, phi_pix2);
float dPhi = reco::deltaPhi(phi_pix1, phi_pix2);

float dR2 = dEta * dEta + dPhi * dPhi;
if ((npMatched >= 1) || (dR2 < 1e-5f)) {
Expand Down
22 changes: 11 additions & 11 deletions RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,22 +429,22 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
shiftedZ = zUpper;
shiftedRt2 = xn * xn + yn * yn;

dPhi = deltaPhi(acc, xLower, yLower, shiftedX, shiftedY); //function from Hit.cc
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY); //function from Hit.cc
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
} else {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zLower;
shiftedRt2 = xn * xn + yn * yn;
dPhi = deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
dPhi = cms::alpakatools::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
}
} else {
shiftedX = 0.f;
shiftedY = 0.f;
shiftedZ = 0.f;
shiftedRt2 = 0.f;
dPhi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
noShiftedDphi = dPhi;
}

Expand Down Expand Up @@ -557,21 +557,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zUpper;
dPhi = deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
} else {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zLower;
dPhi = deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
dPhi = cms::alpakatools::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
}
} else {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zUpper;
dPhi = deltaPhi(acc, xLower, yLower, xn, yn);
noShiftedDphi = deltaPhi(acc, xLower, yLower, xUpper, yUpper);
dPhi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xn, yn);
noShiftedDphi = cms::alpakatools::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
}

// 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"
Expand Down
51 changes: 20 additions & 31 deletions RecoTracker/LSTCore/src/alpaka/NeuralNetwork.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RecoTracker_LSTCore_src_alpaka_NeuralNetwork_h
#define RecoTracker_LSTCore_src_alpaka_NeuralNetwork_h

#include "DataFormats/Math/interface/deltaPhi.h"
#include "FWCore/Utilities/interface/CMSUnrollLoop.h"

#include "RecoTracker/LSTCore/interface/alpaka/Common.h"
Expand Down Expand Up @@ -38,18 +39,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
}
}

ALPAKA_FN_ACC ALPAKA_FN_INLINE float delta_phi(const float phi1, const float phi2) {
float delta = phi1 - phi2;
// Adjust delta to be within the range [-M_PI, M_PI]
if (delta > kPi) {
delta -= 2 * kPi;
} else if (delta < -kPi) {
delta += 2 * kPi;
}

return delta;
}

template <typename TAcc>
ALPAKA_FN_ACC ALPAKA_FN_INLINE bool runInference(TAcc const& acc,
MiniDoubletsConst mds,
Expand Down Expand Up @@ -96,25 +85,25 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
z1 / kZ_max, // inner T3: First hit z normalized
r1 / kR_max, // inner T3: First hit r normalized

eta2 - eta1, // inner T3: Difference in eta between hit 2 and 1
delta_phi(phi2, phi1) / kPhi_norm, // inner T3: Difference in phi between hit 2 and 1
(z2 - z1) / kZ_max, // inner T3: Difference in z between hit 2 and 1 normalized
(r2 - r1) / kR_max, // inner T3: Difference in r between hit 2 and 1 normalized

eta3 - eta2, // inner T3: Difference in eta between hit 3 and 2
delta_phi(phi3, phi2) / kPhi_norm, // inner T3: Difference in phi between hit 3 and 2
(z3 - z2) / kZ_max, // inner T3: Difference in z between hit 3 and 2 normalized
(r3 - r2) / kR_max, // inner T3: Difference in r between hit 3 and 2 normalized

eta4 - eta3, // outer T3: Difference in eta between hit 4 and 3
delta_phi(phi4, phi3) / kPhi_norm, // inner T3: Difference in phi between hit 4 and 3
(z4 - z3) / kZ_max, // outer T3: Difference in z between hit 4 and 3 normalized
(r4 - r3) / kR_max, // outer T3: Difference in r between hit 4 and 3 normalized

eta5 - eta4, // outer T3: Difference in eta between hit 5 and 4
delta_phi(phi5, phi4) / kPhi_norm, // inner T3: Difference in phi between hit 5 and 4
(z5 - z4) / kZ_max, // outer T3: Difference in z between hit 5 and 4 normalized
(r5 - r4) / kR_max, // outer T3: Difference in r between hit 5 and 4 normalized
eta2 - eta1, // inner T3: Difference in eta between hit 2 and 1
reco::deltaPhi(phi2, phi1) / kPhi_norm, // inner T3: Difference in phi between hit 2 and 1
(z2 - z1) / kZ_max, // inner T3: Difference in z between hit 2 and 1 normalized
(r2 - r1) / kR_max, // inner T3: Difference in r between hit 2 and 1 normalized

eta3 - eta2, // inner T3: Difference in eta between hit 3 and 2
reco::deltaPhi(phi3, phi2) / kPhi_norm, // inner T3: Difference in phi between hit 3 and 2
(z3 - z2) / kZ_max, // inner T3: Difference in z between hit 3 and 2 normalized
(r3 - r2) / kR_max, // inner T3: Difference in r between hit 3 and 2 normalized

eta4 - eta3, // outer T3: Difference in eta between hit 4 and 3
reco::deltaPhi(phi4, phi3) / kPhi_norm, // inner T3: Difference in phi between hit 4 and 3
(z4 - z3) / kZ_max, // outer T3: Difference in z between hit 4 and 3 normalized
(r4 - r3) / kR_max, // outer T3: Difference in r between hit 4 and 3 normalized

eta5 - eta4, // outer T3: Difference in eta between hit 5 and 4
reco::deltaPhi(phi5, phi4) / kPhi_norm, // inner T3: Difference in phi between hit 5 and 4
(z5 - z4) / kZ_max, // outer T3: Difference in z between hit 5 and 4 normalized
(r5 - r4) / kR_max, // outer T3: Difference in r between hit 5 and 4 normalized

alpaka::math::log10(acc, innerRadius), // T5 inner radius (t5_innerRadius)
alpaka::math::log10(acc, bridgeRadius), // T5 bridge radius (t5_bridgeRadius)
Expand Down
Loading