@@ -1418,18 +1418,31 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(value_t x
14181418 constexpr value_t kMSConst2 = 0 .0136f * 0 .0136f ;
14191419 constexpr value_t kMinP = 0 .01f ; // kill below this momentum
14201420
1421- value_t csp2 = (1 .f - this ->getSnp ()) * (1 .f + this ->getSnp ()); // cos(phi)^2
1422- value_t cst2I = (1 .f + this ->getTgl () * this ->getTgl ()); // 1/cos(lambda)^2
1423- if (anglecorr) { // Apply angle correction, if requested
1421+ if (x2x0 == 0 .f && xrho == 0 .f ) {
1422+ checkCovariance ();
1423+ return true ;
1424+ }
1425+
1426+ value_t csp2 = 0 .f , cst2I = 0 .f ;
1427+ if (anglecorr || x2x0 != 0 .f ) {
1428+ csp2 = (1 .f - this ->getSnp ()) * (1 .f + this ->getSnp ()); // cos(phi)^2
1429+ cst2I = 1 .f + this ->getTgl () * this ->getTgl (); // 1/cos(lambda)^2
1430+ }
1431+ if (anglecorr) {
14241432 value_t angle = math_utils::detail::sqrt<value_t >(cst2I / csp2);
14251433 x2x0 *= angle;
14261434 xrho *= angle;
14271435 }
14281436 auto m = this ->getPID ().getMass ();
14291437 int charge2 = this ->getAbsCharge () * this ->getAbsCharge ();
1430- value_t p = this ->getP (), p0 = p, p02 = p * p, e2 = p02 + this ->getPID ().getMass2 (), massInv = 1 .f / m, bg = p * massInv, dETot = 0 .f ;
1431- value_t e = math_utils::detail::sqrt<value_t >(e2 ), e0 = e;
1432- if (m > 0 && xrho != 0 .f ) {
1438+ const bool applyELoss = m > 0 && xrho != 0 .f ;
1439+ value_t p02 = 0 .f , e2 = 0 .f , pscale = 1 .f , elossVariance = 0 .f ;
1440+ if (applyELoss) {
1441+ value_t p = this ->getP (), p0 = p;
1442+ p02 = p * p;
1443+ e2 = p02 + this ->getPID ().getMass2 ();
1444+ value_t massInv = 1 .f / m, bg = p * massInv;
1445+ value_t e = math_utils::detail::sqrt<value_t >(e2 ), e0 = e;
14331446 value_t ekin = e - m, dedx = this ->getdEdxBBOpt (bg);
14341447#ifdef _BB_NONCONST_CORR_
14351448 value_t dedxDer = 0 .f , dedx1 = dedx;
@@ -1460,11 +1473,11 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(value_t x
14601473 }
14611474#endif
14621475 e += dE;
1463- if (e > m) { // stopped
1464- p = math_utils::detail::sqrt<value_t >(e * e - this ->getPID ().getMass2 ());
1465- } else {
1476+ const value_t p2 = e * e - this ->getPID ().getMass2 ();
1477+ if (!(e > m && p2 >= kMinP * kMinP )) {
14661478 return false ;
14671479 }
1480+ p = math_utils::detail::sqrt<value_t >(p2);
14681481 if (na) {
14691482 bg = p * massInv;
14701483 dedx = this ->getdEdxBBOpt (bg);
@@ -1481,10 +1494,15 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(value_t x
14811494 }
14821495 }
14831496
1484- if (p < kMinP ) {
1485- return false ;
1486- }
1487- dETot = e - e0 ;
1497+ // Compute the variance directly: the square root of |dE| would be squared again.
1498+ constexpr value_t knst = 0 .0007f ; // To be tuned.
1499+ const value_t factor = knst * e0 / p02 * this ->getCharge2Pt ();
1500+ elossVariance = gpu::CAMath::Abs (e - e0 ) * factor * factor;
1501+ pscale = p0 / p;
1502+ } else if (x2x0 != 0 .f ) {
1503+ // Scattering needs squared momentum and energy, but no energy-loss square roots.
1504+ p02 = this ->getP2 ();
1505+ e2 = p02 + this ->getPID ().getMass2 ();
14881506 } // end of e.loss correction
14891507
14901508 // Calculating the multiple scattering corrections******************
@@ -1516,17 +1534,17 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(value_t x
15161534 // cC44 = theta2*getTgl()*this->getQ2Pt()*getTgl()*this->getQ2Pt();
15171535 }
15181536
1519- // the energy loss correction contribution to cov.matrix: approximate energy loss fluctuation (M.Ivanov)
1520- constexpr value_t knst = 0 .0007f ; // To be tuned.
1521- value_t sigmadE = knst * math_utils::detail::sqrt<value_t >(gpu::CAMath::Abs (dETot)) * e0 / p02 * this ->getCharge2Pt ();
1522- cC44 += sigmadE * sigmadE;
1537+ // Energy-loss fluctuation contribution to the momentum variance (M. Ivanov).
1538+ cC44 += elossVariance;
15231539
15241540 // Applying the corrections*****************************
15251541 fC22 += cC22;
15261542 fC33 += cC33;
15271543 fC43 += cC43;
15281544 fC44 += cC44;
1529- this ->setQ2Pt (this ->getQ2Pt () * p0 / p);
1545+ if (applyELoss) {
1546+ this ->setQ2Pt (this ->getQ2Pt () * pscale);
1547+ }
15301548
15311549 checkCovariance ();
15321550
@@ -1549,19 +1567,31 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(TrackPara
15491567 constexpr value_t kMSConst2 = 0 .0136f * 0 .0136f ;
15501568 constexpr value_t kMinP = 0 .01f ; // kill below this momentum
15511569
1552- value_t csp2 = (1 .f - linRef.getSnp ()) * (1 .f + linRef.getSnp ()); // cos(phi)^2
1553- value_t cst2I = (1 .f + linRef.getTgl () * linRef.getTgl ()); // 1/cos(lambda)^2
1554- if (anglecorr) { // Apply angle correction, if requested
1570+ if (x2x0 == 0 .f && xrho == 0 .f ) {
1571+ checkCovariance ();
1572+ return true ;
1573+ }
1574+
1575+ value_t csp2 = 0 .f , cst2I = 0 .f ;
1576+ if (anglecorr || x2x0 != 0 .f ) {
1577+ csp2 = (1 .f - linRef.getSnp ()) * (1 .f + linRef.getSnp ()); // cos(phi)^2
1578+ cst2I = 1 .f + linRef.getTgl () * linRef.getTgl (); // 1/cos(lambda)^2
1579+ }
1580+ if (anglecorr) {
15551581 value_t angle = math_utils::detail::sqrt<value_t >(cst2I / csp2);
15561582 x2x0 *= angle;
15571583 xrho *= angle;
15581584 }
1559- auto pid = linRef.getPID ();
1560- auto m = pid.getMass ();
1585+ auto m = linRef.getPID ().getMass ();
15611586 int charge2 = linRef.getAbsCharge () * linRef.getAbsCharge ();
1562- value_t p = linRef.getP (), p0 = p, p02 = p * p, e2 = p02 + pid.getMass2 (), massInv = 1 .f / m, bg = p * massInv, dETot = 0 .f ;
1563- value_t e = math_utils::detail::sqrt<value_t >(e2 ), e0 = e;
1564- if (m > 0 && xrho != 0 .f ) {
1587+ const bool applyELoss = m > 0 && xrho != 0 .f ;
1588+ value_t p02 = 0 .f , e2 = 0 .f , pscale = 1 .f , elossVariance = 0 .f ;
1589+ if (applyELoss) {
1590+ value_t p = linRef.getP (), p0 = p;
1591+ p02 = p * p;
1592+ e2 = p02 + linRef.getPID ().getMass2 ();
1593+ value_t massInv = 1 .f / m, bg = p * massInv;
1594+ value_t e = math_utils::detail::sqrt<value_t >(e2 ), e0 = e;
15651595 value_t ekin = e - m, dedx = this ->getdEdxBBOpt (bg);
15661596#ifdef _BB_NONCONST_CORR_
15671597 value_t dedxDer = 0 .f , dedx1 = dedx;
@@ -1592,11 +1622,11 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(TrackPara
15921622 }
15931623#endif
15941624 e += dE;
1595- if (e > m) { // stopped
1596- p = math_utils::detail::sqrt<value_t >(e * e - pid.getMass2 ());
1597- } else {
1625+ const value_t p2 = e * e - linRef.getPID ().getMass2 ();
1626+ if (!(e > m && p2 >= kMinP * kMinP )) {
15981627 return false ;
15991628 }
1629+ p = math_utils::detail::sqrt<value_t >(p2);
16001630 if (na) {
16011631 bg = p * massInv;
16021632 dedx = this ->getdEdxBBOpt (bg);
@@ -1613,10 +1643,15 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(TrackPara
16131643 }
16141644 }
16151645
1616- if (p < kMinP ) {
1617- return false ;
1618- }
1619- dETot = e - e0 ;
1646+ // Compute the variance directly: the square root of |dE| would be squared again.
1647+ constexpr value_t knst = 0 .0007f ; // To be tuned.
1648+ const value_t factor = knst * e0 / p02 * linRef.getCharge2Pt ();
1649+ elossVariance = gpu::CAMath::Abs (e - e0 ) * factor * factor;
1650+ pscale = p0 / p;
1651+ } else if (x2x0 != 0 .f ) {
1652+ // Scattering needs squared momentum and energy, but no energy-loss square roots.
1653+ p02 = linRef.getP2 ();
1654+ e2 = p02 + linRef.getPID ().getMass2 ();
16201655 } // end of e.loss correction
16211656
16221657 // Calculating the multiple scattering corrections******************
@@ -1648,19 +1683,18 @@ GPUd() bool TrackParametrizationWithError<value_T>::correctForMaterial(TrackPara
16481683 // cC44 = theta2*getTgl()*this->getQ2Pt()*getTgl()*this->getQ2Pt();
16491684 }
16501685
1651- // the energy loss correction contribution to cov.matrix: approximate energy loss fluctuation (M.Ivanov)
1652- constexpr value_t knst = 0 .0007f ; // To be tuned.
1653- value_t sigmadE = knst * math_utils::detail::sqrt<value_t >(gpu::CAMath::Abs (dETot)) * e0 / p02 * linRef.getCharge2Pt ();
1654- cC44 += sigmadE * sigmadE;
1686+ // Energy-loss fluctuation contribution to the momentum variance (M. Ivanov).
1687+ cC44 += elossVariance;
16551688
16561689 // Applying the corrections*****************************
16571690 fC22 += cC22;
16581691 fC33 += cC33;
16591692 fC43 += cC43;
16601693 fC44 += cC44;
1661- auto pscale = p0 / p;
1662- linRef.setQ2Pt (linRef.getQ2Pt () * pscale);
1663- this ->setQ2Pt (this ->getQ2Pt () * pscale);
1694+ if (applyELoss) {
1695+ linRef.setQ2Pt (linRef.getQ2Pt () * pscale);
1696+ this ->setQ2Pt (this ->getQ2Pt () * pscale);
1697+ }
16641698
16651699 checkCovariance ();
16661700
0 commit comments