diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp index 5b6aa524115..df2962863b9 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp @@ -291,11 +291,7 @@ inline Acts::Result Acts::AdaptiveMultiVertexFitter::setWeightsAndUpdate( // Update the vertex with the new track. The second template argument // corresponds to the number of fitted vertex dimensions (i.e., 3 if we // only fit spatial coordinates and 4 if we also fit time). - if (m_cfg.useTime) { - KalmanVertexUpdater::updateVertexWithTrack<4>(*vtx, trkAtVtx); - } else { - KalmanVertexUpdater::updateVertexWithTrack<3>(*vtx, trkAtVtx); - } + KalmanVertexUpdater::updateVertexWithTrack(*vtx, trkAtVtx, m_cfg.useTime ? 4 : 3); } else { ACTS_VERBOSE("Track weight too low. Skip track."); } diff --git a/Core/include/Acts/Vertexing/KalmanVertexTrackUpdater.hpp b/Core/include/Acts/Vertexing/KalmanVertexTrackUpdater.hpp index 9ce58e47238..3a68b248756 100644 --- a/Core/include/Acts/Vertexing/KalmanVertexTrackUpdater.hpp +++ b/Core/include/Acts/Vertexing/KalmanVertexTrackUpdater.hpp @@ -39,22 +39,5 @@ namespace KalmanVertexTrackUpdater { void update(TrackAtVertexRef track, const Vector4& vtxPosFull, const SquareMatrix4& vtxCovFull, unsigned int nDimVertex); -namespace detail { - -/// @brief Calculates a covariance matrix for the refitted track parameters -/// -/// @param wMat W_k matrix from Ref. (1) -/// @param crossCovVP Cross-covariance matrix between vertex position and track -/// momentum -/// @param vtxCov Vertex covariance matrix -/// @param newTrkParams Refitted track parameters -template -inline BoundMatrix calculateTrackCovariance( - const SquareMatrix3& wMat, const ActsMatrix& crossCovVP, - const ActsSquareMatrix& vtxCov, - const BoundVector& newTrkParams); - -} // Namespace detail - } // Namespace KalmanVertexTrackUpdater } // Namespace Acts diff --git a/Core/include/Acts/Vertexing/KalmanVertexUpdater.hpp b/Core/include/Acts/Vertexing/KalmanVertexUpdater.hpp index 3baecfbf7fc..de5ba726d5d 100644 --- a/Core/include/Acts/Vertexing/KalmanVertexUpdater.hpp +++ b/Core/include/Acts/Vertexing/KalmanVertexUpdater.hpp @@ -54,25 +54,7 @@ struct Cache { SquareMatrix3 wMat = SquareMatrix3::Zero(); }; -/// @brief Updates vertex with knowledge of new track -/// @note KalmanVertexUpdater updates the vertex when trk is added to the fit. -/// However, it does not add the track to the TrackAtVertex list. This to be -/// done manually after calling the method. -/// -/// @tparam nDimVertex number of dimensions of the vertex. Can be 3 (if we only -/// fit its spatial coordinates) or 4 (if we also fit time). -/// -/// @param vtx Vertex to be updated -/// @param trk Track to be used for updating the vertex -template -void updateVertexWithTrack(Vertex& vtx, TrackAtVertex& trk); - namespace detail { -void updateVertexWithTrack(Vector4& vtxPos, SquareMatrix4& vtxCov, - std::pair& fitQuality, - TrackAtVertexRef trk, int sign, - unsigned int nDimVertex); - // These two functions only exist so we can compile calculateUpdate in a // compilation unit void calculateUpdate3(const Vector4& vtxPos, const SquareMatrix4& vtxCov, @@ -86,6 +68,19 @@ void calculateUpdate4(const Vector4& vtxPos, const SquareMatrix4& vtxCov, Cache<4>& cache); } // namespace detail +/// @brief Updates vertex with knowledge of new track +/// @note KalmanVertexUpdater updates the vertex when trk is added to the fit. +/// However, it does not add the track to the TrackAtVertex list. This to be +/// done manually after calling the method. +/// +/// +/// @param vtx Vertex to be updated +/// @param trk Track to be used for updating the vertex +/// @param nDimVertex number of dimensions of the vertex. Can be 3 (if we only +/// fit its spatial coordinates) or 4 (if we also fit time). +void updateVertexWithTrack(Vertex& vtx, TrackAtVertex& trk, + unsigned int nDimVertex); + /// @brief Calculates updated vertex position and covariance as well as the /// updated track momentum when adding/removing linTrack. Saves the result in /// cache. @@ -119,7 +114,5 @@ void calculateUpdate(const Vector4& vtxPos, const SquareMatrix4& vtxCov, } } -} // Namespace KalmanVertexUpdater -} // Namespace Acts - -#include "KalmanVertexUpdater.ipp" +} // namespace KalmanVertexUpdater +} // namespace Acts diff --git a/Core/src/Vertexing/KalmanVertexTrackUpdater.cpp b/Core/src/Vertexing/KalmanVertexTrackUpdater.cpp index 243335fc5ad..121aeaa02f6 100644 --- a/Core/src/Vertexing/KalmanVertexTrackUpdater.cpp +++ b/Core/src/Vertexing/KalmanVertexTrackUpdater.cpp @@ -18,6 +18,16 @@ namespace Acts { namespace { +/// @brief Calculates a covariance matrix for the refitted track parameters +/// +/// @tparam nDimVertex number of dimensions of the vertex. Can be 3 (if we only +/// fit its spatial coordinates) or 4 (if we also fit time). +/// +/// @param wMat W_k matrix from Ref. (1) +/// @param crossCovVP Cross-covariance matrix between vertex position and track +/// momentum +/// @param vtxCov Vertex covariance matrix +/// @param newTrkParams Refitted track parameters template Acts::BoundMatrix calculateTrackCovariance( const SquareMatrix3& wMat, const ActsMatrix& crossCovVP, diff --git a/Core/src/Vertexing/KalmanVertexUpdater.cpp b/Core/src/Vertexing/KalmanVertexUpdater.cpp index ac4f0769f4b..03779c3820b 100644 --- a/Core/src/Vertexing/KalmanVertexUpdater.cpp +++ b/Core/src/Vertexing/KalmanVertexUpdater.cpp @@ -13,6 +13,21 @@ namespace Acts { namespace { + +/// @brief Calculates updated vertex position and covariance as well as the +/// updated track momentum when adding/removing linTrack. Saves the result in +/// cache. +/// +/// @tparam nDimVertex number of dimensions of the vertex. Can be 3 (if we only +/// fit its spatial coordinates) or 4 (if we also fit time). +/// +/// @param vtx Vertex +/// @param linTrack Linearized track to be added or removed +/// @param trackWeight Track weight +/// @param sign +1 (add track) or -1 (remove track) +/// @note Tracks are removed during the smoothing procedure to compute +/// the chi2 of the track wrt the updated vertex position +/// @param[out] cache A cache to store the results of this function template void calculateUpdateImpl(const Vector4& vtxPos, const SquareMatrix4& vtxCov, const Acts::LinearizedTrack& linTrack, @@ -145,8 +160,14 @@ void update(Vector4& vtxPos, SquareMatrix4& vtxCov, KalmanVertexUpdater::Cache cache; // Calculate update and save result in cache - calculateUpdate(vtxPos, vtxCov, trk.linearizedState, trackWeight, sign, - cache); + + if constexpr (nDimVertex == 3) { + calculateUpdateImpl(vtxPos, vtxCov, trk.linearizedState, trackWeight, sign, + cache); + } else if constexpr (nDimVertex == 4) { + calculateUpdateImpl(vtxPos, vtxCov, trk.linearizedState, trackWeight, sign, + cache); + } // Get fit quality parameters wrt to old vertex double chi2 = 0.; @@ -206,19 +227,20 @@ void KalmanVertexUpdater::detail::calculateUpdate4( calculateUpdateImpl<4>(vtxPos, vtxCov, linTrack, trackWeight, sign, cache); } -void KalmanVertexUpdater::detail::updateVertexWithTrack( - Vector4& vtxPos, SquareMatrix4& vtxCov, - std::pair& fitQuality, TrackAtVertexRef trk, int sign, - unsigned int nDimVertex) { +void KalmanVertexUpdater::updateVertexWithTrack(Vertex& vtx, TrackAtVertex& trk, + unsigned int nDimVertex) { + std::pair fitQuality = vtx.fitQuality(); + if (nDimVertex == 3) { - update<3>(vtxPos, vtxCov, fitQuality, trk, sign); + update<3>(vtx.fullPosition(), vtx.fullCovariance(), fitQuality, trk, 1); } else if (nDimVertex == 4) { - update<4>(vtxPos, vtxCov, fitQuality, trk, sign); + update<4>(vtx.fullPosition(), vtx.fullCovariance(), fitQuality, trk, 1); } else { throw std::invalid_argument( "The vertex dimension must either be 3 (when fitting the spatial " "coordinates) or 4 (when fitting the spatial coordinates + time)."); } + vtx.setFitQuality(fitQuality); } } // namespace Acts diff --git a/Tests/UnitTests/Core/Vertexing/KalmanVertexUpdaterTests.cpp b/Tests/UnitTests/Core/Vertexing/KalmanVertexUpdaterTests.cpp index 5dbf8016eae..1328b80f7fc 100644 --- a/Tests/UnitTests/Core/Vertexing/KalmanVertexUpdaterTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/KalmanVertexUpdaterTests.cpp @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(Kalman_Vertex_Updater) { vtx.setFullCovariance(SquareMatrix4::Identity() * 0.01); // Update trkAtVertex with assumption of originating from vtx - KalmanVertexUpdater::updateVertexWithTrack<3>(vtx, trkAtVtx); + KalmanVertexUpdater::updateVertexWithTrack(vtx, trkAtVtx, 3); if (debug) { std::cout << "Old vertex position: " << vtxPos << std::endl;