Skip to content
Snippets Groups Projects

Implement new TrackState EDM used in KF

Merged Paul Gessinger requested to merge local_trajectory into master
5 files
+ 234
272
Compare changes
  • Side-by-side
  • Inline
Files
5
  • de4a3bf2
    The gain matrix smoother and updator now accept MJ and TSProxies respectively.
    The KF is changed to accomodate this. The KF now does not pre-fill measurements
    into track states, but appends them to the MJ as it goes along. Calibration is
    now done by the KF itself, the GainMatrixUpdator loses the calibrator object and
    doesn't to it anymore.
    
    WARNING: The Updator currently uses dynamic matrices! This is slow and will be
    replaced with fixed size matrix arithmetic again!
    
    The Updator and Smoother tests are updated to support the new arguments, but
    expect the same calculation results as before.
@@ -10,6 +10,7 @@
#include <boost/range/adaptors.hpp>
#include <memory>
#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/TrackParameters.hpp"
namespace Acts {
@@ -26,70 +27,59 @@ class GainMatrixSmoother {
/// @brief Gain Matrix smoother implementation
///
template <typename track_states_t>
boost::optional<parameters_t> operator()(
const GeometryContext& gctx, track_states_t& filteredStates) const {
template <typename source_link_t>
parameters_t operator()(const GeometryContext& gctx,
MultiTrajectory<source_link_t>& trajectory,
size_t entryIndex) const {
using namespace boost::adaptors;
using track_state_t = typename track_states_t::value_type;
using ParVector_t = typename parameters_t::ParVector_t;
// using ParVector_t = typename parameters_t::ParVector_t;
using CovMatrix_t = typename parameters_t::CovMatrix_t;
using gain_matrix_t = CovMatrix_t;
// smoothed parameter vector and covariance matrix
ParVector_t smoothedPars;
CovMatrix_t smoothedCov;
// For the last state: smoothed is filtered - also: switch to next
auto* prev_ts = &filteredStates.back();
assert(prev_ts->parameter.filtered);
prev_ts->parameter.smoothed = *prev_ts->parameter.filtered;
auto prev_ts = trajectory.getTrackState(entryIndex);
prev_ts.smoothed() = prev_ts.filtered();
prev_ts.smoothedCovariance() = prev_ts.filteredCovariance();
// Smoothing gain matrix
gain_matrix_t G;
// Loop and smooth the remaining states
for (track_state_t& ts :
filteredStates | sliced(0, filteredStates.size() - 1) | reversed) {
// The current state
assert(ts.parameter.filtered);
assert(ts.parameter.predicted);
assert(ts.parameter.jacobian);
assert(ts.parameter.predicted->covariance() != nullptr);
assert(ts.parameter.filtered->covariance() != nullptr);
trajectory.applyBackwards(prev_ts.previous(), [&prev_ts, &G](auto ts) {
// should have filtered and predicted, this should also include the
// covariances.
assert(ts.hasFiltered());
assert(ts.hasPredicted());
assert(ts.hasJacobian());
assert(prev_ts->parameter.smoothed);
assert(prev_ts->parameter.predicted);
// clang-format off
// previous trackstate should have smoothed and predicted
assert(prev_ts.hasSmoothed());
assert(prev_ts.hasPredicted());
// Gain smoothing matrix
G = (*ts.parameter.filtered->covariance())
* ts.parameter.jacobian->transpose()
* (*prev_ts->parameter.predicted->covariance()).inverse();
G = ts.filteredCovariance() * ts.jacobian().transpose() *
prev_ts.predictedCovariance().inverse();
// Calculate the smoothed parameters
smoothedPars = ts.parameter.filtered->parameters()
+ G * (prev_ts->parameter.smoothed->parameters()
- prev_ts->parameter.predicted->parameters());
ts.smoothed() =
ts.filtered() + G * (prev_ts.smoothed() - prev_ts.predicted());
// And the smoothed covariance
smoothedCov = (*ts.parameter.filtered->covariance())
- G * (*(prev_ts->parameter.predicted->covariance())
- (*prev_ts->parameter.smoothed->covariance()))
* G.transpose();
// clang-format on
// Create smoothed track parameters
ts.parameter.smoothed = parameters_t(
gctx, std::make_unique<CovMatrix_t>(std::move(smoothedCov)),
smoothedPars, ts.referenceSurface().getSharedPtr());
// Point prev state to current state
prev_ts = &ts;
}
// The result is the pointer to the last smoothed state - for the cache
return prev_ts->parameter.smoothed;
ts.smoothedCovariance() =
ts.filteredCovariance() -
G * (prev_ts.predictedCovariance() - prev_ts.smoothedCovariance()) *
G.transpose();
prev_ts = ts;
});
// construct parameters from last track state
parameters_t lastSmoothed(
gctx, std::make_unique<CovMatrix_t>(prev_ts.smoothedCovariance()),
prev_ts.smoothed(), prev_ts.referenceSurface().getSharedPtr());
return lastSmoothed;
}
};
} // namespace Acts
Loading