Warning, file /acts/Core/include/Acts/TrackFitting/detail/TrackletJoining.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/EventData/AnyTrackStateProxy.hpp"
0014 #include "Acts/EventData/TrackProxyCommon.hpp"
0015 #include "Acts/EventData/TrackProxyConcept.hpp"
0016 #include "Acts/EventData/TrackStatePropMask.hpp"
0017 #include "Acts/EventData/TrackStateProxyConcept.hpp"
0018 #include "Acts/EventData/Types.hpp"
0019 #include "Acts/TrackFitting/GainMatrixSmoother.hpp"
0020 #include "Acts/TrackFitting/KalmanFitterError.hpp"
0021 #include "Acts/Utilities/Logger.hpp"
0022 #include "Acts/Utilities/Result.hpp"
0023
0024 #include <cstddef>
0025 #include <optional>
0026 #include <ranges>
0027 #include <utility>
0028 #include <vector>
0029
0030 namespace Acts::detail {
0031
0032
0033
0034
0035
0036 void setSmoothedWithoutSharing(AnyMutableTrackStateProxy ts, BoundVector mean,
0037 BoundMatrix cov);
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 Result<std::pair<BoundVector, BoundMatrix>> smoothPriorNode(
0054 const AnyConstTrackStateProxy& first, const BoundVector& priorMean,
0055 const BoundMatrix& priorCov, const Logger& logger);
0056
0057
0058
0059 struct SharedStateCondition {
0060
0061 BoundVector u = BoundVector::Zero();
0062
0063 BoundMatrix w = BoundMatrix::Zero();
0064 };
0065
0066
0067
0068
0069
0070
0071
0072
0073 Result<SharedStateCondition> makeSharedStateCondition(
0074 const AnyConstTrackStateProxy& shared, const BoundVector& newMean,
0075 const BoundMatrix& newCov, const Logger& logger);
0076
0077
0078
0079
0080
0081
0082
0083
0084 BoundMatrix filteredSensitivity(const AnyConstTrackStateProxy& ts,
0085 const BoundMatrix& dp);
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 Result<void> conditionTrackState(AnyMutableTrackStateProxy ts,
0100 const BoundMatrix& dp, const BoundMatrix& df,
0101 BoundMatrix& psiHat,
0102 const SharedStateCondition& condition,
0103 const Logger& logger);
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 template <typename traj_t>
0132 Result<void> conditionSmoothedStatesOnSharedState(traj_t& trajectory,
0133 std::size_t sharedIndex,
0134 std::size_t tipIndex,
0135 const BoundVector& newMean,
0136 const BoundMatrix& newCov,
0137 const Logger& logger) {
0138 using TrackStateProxy = typename traj_t::TrackStateProxy;
0139
0140
0141 std::vector<std::size_t> indices;
0142 bool found = false;
0143 trajectory.applyBackwards(tipIndex, [&](TrackStateProxy ts) {
0144 indices.push_back(ts.index());
0145 found = (ts.index() == sharedIndex);
0146 return !found;
0147 });
0148 if (!found) {
0149 ACTS_DEBUG("Shared state " << sharedIndex << " is not on the chain of "
0150 << tipIndex);
0151 return KalmanFitterError::SmoothFailed;
0152 }
0153
0154
0155
0156 std::size_t skip = 0;
0157 while (skip + 1 < indices.size() &&
0158 !trajectory.getTrackState(indices[skip]).hasSmoothed()) {
0159 ++skip;
0160 }
0161 indices.erase(indices.begin(), indices.begin() + skip);
0162
0163 auto shared = trajectory.getTrackState(sharedIndex);
0164 if (!shared.hasSmoothed()) {
0165 ACTS_DEBUG("Shared state " << sharedIndex << " has no smoothed parameters");
0166 return KalmanFitterError::SmoothFailed;
0167 }
0168 auto condition = makeSharedStateCondition(AnyConstTrackStateProxy{shared},
0169 newMean, newCov, logger);
0170 if (!condition.ok()) {
0171 return condition.error();
0172 }
0173
0174
0175
0176 std::vector<std::pair<BoundMatrix, BoundMatrix>> sensitivities(
0177 indices.size());
0178 BoundMatrix df = BoundMatrix::Identity();
0179 for (std::size_t k :
0180 std::views::iota(std::size_t{0}, indices.size()) | std::views::reverse) {
0181 auto ts = trajectory.getTrackState(indices[k]);
0182 if (!ts.hasSmoothed() || !ts.hasPredicted() || !ts.hasJacobian()) {
0183 ACTS_DEBUG("State " << ts.index()
0184 << " lacks smoothed, predicted or jacobian");
0185 return KalmanFitterError::SmoothFailed;
0186 }
0187 const bool isShared = (k + 1 == indices.size());
0188 const BoundMatrix dp =
0189 isShared ? BoundMatrix::Identity() : BoundMatrix(ts.jacobian() * df);
0190 df = filteredSensitivity(AnyConstTrackStateProxy{ts}, dp);
0191 sensitivities[k] = {dp, df};
0192 }
0193
0194
0195 BoundMatrix psiHat = BoundMatrix::Zero();
0196 for (std::size_t k = 0; k + 1 < indices.size(); ++k) {
0197 auto ts = trajectory.getTrackState(indices[k]);
0198 const auto& [dp, dfk] = sensitivities[k];
0199 auto res = conditionTrackState(AnyMutableTrackStateProxy{ts}, dp, dfk,
0200 psiHat, *condition, logger);
0201 if (!res.ok()) {
0202 return res.error();
0203 }
0204 }
0205
0206 setSmoothedWithoutSharing(AnyMutableTrackStateProxy{shared}, newMean, newCov);
0207
0208 if (shared.hasPrevious()) {
0209 GainMatrixSmoother smoother;
0210 Result<void> result = Result<void>::success();
0211 auto later = shared;
0212 trajectory.applyBackwards(shared.previous(), [&](TrackStateProxy ts) {
0213 ts.addComponents(TrackStatePropMask::Smoothed);
0214 auto res = smoother.calculate(AnyMutableTrackStateProxy{ts},
0215 AnyConstTrackStateProxy{later}, logger);
0216 if (!res.ok()) {
0217 result = res;
0218 return false;
0219 }
0220 later = ts;
0221 return true;
0222 });
0223 return result;
0224 }
0225
0226 return Result<void>::success();
0227 }
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 template <TrackStateProxyConcept track_state_proxy_t,
0243 TrackProxyConcept track_proxy_t>
0244 std::optional<BoundMatrix> linkTrackletBehind(track_state_proxy_t sharedState,
0245 track_proxy_t& second,
0246 bool invertJacobians) {
0247 std::optional<BoundMatrix> stitch =
0248 second.reverseTrackStates(invertJacobians);
0249 if (second.tipIndex() == kTrackIndexInvalid) {
0250 return stitch;
0251 }
0252
0253 auto secondTip = second.outermostTrackState();
0254 sharedState.previous() = secondTip.index();
0255 secondTip.template component<TrackIndexType>(detail_tp::kNextKey) =
0256 sharedState.index();
0257
0258 if (stitch.has_value()) {
0259 sharedState.jacobian() = *stitch;
0260 }
0261
0262 return stitch;
0263 }
0264
0265 }