Skip to content

Commit

Permalink
Use central phi functions instead LST ones
Browse files Browse the repository at this point in the history
  • Loading branch information
VourMa committed Jan 20, 2025
1 parent e299d58 commit eec20cb
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 159 deletions.
50 changes: 4 additions & 46 deletions RecoTracker/LSTCore/src/alpaka/Hit.h
Original file line number Diff line number Diff line change
@@ -1,59 +1,17 @@
#ifndef RecoTracker_LSTCore_src_alpaka_Hit_h
#define RecoTracker_LSTCore_src_alpaka_Hit_h

#include "DataFormats/Math/interface/deltaPhi.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 @@ -103,7 +61,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 @@ -164,7 +164,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 @@ -244,7 +244,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 @@ -413,7 +413,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 @@ -428,22 +428,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 @@ -556,21 +556,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
98 changes: 49 additions & 49 deletions RecoTracker/LSTCore/src/alpaka/PixelTriplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

float rt_InOut = rt_InUp;

if (alpaka::math::abs(acc, deltaPhi(acc, x_InUp, y_InUp, x_OutLo, y_OutLo)) > kPi / 2.f)
if (alpaka::math::abs(acc, cms::alpakatools::deltaPhi(acc, x_InUp, y_InUp, x_OutLo, y_OutLo)) > kPi / 2.f)
return false;

unsigned int pixelSegmentArrayIndex = innerSegmentIndex - ranges.segmentModuleIndices()[pixelModuleIndex];
Expand Down Expand Up @@ -1043,7 +1043,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
float diffX = x_OutLo - x_InLo;
float diffY = y_OutLo - y_InLo;

dPhi = deltaPhi(acc, midPointX, midPointY, diffX, diffY);
dPhi = cms::alpakatools::deltaPhi(acc, midPointX, midPointY, diffX, diffY);

if (alpaka::math::abs(acc, dPhi) > dPhiCut)
return false;
Expand All @@ -1057,7 +1057,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
modules.moduleType()[outerOuterLowerModuleIndex] == TwoS;

float alpha_OutUp, alpha_OutUp_highEdge, alpha_OutUp_lowEdge;
alpha_OutUp = deltaPhi(acc, x_OutUp, y_OutUp, x_OutUp - x_OutLo, y_OutUp - y_OutLo);
alpha_OutUp = cms::alpakatools::deltaPhi(acc, x_OutUp, y_OutUp, x_OutUp - x_OutLo, y_OutUp - y_OutLo);

alpha_OutUp_highEdge = alpha_OutUp;
alpha_OutUp_lowEdge = alpha_OutUp;
Expand All @@ -1071,42 +1071,42 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
float tl_axis_lowEdge_x = tl_axis_x;
float tl_axis_lowEdge_y = tl_axis_y;

betaIn = -deltaPhi(acc, px, py, tl_axis_x, tl_axis_y);
betaIn = -cms::alpakatools::deltaPhi(acc, px, py, tl_axis_x, tl_axis_y);
float betaInRHmin = betaIn;
float betaInRHmax = betaIn;

betaOut = -alpha_OutUp + deltaPhi(acc, x_OutUp, y_OutUp, tl_axis_x, tl_axis_y);
betaOut = -alpha_OutUp + cms::alpakatools::deltaPhi(acc, x_OutUp, y_OutUp, tl_axis_x, tl_axis_y);

float betaOutRHmin = betaOut;
float betaOutRHmax = betaOut;

if (isEC_lastLayer) {
alpha_OutUp_highEdge = deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
mds.anchorHighEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorHighEdgeY()[fourthMDIndex] - y_OutLo);
alpha_OutUp_lowEdge = deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
mds.anchorLowEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorLowEdgeY()[fourthMDIndex] - y_OutLo);
alpha_OutUp_highEdge = cms::alpakatools::deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
mds.anchorHighEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorHighEdgeY()[fourthMDIndex] - y_OutLo);
alpha_OutUp_lowEdge = cms::alpakatools::deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
mds.anchorLowEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorLowEdgeY()[fourthMDIndex] - y_OutLo);

tl_axis_highEdge_x = mds.anchorHighEdgeX()[fourthMDIndex] - x_InUp;
tl_axis_highEdge_y = mds.anchorHighEdgeY()[fourthMDIndex] - y_InUp;
tl_axis_lowEdge_x = mds.anchorLowEdgeX()[fourthMDIndex] - x_InUp;
tl_axis_lowEdge_y = mds.anchorLowEdgeY()[fourthMDIndex] - y_InUp;

betaOutRHmin = -alpha_OutUp_highEdge + deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
tl_axis_highEdge_x,
tl_axis_highEdge_y);
betaOutRHmax = -alpha_OutUp_lowEdge + deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
tl_axis_lowEdge_x,
tl_axis_lowEdge_y);
betaOutRHmin = -alpha_OutUp_highEdge + cms::alpakatools::deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
tl_axis_highEdge_x,
tl_axis_highEdge_y);
betaOutRHmax = -alpha_OutUp_lowEdge + cms::alpakatools::deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
tl_axis_lowEdge_x,
tl_axis_lowEdge_y);
}

//beta computation
Expand Down Expand Up @@ -1307,7 +1307,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
float diffX = x_OutLo - x_InLo;
float diffY = y_OutLo - y_InLo;

dPhi = deltaPhi(acc, midPointX, midPointY, diffX, diffY);
dPhi = cms::alpakatools::deltaPhi(acc, midPointX, midPointY, diffX, diffY);

// Cut #5: deltaPhiChange
if (alpaka::math::abs(acc, dPhi) > dPhiCut)
Expand All @@ -1321,7 +1321,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

float alpha_OutUp, alpha_OutUp_highEdge, alpha_OutUp_lowEdge;

alpha_OutUp = deltaPhi(acc, x_OutUp, y_OutUp, x_OutUp - x_OutLo, y_OutUp - y_OutLo);
alpha_OutUp = cms::alpakatools::deltaPhi(acc, x_OutUp, y_OutUp, x_OutUp - x_OutLo, y_OutUp - y_OutLo);
alpha_OutUp_highEdge = alpha_OutUp;
alpha_OutUp_lowEdge = alpha_OutUp;

Expand All @@ -1334,41 +1334,41 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
float tl_axis_lowEdge_x = tl_axis_x;
float tl_axis_lowEdge_y = tl_axis_y;

betaIn = -deltaPhi(acc, px, py, tl_axis_x, tl_axis_y);
betaIn = -cms::alpakatools::deltaPhi(acc, px, py, tl_axis_x, tl_axis_y);
float betaInRHmin = betaIn;
float betaInRHmax = betaIn;

betaOut = -alpha_OutUp + deltaPhi(acc, x_OutUp, y_OutUp, tl_axis_x, tl_axis_y);
betaOut = -alpha_OutUp + cms::alpakatools::deltaPhi(acc, x_OutUp, y_OutUp, tl_axis_x, tl_axis_y);
float betaOutRHmin = betaOut;
float betaOutRHmax = betaOut;

if (isEC_lastLayer) {
alpha_OutUp_highEdge = deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
mds.anchorHighEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorHighEdgeY()[fourthMDIndex] - y_OutLo);
alpha_OutUp_lowEdge = deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
mds.anchorLowEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorLowEdgeY()[fourthMDIndex] - y_OutLo);
alpha_OutUp_highEdge = cms::alpakatools::deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
mds.anchorHighEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorHighEdgeY()[fourthMDIndex] - y_OutLo);
alpha_OutUp_lowEdge = cms::alpakatools::deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
mds.anchorLowEdgeX()[fourthMDIndex] - x_OutLo,
mds.anchorLowEdgeY()[fourthMDIndex] - y_OutLo);

tl_axis_highEdge_x = mds.anchorHighEdgeX()[fourthMDIndex] - x_InUp;
tl_axis_highEdge_y = mds.anchorHighEdgeY()[fourthMDIndex] - y_InUp;
tl_axis_lowEdge_x = mds.anchorLowEdgeX()[fourthMDIndex] - x_InUp;
tl_axis_lowEdge_y = mds.anchorLowEdgeY()[fourthMDIndex] - y_InUp;

betaOutRHmin = -alpha_OutUp_highEdge + deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
tl_axis_highEdge_x,
tl_axis_highEdge_y);
betaOutRHmax = -alpha_OutUp_lowEdge + deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
tl_axis_lowEdge_x,
tl_axis_lowEdge_y);
betaOutRHmin = -alpha_OutUp_highEdge + cms::alpakatools::deltaPhi(acc,
mds.anchorHighEdgeX()[fourthMDIndex],
mds.anchorHighEdgeY()[fourthMDIndex],
tl_axis_highEdge_x,
tl_axis_highEdge_y);
betaOutRHmax = -alpha_OutUp_lowEdge + cms::alpakatools::deltaPhi(acc,
mds.anchorLowEdgeX()[fourthMDIndex],
mds.anchorLowEdgeY()[fourthMDIndex],
tl_axis_lowEdge_x,
tl_axis_lowEdge_y);
}

//beta computation
Expand Down
Loading

0 comments on commit eec20cb

Please sign in to comment.