Skip to content

Commit e25f6d0

Browse files
committed
Protect TrackPar against dealing with infinite pT, p
1 parent 757c8ba commit e25f6d0

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrization.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ GPUconstexpr() int CovarMap[kNParams][kNParams] = {{0, 1, 3, 6, 10},
115115
GPUconstexpr() int DiagMap[kNParams] = {0, 2, 5, 9, 14};
116116

117117
constexpr float HugeF = o2::constants::math::VeryBig;
118+
constexpr float MaxPT = 100000.; // do not allow pTs exceeding this value (to avoid NANs)
119+
constexpr float MinPTInv = 1. / MaxPT; // do not allow q/pTs less this value (to avoid NANs)
118120

119121
template <typename value_T = float>
120122
class TrackParametrization
@@ -541,7 +543,10 @@ template <typename value_T>
541543
GPUdi() auto TrackParametrization<value_T>::getPtInv() const -> value_t
542544
{
543545
// return the inverted track pT
544-
const value_t ptInv = gpu::CAMath::Abs(mP[kQ2Pt]);
546+
value_t ptInv = gpu::CAMath::Abs(mP[kQ2Pt]);
547+
if (ptInv < MinPTInv) {
548+
ptInv = MinPTInv;
549+
}
545550
return (mAbsCharge > 1) ? ptInv / mAbsCharge : ptInv;
546551
}
547552

@@ -550,47 +555,40 @@ template <typename value_T>
550555
GPUdi() auto TrackParametrization<value_T>::getP2Inv() const -> value_t
551556
{
552557
// return the inverted track momentum^2
553-
const value_t p2 = mP[kQ2Pt] * mP[kQ2Pt] / (1.f + getTgl() * getTgl());
554-
return (mAbsCharge > 1) ? p2 / (mAbsCharge * mAbsCharge) : p2;
558+
value_t p2 = getPtInv();
559+
return p2 * p2 / (1.f + getTgl() * getTgl());
555560
}
556561

557562
//____________________________________________________________
558563
template <typename value_T>
559564
GPUdi() auto TrackParametrization<value_T>::getP2() const -> value_t
560565
{
561566
// return the track momentum^2
562-
const value_t p2inv = getP2Inv();
563-
return (p2inv > o2::constants::math::Almost0) ? 1.f / p2inv : o2::constants::math::VeryBig;
567+
return 1.f / getP2Inv(); // getP2Inv is protected against being 0, full charge accounted
564568
}
565569

566570
//____________________________________________________________
567571
template <typename value_T>
568572
GPUdi() auto TrackParametrization<value_T>::getPInv() const -> value_t
569573
{
570-
// return the inverted track momentum^2
571-
const value_t pInv = gpu::CAMath::Abs(mP[kQ2Pt]) / gpu::CAMath::Sqrt(1.f + getTgl() * getTgl());
572-
return (mAbsCharge > 1) ? pInv / mAbsCharge : pInv;
574+
// return the inverted track momentum
575+
return getPtInv() / gpu::CAMath::Sqrt(1.f + getTgl() * getTgl()); // getPtInv() is protected against being 0, full charge accounted
573576
}
574577

575578
//____________________________________________________________
576579
template <typename value_T>
577580
GPUdi() auto TrackParametrization<value_T>::getP() const -> value_t
578581
{
579582
// return the track momentum
580-
const value_t pInv = getPInv();
581-
return (pInv > o2::constants::math::Almost0) ? 1.f / pInv : o2::constants::math::VeryBig;
583+
return 1.f / getPInv(); // getPInv is already protected against being 0
582584
}
583585

584586
//____________________________________________________________
585587
template <typename value_T>
586588
GPUdi() auto TrackParametrization<value_T>::getPt() const -> value_t
587589
{
588590
// return the track transverse momentum
589-
value_t ptI = gpu::CAMath::Abs(mP[kQ2Pt]);
590-
if (mAbsCharge > 1) {
591-
ptI /= mAbsCharge;
592-
}
593-
return (ptI > o2::constants::math::Almost0) ? 1.f / ptI : o2::constants::math::VeryBig;
591+
return 1.f / getPtInv(); // getPtInv is already protected against being 0
594592
}
595593

596594
//____________________________________________________________

DataFormats/Reconstruction/src/TrackParametrization.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ template <typename value_T>
144144
GPUd() bool TrackParametrization<value_T>::getPosDirGlo(gpu::gpustd::array<value_t, 9>& posdirp) const
145145
{
146146
// fill vector with lab x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha
147-
value_t ptI = gpu::CAMath::Abs(getQ2Pt());
147+
value_t ptI = getPtInv();
148148
value_t snp = getSnp();
149-
if (ptI < constants::math::Almost0 || gpu::CAMath::Abs(snp) > constants::math::Almost1) {
149+
if (gpu::CAMath::Abs(snp) > constants::math::Almost1) {
150150
return false;
151151
}
152152
value_t &sn = posdirp[7], &cs = posdirp[8];

0 commit comments

Comments
 (0)