@@ -867,6 +867,30 @@ GPUd() bool TrackParametrization<value_T>::getXatLabR(value_t r, value_t& x, val
867867 return true ;
868868}
869869
870+ // ______________________________________________
871+ template <typename value_T>
872+ GPUd () int TrackParametrization<value_T>::getELossSteps(value_t xrho, bool anglecorr) const
873+ {
874+ // Copied from correctForMaterial before entering its energy-loss loop
875+ const value_t m = getPID ().getMass ();
876+ if (!(m > 0 ) || xrho == 0 .f ) {
877+ return 0 ; // correctForMaterial skips the energy-loss block entirely
878+ }
879+ if (anglecorr) {
880+ const value_t csp2 = (1 .f - getSnp ()) * (1 .f + getSnp ()); // cos(phi)^2
881+ const value_t cst2I = (1 .f + getTgl () * getTgl ()); // 1/cos(lambda)^2
882+ xrho *= gpu::CAMath::Sqrt (cst2I / csp2);
883+ }
884+ const value_t p = getP (), massInv = 1 .f / m;
885+ const value_t e = gpu::CAMath::Sqrt (p * p + getPID ().getMass2 ()), ekin = e - m;
886+ value_t dedx = getdEdxBBOpt (p * massInv);
887+ const int charge2 = getAbsCharge () * getAbsCharge ();
888+ if (charge2 != 1 ) {
889+ dedx *= charge2;
890+ }
891+ return nELossSteps (dedx * xrho, ekin);
892+ }
893+
870894// ______________________________________________
871895template <typename value_T>
872896GPUd () bool TrackParametrization<value_T>::correctForELoss(value_t xrho, bool anglecorr)
@@ -891,7 +915,7 @@ GPUd() bool TrackParametrization<value_T>::correctForELoss(value_t xrho, bool an
891915 xrho *= angle;
892916 }
893917 int charge2 = getAbsCharge () * getAbsCharge ();
894- value_t p = getP (), p0 = p, p2 = p * p, e2 = p2 + getPID ().getMass2 (), massInv = 1 . / m, bg = p * massInv;
918+ value_t p = getP (), p0 = p, p2 = p * p, e2 = p2 + getPID ().getMass2 (), massInv = 1 .f / m, bg = p * massInv;
895919 value_t e = gpu::CAMath::Sqrt (e2 ), ekin = e - m, dedx = getdEdxBBOpt (bg);
896920#ifdef _BB_NONCONST_CORR_
897921 value_t dedxDer = 0 ., dedx1 = dedx;
@@ -900,10 +924,7 @@ GPUd() bool TrackParametrization<value_T>::correctForELoss(value_t xrho, bool an
900924 dedx *= charge2;
901925 }
902926 value_t dE = dedx * xrho;
903- int na = 1 + int (gpu::CAMath::Abs (dE) / ekin * ELoss2EKinThreshInv);
904- if (na > MaxELossIter) {
905- na = MaxELossIter;
906- }
927+ int na = nELossSteps (dE, ekin);
907928 if (na > 1 ) {
908929 dE /= na;
909930 xrho /= na;
0 commit comments