File indexing completed on 2025-01-18 09:11:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/EventData/MultiTrajectory.hpp"
0012 #include "Acts/EventData/SourceLink.hpp"
0013 #include "Acts/EventData/TrackParameters.hpp"
0014 #include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "Acts/Utilities/CalibrationContext.hpp"
0017 #include "Acts/Utilities/Result.hpp"
0018
0019 namespace Acts::detail {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template <typename propagator_state_t, typename stepper_t,
0037 typename extensions_t, typename traj_t>
0038 auto kalmanHandleMeasurement(
0039 const CalibrationContext &calibrationContext, propagator_state_t &state,
0040 const stepper_t &stepper, const extensions_t &extensions,
0041 const Surface &surface, const SourceLink &sourceLink, traj_t &fittedStates,
0042 const std::size_t lastTrackIndex, bool doCovTransport, const Logger &logger,
0043 const FreeToBoundCorrection &freeToBoundCorrection = FreeToBoundCorrection(
0044 false)) -> Result<typename traj_t::TrackStateProxy> {
0045
0046
0047 TrackStatePropMask mask =
0048 TrackStatePropMask::Predicted | TrackStatePropMask::Filtered |
0049 TrackStatePropMask::Smoothed | TrackStatePropMask::Jacobian |
0050 TrackStatePropMask::Calibrated;
0051 typename traj_t::TrackStateProxy trackStateProxy =
0052 fittedStates.makeTrackState(mask, lastTrackIndex);
0053
0054
0055
0056 {
0057 trackStateProxy.setReferenceSurface(surface.getSharedPtr());
0058
0059 auto res = stepper.boundState(state.stepping, surface, doCovTransport,
0060 freeToBoundCorrection);
0061 if (!res.ok()) {
0062 ACTS_ERROR("Propagate to surface " << surface.geometryId()
0063 << " failed: " << res.error());
0064 return res.error();
0065 }
0066 const auto &[boundParams, jacobian, pathLength] = *res;
0067
0068
0069 trackStateProxy.predicted() = boundParams.parameters();
0070 trackStateProxy.predictedCovariance() = state.stepping.cov;
0071
0072 trackStateProxy.jacobian() = jacobian;
0073 trackStateProxy.pathLength() = pathLength;
0074 }
0075
0076
0077
0078 extensions.calibrator(state.geoContext, calibrationContext, sourceLink,
0079 trackStateProxy);
0080
0081
0082 {
0083 auto typeFlags = trackStateProxy.typeFlags();
0084 typeFlags.set(TrackStateFlag::ParameterFlag);
0085 if (surface.surfaceMaterial() != nullptr) {
0086 typeFlags.set(TrackStateFlag::MaterialFlag);
0087 }
0088
0089
0090
0091
0092
0093
0094
0095 if (!extensions.outlierFinder(trackStateProxy)) {
0096
0097 auto updateRes =
0098 extensions.updater(state.geoContext, trackStateProxy, logger);
0099 if (!updateRes.ok()) {
0100 ACTS_ERROR("Update step failed: " << updateRes.error());
0101 return updateRes.error();
0102 }
0103
0104 typeFlags.set(TrackStateFlag::MeasurementFlag);
0105 } else {
0106 ACTS_VERBOSE(
0107 "Filtering step successful. But measurement is determined "
0108 "to be an outlier. Stepping state is not updated.");
0109
0110 typeFlags.set(TrackStateFlag::OutlierFlag);
0111 trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
0112 TrackStatePropMask::Filtered);
0113 }
0114 }
0115
0116 return trackStateProxy;
0117 }
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 template <typename propagator_state_t, typename stepper_t, typename traj_t>
0135 auto kalmanHandleNoMeasurement(
0136 propagator_state_t &state, const stepper_t &stepper, const Surface &surface,
0137 traj_t &fittedStates, const std::size_t lastTrackIndex, bool doCovTransport,
0138 const Logger &logger, const bool precedingMeasurementExists,
0139 const FreeToBoundCorrection &freeToBoundCorrection = FreeToBoundCorrection(
0140 false)) -> Result<typename traj_t::TrackStateProxy> {
0141
0142
0143 TrackStatePropMask mask = TrackStatePropMask::Predicted |
0144 TrackStatePropMask::Smoothed |
0145 TrackStatePropMask::Jacobian;
0146 typename traj_t::TrackStateProxy trackStateProxy =
0147 fittedStates.makeTrackState(mask, lastTrackIndex);
0148
0149
0150
0151 {
0152 trackStateProxy.setReferenceSurface(surface.getSharedPtr());
0153
0154 auto res = stepper.boundState(state.stepping, surface, doCovTransport,
0155 freeToBoundCorrection);
0156 if (!res.ok()) {
0157 return res.error();
0158 }
0159 const auto &[boundParams, jacobian, pathLength] = *res;
0160
0161
0162 trackStateProxy.predicted() = boundParams.parameters();
0163 trackStateProxy.predictedCovariance() = state.stepping.cov;
0164
0165 trackStateProxy.jacobian() = jacobian;
0166 trackStateProxy.pathLength() = pathLength;
0167
0168
0169
0170 trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
0171 TrackStatePropMask::Filtered);
0172 }
0173
0174
0175 const bool surfaceHasMaterial = surface.surfaceMaterial() != nullptr;
0176 const bool surfaceIsSensitive =
0177 surface.associatedDetectorElement() != nullptr;
0178 auto typeFlags = trackStateProxy.typeFlags();
0179 typeFlags.set(TrackStateFlag::ParameterFlag);
0180
0181 if (surfaceHasMaterial) {
0182 typeFlags.set(TrackStateFlag::MaterialFlag);
0183 }
0184
0185 if (surfaceIsSensitive && precedingMeasurementExists) {
0186 ACTS_VERBOSE("Detected hole on " << surface.geometryId());
0187
0188 typeFlags.set(TrackStateFlag::HoleFlag);
0189 } else if (surfaceIsSensitive) {
0190 ACTS_VERBOSE("Skip hole (no preceding measurements) on surface "
0191 << surface.geometryId());
0192 } else if (surfaceHasMaterial) {
0193 ACTS_VERBOSE("Detected in-sensitive surface " << surface.geometryId());
0194 }
0195
0196 return trackStateProxy;
0197 }
0198
0199 }