Skip to content

Commit

Permalink
change concept
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Oct 11, 2023
1 parent f8012c2 commit 027fd9f
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 146 deletions.
46 changes: 38 additions & 8 deletions Core/include/Acts/TrackFitting/KalmanFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "Acts/Propagator/StandardAborters.hpp"
#include "Acts/Propagator/detail/PointwiseMaterialInteraction.hpp"
#include "Acts/TrackFitting/KalmanFitterError.hpp"
#include "Acts/TrackFitting/detail/FitterHelpers.hpp"
#include "Acts/TrackFitting/detail/KalmanUpdateHelpers.hpp"
#include "Acts/TrackFitting/detail/VoidFitterComponents.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"
Expand Down Expand Up @@ -717,14 +716,45 @@ class KalmanFitter {
materialInteractor(surface, state, stepper, navigator,
MaterialUpdateStage::PreUpdate);

auto trackStateProxyRes = detail::getTrackStateProxy(
state, stepper, *surface, *result.fittedStates,
Acts::MultiTrajectoryTraits::kInvalid, false, logger(),
freeToBoundCorrection, TrackStatePropMask::All);
if (!trackStateProxyRes.ok()) {
return trackStateProxyRes.error();
auto fittedStates = *result.fittedStates;

// Add a <mask> TrackState entry multi trajectory. This allocates
// storage for all components, which we will set later.
TrackStatePropMask mask = TrackStatePropMask::All;
size_t currentTrackIndex = fittedStates.addTrackState(
mask, Acts::MultiTrajectoryTraits::kInvalid);

// now get track state proxy back
typename traj_t::TrackStateProxy trackStateProxy =
fittedStates.getTrackState(currentTrackIndex);

// Set the trackStateProxy components with the state from the ongoing
// propagation
{
trackStateProxy.setReferenceSurface(surface->getSharedPtr());
// Bind the transported state to the current surface
auto res = stepper.boundState(state.stepping, *surface, false,
freeToBoundCorrection);
if (!res.ok()) {
// ACTS_ERROR("Propagate to surface " <<
// surface.geometryId()
// << " failed: " <<
// res.error());
return res.error();
}
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.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);
}
auto& trackStateProxy = *trackStateProxyRes;

// We have predicted parameters, so calibrate the uncalibrated input
// measurement
extensions.calibrator(state.geoContext, *calibrationContext,
Expand Down
93 changes: 0 additions & 93 deletions Core/include/Acts/TrackFitting/detail/FitterHelpers.hpp

This file was deleted.

147 changes: 102 additions & 45 deletions Core/include/Acts/TrackFitting/detail/KalmanUpdateHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/TrackFitting/detail/FitterHelpers.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"
#include "Acts/Utilities/Result.hpp"

Expand Down Expand Up @@ -43,47 +42,78 @@ auto kalmanHandleMeasurement(
const size_t lastTrackIndex, bool doCovTransport, const Logger &logger,
const FreeToBoundCorrection &freeToBoundCorrection = FreeToBoundCorrection(
false)) -> Result<typename traj_t::TrackStateProxy> {
auto trackStateProxyRes = getTrackStateProxy(
state, stepper, surface, fittedStates, lastTrackIndex, doCovTransport,
logger, freeToBoundCorrection, TrackStatePropMask::All);
if (!trackStateProxyRes.ok()) {
return trackStateProxyRes.error();
// Add a <mask> TrackState entry multi trajectory. This allocates storage for
// all components, which we will set later.
TrackStatePropMask mask = TrackStatePropMask::All;
size_t currentTrackIndex = fittedStates.addTrackState(mask, lastTrackIndex);

// now get track state proxy back
typename traj_t::TrackStateProxy trackStateProxy =
fittedStates.getTrackState(currentTrackIndex);

// Set the trackStateProxy components with the state from the ongoing
// propagation
{
trackStateProxy.setReferenceSurface(surface.getSharedPtr());
// Bind the transported state to the current surface
auto res = stepper.boundState(state.stepping, surface, doCovTransport,
freeToBoundCorrection);
if (!res.ok()) {
ACTS_ERROR("Propagate to surface " << surface.geometryId()
<< " failed: " << res.error());
return res.error();
}
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.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);
}
auto &trackStateProxy = *trackStateProxyRes;

// We have predicted parameters, so calibrate the uncalibrated input
// measurement
extensions.calibrator(state.geoContext, calibrationContext, source_link,
trackStateProxy);

// Get and set the type flags
auto typeFlags = trackStateProxy.typeFlags();
typeFlags.set(TrackStateFlag::ParameterFlag);
if (surface.surfaceMaterial() != nullptr) {
typeFlags.set(TrackStateFlag::MaterialFlag);
}
{
auto typeFlags = trackStateProxy.typeFlags();
typeFlags.set(TrackStateFlag::ParameterFlag);
if (surface.surfaceMaterial() != nullptr) {
typeFlags.set(TrackStateFlag::MaterialFlag);
}

// Check if the state is an outlier.
// If not, run Kalman update, tag it as a
// measurement and update the stepping state. Otherwise, just tag it as
// an outlier
if (not extensions.outlierFinder(trackStateProxy)) {
// Run Kalman update
auto updateRes = extensions.updater(state.geoContext, trackStateProxy,
state.options.direction, logger);
if (!updateRes.ok()) {
ACTS_ERROR("Update step failed: " << updateRes.error());
return updateRes.error();
// Check if the state is an outlier.
// If not:
// - run Kalman update
// - tag it as a measurement
// - update the stepping state.
// Else, just tag it as an outlier
if (not extensions.outlierFinder(trackStateProxy)) {
// Run Kalman update
auto updateRes = extensions.updater(state.geoContext, trackStateProxy,
state.options.direction, logger);
if (!updateRes.ok()) {
ACTS_ERROR("Update step failed: " << updateRes.error());
return updateRes.error();
}
// Set the measurement type flag
typeFlags.set(TrackStateFlag::MeasurementFlag);
} else {
ACTS_VERBOSE(
"Filtering step successful. But measurement is determined "
"to be an outlier. Stepping state is not updated.")
// Set the outlier type flag
typeFlags.set(TrackStateFlag::OutlierFlag);
trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
TrackStatePropMask::Filtered);
}
// Set the measurement type flag
typeFlags.set(TrackStateFlag::MeasurementFlag);
} else {
ACTS_VERBOSE(
"Filtering step successful. But measurement is determined "
"to be an outlier. Stepping state is not updated.")
// Set the outlier type flag
typeFlags.set(TrackStateFlag::OutlierFlag);
trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
TrackStatePropMask::Filtered);
}

return trackStateProxy;
Expand Down Expand Up @@ -111,14 +141,46 @@ auto kalmanHandleNoMeasurement(
// No source links on surface, add either hole or passive material
// TrackState entry multi trajectory. No storage allocation for
// uncalibrated/calibrated measurement and filtered parameter
auto trackStateProxyRes = getTrackStateProxy(
state, stepper, surface, fittedStates, lastTrackIndex, doCovTransport,
logger, freeToBoundCorrection,
~(TrackStatePropMask::Calibrated | TrackStatePropMask::Filtered));
if (!trackStateProxyRes.ok()) {
return trackStateProxyRes.error();

// Add a <mask> TrackState entry multi trajectory. This allocates storage for
// all components, which we will set later.
TrackStatePropMask mask =
~(TrackStatePropMask::Calibrated | TrackStatePropMask::Filtered);
size_t currentTrackIndex = fittedStates.addTrackState(mask, lastTrackIndex);

// now get track state proxy back
typename traj_t::TrackStateProxy trackStateProxy =
fittedStates.getTrackState(currentTrackIndex);

// Set the trackStateProxy components with the state from the ongoing
// propagation
{
trackStateProxy.setReferenceSurface(surface.getSharedPtr());
// Bind the transported state to the current surface
auto res = stepper.boundState(state.stepping, surface, doCovTransport,
freeToBoundCorrection);
if (!res.ok()) {
ACTS_ERROR("Propagate to surface " << surface.geometryId()
<< " failed: " << res.error());
return res.error();
}
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.jacobian() = std::move(jacobian);
trackStateProxy.pathLength() = std::move(pathLength);

// Set the filtered parameter index to be the same with predicted
// parameter
trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
TrackStatePropMask::Filtered);
}
auto &trackStateProxy = *trackStateProxyRes;

// Set the track state flags
auto typeFlags = trackStateProxy.typeFlags();
Expand All @@ -134,11 +196,6 @@ auto kalmanHandleNoMeasurement(
ACTS_VERBOSE("Detected in-sensitive surface " << surface.geometryId());
}

// Set the filtered parameter index to be the same with predicted
// parameter
trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
TrackStatePropMask::Filtered);

return trackStateProxy;
}

Expand Down

0 comments on commit 027fd9f

Please sign in to comment.