diff --git a/Phys/SelTools/include/SelTools/DistanceCalculator.h b/Phys/SelTools/include/SelTools/DistanceCalculator.h index 2d3c139b448cd3db79634c071d14a075100030a7..08b57050d8742e8ccbbe55e19ea5bf616795b36e 100644 --- a/Phys/SelTools/include/SelTools/DistanceCalculator.h +++ b/Phys/SelTools/include/SelTools/DistanceCalculator.h @@ -259,9 +259,16 @@ namespace Sel { } auto [success, W_Inv] = W.invChol(); - auto halfdChi2dLam2 = similarity( dir, W_Inv ); - auto decayLength = dot( dir, W_Inv * flight ) / halfdChi2dLam2; - auto decayLengthErr = sqrt( 1 / halfdChi2dLam2 ); + // Temporary fix: If W is not invertible due to neg Det, exclude 'a' terms. + if ( !success ) { + for ( size_t row = 0; row < 3; ++row ) { + for ( size_t col = 0; col <= row; ++col ) { W( row, col ) = vertexCov( row, col ) + pCov( row, col ); } + } + } + std::tie( success, W_Inv ) = W.invChol(); + auto halfdChi2dLam2 = similarity( dir, W_Inv ); + auto decayLength = dot( dir, W_Inv * flight ) / halfdChi2dLam2; + auto decayLengthErr = sqrt( 1 / halfdChi2dLam2 ); if constexpr ( std::is_arithmetic_v ) { return success ? decayLength / decayLengthErr : NonPhysicalValue; } else { @@ -318,11 +325,13 @@ namespace Sel { using LHCb::Event::fourMomentum; using Sel::Utils::all; using std::abs; + using std::isnan; using std::sqrt; // convergence parameters const float_v delta_chi2 = 0.001; const int m_max_iter = 5; + const auto ctau_init = ctau; // invariants which are not changed during iteration const auto momCov = momCovMatrix( particle ); @@ -349,7 +358,9 @@ namespace Sel { error = new_error; if ( converged ) { break; } } - + // Temporary fix: In case of NaN, take initial value for ctau + float ctau_float = static_cast( ctau ); + ctau = isnan( ctau_float ) ? ctau_init : ctau; if ( !converged && m_no_convergence.has_value() ) { ++( *m_no_convergence ); } }