From e93e31f066c63228ec2bc68400917637768dc5d0 Mon Sep 17 00:00:00 2001 From: shahoian Date: Tue, 28 Jul 2026 11:47:51 +0200 Subject: [PATCH] Use fastAtan2 with protection against radial tracks --- Detectors/Base/include/DetectorsBase/MatLayerCyl.h | 2 +- Detectors/Base/include/DetectorsBase/Ray.h | 2 +- Detectors/Base/src/MatLayerCylSet.cxx | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Detectors/Base/include/DetectorsBase/MatLayerCyl.h b/Detectors/Base/include/DetectorsBase/MatLayerCyl.h index e63de51e0a6ca..439bd12e7f673 100644 --- a/Detectors/Base/include/DetectorsBase/MatLayerCyl.h +++ b/Detectors/Base/include/DetectorsBase/MatLayerCyl.h @@ -107,7 +107,7 @@ class MatLayerCyl : public o2::gpu::FlatObject GPUd() int getZBinID(float z) const { int idz = int((z - getZMin()) * getDZInv()); // cannot be negative since before isZOutside is applied - return idz < getNZBins() ? idz : getNZBins() - 1; + return idz < getNZBins() ? (idz > 0 ? idz : 0) : getNZBins() - 1; } // lower boundary of Z slice diff --git a/Detectors/Base/include/DetectorsBase/Ray.h b/Detectors/Base/include/DetectorsBase/Ray.h index a72208c41af0d..0b0c2f2904d27 100644 --- a/Detectors/Base/include/DetectorsBase/Ray.h +++ b/Detectors/Base/include/DetectorsBase/Ray.h @@ -79,7 +79,7 @@ class Ray GPUd() float getPhi(float t) const { - float p = o2::gpu::CAMath::ATan2(mP[1] + t * mD[1], mP[0] + t * mD[0]); + float p = o2::math_utils::fastATan2(mP[1] + t * mD[1], mP[0] + t * mD[0]); // instead of float p = o2::gpu::CAMath::ATan2(mP[1] + t * mD[1], mP[0] + t * mD[0]); o2::math_utils::bringTo02Pi(p); return p; } diff --git a/Detectors/Base/src/MatLayerCylSet.cxx b/Detectors/Base/src/MatLayerCylSet.cxx index c390c8d617326..9d1f0f298b587 100644 --- a/Detectors/Base/src/MatLayerCylSet.cxx +++ b/Detectors/Base/src/MatLayerCylSet.cxx @@ -348,6 +348,12 @@ GPUd() MatBudget MatLayerCylSet::getMatBudget(float x0, float y0, float z0, floa if (tEndPhi == Ray::InvalidT) { break; // ray parallel to radial line, abandon check for phi bin change } + const auto tMarginPhi = 1.e-6f + 1.e-5f * (cross1 - cross2); + // if (!(tEndPhi >= cross2 - tMarginPhi) | !(tEndPhi <= cross1 + tMarginPhi)) { // use non-short-circuit | to reject eventual NANs + if (tEndPhi < cross2 - tMarginPhi || tEndPhi > cross1 + tMarginPhi) { + tEndPhi = cross2; + checkMorePhi = false; + } } auto zID = lr.getZBinID(ray.getZ(tStartPhi)); auto zIDLast = lr.getZBinID(ray.getZ(tEndPhi));