File indexing completed on 2025-01-19 09:23:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012
0013 #include <type_traits>
0014
0015 namespace Acts::detail {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template <typename CovMatrix_t, signed int NumIter = 1>
0030 struct CovarianceHelper {
0031
0032 static bool validate(CovMatrix_t& covariance) {
0033 if (covariance.hasNaN()) {
0034 return false;
0035 }
0036 std::size_t nIteration = 0;
0037 while (nIteration < NumIter) {
0038 if (isSemiPositive(covariance)) {
0039 return true;
0040 } else {
0041 Eigen::JacobiSVD<CovMatrix_t> svdCov(
0042 covariance, Eigen::ComputeFullU | Eigen::ComputeFullV);
0043 CovMatrix_t S = svdCov.singularValues().asDiagonal();
0044 CovMatrix_t V = svdCov.matrixV();
0045 CovMatrix_t H = V * S * V.transpose();
0046 covariance = (covariance + H) / 2;
0047 nIteration++;
0048 }
0049 }
0050
0051 return isSemiPositive(covariance);
0052 }
0053
0054
0055 static bool isSemiPositive(const CovMatrix_t& covariance) {
0056 if (covariance.hasNaN()) {
0057 return false;
0058 }
0059 Eigen::LDLT<CovMatrix_t> ldltCov(covariance);
0060 return ldltCov.isPositive();
0061 }
0062
0063
0064 static bool isPositive(const CovMatrix_t& covariance) {
0065 if (covariance.hasNaN()) {
0066 return false;
0067 }
0068 Eigen::LLT<CovMatrix_t> lltCov(covariance);
0069 return lltCov.info() == Eigen::Success ? true : false;
0070 }
0071 };
0072
0073 }