Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor how the bound state covariance is handled without transport #3104

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ class CombinatorialKalmanFilter {
if (!boundStateRes.ok()) {
return boundStateRes.error();
}
auto boundState = *boundStateRes;
auto& boundState = *boundStateRes;
auto& [boundParams, jacobian, pathLength] = boundState;
boundParams.covariance() = state.stepping.cov;

// Retrieve the previous tip and its state
// The states created on this surface will have the common previous tip
Expand Down Expand Up @@ -940,9 +942,7 @@ class CombinatorialKalmanFilter {
const auto& [boundParams, jacobian, pathLength] = boundState;
// Fill the track state
trackStateProxy.predicted() = boundParams.parameters();
if (boundParams.covariance().has_value()) {
trackStateProxy.predictedCovariance() = *boundParams.covariance();
}
trackStateProxy.predictedCovariance() = boundParams.covariance().value();
trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;
// Set the surface
Expand Down
13 changes: 5 additions & 8 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,14 @@ class Gx2Fitter {
result.result = res.error();
return;
}
auto& [boundParams, jacobian, pathLength] = *res;
const auto& [boundParams, jacobian, pathLength] = *res;

// Fill the track state
trackStateProxy.predicted() = std::move(boundParams.parameters());
if (boundParams.covariance().has_value()) {
trackStateProxy.predictedCovariance() =
std::move(*boundParams.covariance());
}
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);
trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;
}

// We have predicted parameters, so calibrate the uncalibrated input
Expand Down
13 changes: 5 additions & 8 deletions Core/include/Acts/TrackFitting/KalmanFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,17 +744,14 @@ class KalmanFitter {
if (!res.ok()) {
return res.error();
}
auto& [boundParams, jacobian, pathLength] = *res;
const auto& [boundParams, jacobian, pathLength] = *res;

// Fill the track state
trackStateProxy.predicted() = std::move(boundParams.parameters());
if (boundParams.covariance().has_value()) {
trackStateProxy.predictedCovariance() =
std::move(*boundParams.covariance());
}
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);
trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;
}

// We have predicted parameters, so calibrate the uncalibrated input
Expand Down
27 changes: 11 additions & 16 deletions Core/include/Acts/TrackFitting/detail/KalmanUpdateHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"
Expand Down Expand Up @@ -59,17 +60,14 @@ auto kalmanHandleMeasurement(
<< " failed: " << res.error());
return res.error();
}
auto &[boundParams, jacobian, pathLength] = *res;
const auto &[boundParams, jacobian, pathLength] = *res;

// Fill the track state
trackStateProxy.predicted() = std::move(boundParams.parameters());
if (boundParams.covariance().has_value()) {
trackStateProxy.predictedCovariance() =
std::move(*boundParams.covariance());
}
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);
trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;
}

// We have predicted parameters, so calibrate the uncalibrated input
Expand Down Expand Up @@ -154,17 +152,14 @@ auto kalmanHandleNoMeasurement(
if (!res.ok()) {
return res.error();
}
auto &[boundParams, jacobian, pathLength] = *res;
const auto &[boundParams, jacobian, pathLength] = *res;

// Fill the track state
trackStateProxy.predicted() = std::move(boundParams.parameters());
if (boundParams.covariance().has_value()) {
trackStateProxy.predictedCovariance() =
std::move(*boundParams.covariance());
}
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);
trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;

// Set the filtered parameter index to be the same with predicted
// parameter
Expand Down
8 changes: 0 additions & 8 deletions Core/src/Propagator/detail/CovarianceEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ Result<BoundState> detail::boundState(
// Covariance transport
std::optional<BoundSquareMatrix> cov = std::nullopt;
if (covTransport) {
// Initialize the jacobian from start local to final local
fullTransportJacobian = BoundMatrix::Identity();
// Calculate the jacobian and transport the covarianceMatrix to final local.
// Then reinitialize the transportJacobian, derivatives and the
// boundToFreeJacobian
transportCovarianceToBound(geoContext, surface, boundCovariance,
fullTransportJacobian, freeTransportJacobian,
freeToPathDerivatives, boundToFreeJacobian,
freeParameters, freeToBoundCorrection);
}
if (boundCovariance != BoundSquareMatrix::Zero()) {
cov = boundCovariance;
}

Expand All @@ -82,16 +78,12 @@ CurvilinearState detail::curvilinearState(
// Covariance transport
std::optional<BoundSquareMatrix> cov = std::nullopt;
if (covTransport) {
// Initialize the jacobian from start local to final local
fullTransportJacobian = BoundMatrix::Identity();
// Calculate the jacobian and transport the covarianceMatrix to final local.
// Then reinitialize the transportJacobian, derivatives and the
// boundToFreeJacobian
transportCovarianceToCurvilinear(
boundCovariance, fullTransportJacobian, freeTransportJacobian,
freeToPathDerivatives, boundToFreeJacobian, direction);
}
if (boundCovariance != BoundSquareMatrix::Zero()) {
cov = boundCovariance;
}

Expand Down
6 changes: 2 additions & 4 deletions Tests/UnitTests/Core/Propagator/CovarianceEngineTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ BOOST_AUTO_TEST_CASE(covariance_engine_test) {
BOOST_CHECK_EQUAL(parameters, startParameters);

// Produce a curvilinear state without covariance matrix
auto covarianceBefore = covariance;
auto curvResult = detail::curvilinearState(
covariance, jacobian, transportJacobian, derivatives, boundToFreeJacobian,
parameters, particleHypothesis, false, 1337.);
BOOST_CHECK(std::get<0>(curvResult).covariance().has_value());
BOOST_CHECK_EQUAL(*(std::get<0>(curvResult).covariance()), covarianceBefore);
BOOST_CHECK(!std::get<0>(curvResult).covariance().has_value());
andiwand marked this conversation as resolved.
Show resolved Hide resolved
BOOST_CHECK_EQUAL(std::get<2>(curvResult), 1337.);

// Reset
Expand All @@ -136,7 +134,7 @@ BOOST_AUTO_TEST_CASE(covariance_engine_test) {
BOOST_CHECK_EQUAL(std::get<2>(curvResult), 1337.);

// Produce a bound state without covariance matrix
covarianceBefore = covariance;
auto covarianceBefore = covariance;
auto boundResult =
detail::boundState(tgContext, *surface, covariance, jacobian,
transportJacobian, derivatives, boundToFreeJacobian,
Expand Down
Loading