From 1deb689240ff4c175c7ea6bbdf7104cb44766593 Mon Sep 17 00:00:00 2001 From: Adrien Blanchet Date: Tue, 19 Nov 2024 13:37:02 +0100 Subject: [PATCH] adding check for prior matrix inversion --- src/ParametersManager/src/ParameterSet.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ParametersManager/src/ParameterSet.cpp b/src/ParametersManager/src/ParameterSet.cpp index 63c5cbdb..a18277d4 100644 --- a/src/ParametersManager/src/ParameterSet.cpp +++ b/src/ParametersManager/src/ParameterSet.cpp @@ -195,7 +195,26 @@ void ParameterSet::processCovarianceMatrix(){ << _strippedCovarianceMatrix_->GetNcols() << "x" << _strippedCovarianceMatrix_->GetNrows() << std::endl; _inverseStrippedCovarianceMatrix_ = std::shared_ptr((TMatrixD*)(_strippedCovarianceMatrix_->Clone())); - _inverseStrippedCovarianceMatrix_->Invert(); + + double det; + _inverseStrippedCovarianceMatrix_->Invert(&det); + + bool failed{false}; + if( det == 0 ){ + LogError << "Determinant is null." << std::endl; + failed = true; + } + + TVectorD eigenValues; + // https://root-forum.cern.ch/t/tmatrixt-get-eigenvalues/25924 + _inverseStrippedCovarianceMatrix_->EigenVectors(eigenValues); + if( eigenValues.Min() < 0 ){ + LogError << "Negative eigen values for prior cov matrix: " << eigenValues.Min() << std::endl; + failed = true; + } + + LogThrowIf(failed, "Failed inverting prior covariance matrix of par set: " << getName() ); + } else { LogWarning << "Decomposing the stripped covariance matrix..." << std::endl;