File indexing completed on 2025-11-06 09:17:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/EventData/MultiTrajectory.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Utilities/Delegate.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 #include "Acts/Utilities/Result.hpp"
0016
0017 #include <cassert>
0018 #include <cstddef>
0019 #include <system_error>
0020
0021 namespace Acts {
0022
0023
0024
0025
0026
0027
0028 class GainMatrixSmoother {
0029 public:
0030
0031
0032 bool doCovCheckAndAttemptFix = false;
0033
0034
0035
0036
0037
0038
0039
0040
0041 template <typename traj_t>
0042 Result<void> operator()(const GeometryContext& gctx, traj_t& trajectory,
0043 std::size_t entryIndex,
0044 const Logger& logger = getDummyLogger()) const {
0045 (void)gctx;
0046
0047 using TrackStateProxy = typename traj_t::TrackStateProxy;
0048
0049 GetParameters filtered;
0050 GetCovariance filteredCovariance;
0051 GetParameters smoothed;
0052 GetParameters predicted;
0053 GetCovariance predictedCovariance;
0054 GetCovariance smoothedCovariance;
0055 GetCovariance jacobian;
0056
0057 filtered.connect([](const void*, void* ts) {
0058 return static_cast<TrackStateProxy*>(ts)->filtered();
0059 });
0060 filteredCovariance.connect([](const void*, void* ts) {
0061 return static_cast<TrackStateProxy*>(ts)->filteredCovariance();
0062 });
0063
0064 smoothed.connect([](const void*, void* ts) {
0065 return static_cast<TrackStateProxy*>(ts)->smoothed();
0066 });
0067 smoothedCovariance.connect([](const void*, void* ts) {
0068 return static_cast<TrackStateProxy*>(ts)->smoothedCovariance();
0069 });
0070
0071 predicted.connect([](const void*, void* ts) {
0072 return static_cast<TrackStateProxy*>(ts)->predicted();
0073 });
0074 predictedCovariance.connect([](const void*, void* ts) {
0075 return static_cast<TrackStateProxy*>(ts)->predictedCovariance();
0076 });
0077
0078 jacobian.connect([](const void*, void* ts) {
0079 return static_cast<TrackStateProxy*>(ts)->jacobian();
0080 });
0081
0082 ACTS_VERBOSE("Invoked GainMatrixSmoother on entry index: " << entryIndex);
0083
0084
0085 ACTS_VERBOSE("Getting previous track state");
0086 auto prev_ts = trajectory.getTrackState(entryIndex);
0087
0088 prev_ts.shareFrom(TrackStatePropMask::Filtered,
0089 TrackStatePropMask::Smoothed);
0090
0091
0092 if (!prev_ts.hasPrevious()) {
0093 ACTS_VERBOSE("Only one track state given, smoothing terminates early");
0094 return Result<void>::success();
0095 }
0096
0097 ACTS_VERBOSE("Start smoothing from previous track state at index: "
0098 << prev_ts.previous());
0099
0100
0101 std::error_code error;
0102 trajectory.applyBackwards(prev_ts.previous(), [&, this](auto ts) {
0103
0104
0105 assert(ts.hasFiltered());
0106 assert(ts.hasPredicted());
0107
0108
0109 assert(prev_ts.hasSmoothed());
0110 assert(prev_ts.hasPredicted());
0111 assert(prev_ts.hasJacobian());
0112
0113 ACTS_VERBOSE("Calculate smoothing matrix:");
0114 ACTS_VERBOSE("Filtered covariance:\n" << ts.filteredCovariance());
0115 ACTS_VERBOSE("Jacobian:\n" << prev_ts.jacobian());
0116
0117
0118 ts.addComponents(TrackStatePropMask::Smoothed);
0119
0120 if (auto res = calculate(&ts, &prev_ts, filtered, filteredCovariance,
0121 smoothed, predicted, predictedCovariance,
0122 smoothedCovariance, jacobian, logger);
0123 !res.ok()) {
0124 error = res.error();
0125 return false;
0126 }
0127
0128 prev_ts = ts;
0129 return true;
0130 });
0131
0132 return error ? Result<void>::failure(error) : Result<void>::success();
0133 }
0134
0135
0136 using GetParameters =
0137 Acts::Delegate<TrackStateTraits<MultiTrajectoryTraits::MeasurementSizeMax,
0138 false>::Parameters(void*)>;
0139
0140 using GetCovariance =
0141 Acts::Delegate<TrackStateTraits<MultiTrajectoryTraits::MeasurementSizeMax,
0142 false>::Covariance(void*)>;
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 Result<void> calculate(void* ts, void* prev_ts, const GetParameters& filtered,
0159 const GetCovariance& filteredCovariance,
0160 const GetParameters& smoothed,
0161 const GetParameters& predicted,
0162 const GetCovariance& predictedCovariance,
0163 const GetCovariance& smoothedCovariance,
0164 const GetCovariance& jacobian,
0165 const Logger& logger) const;
0166 };
0167
0168 }