Skip to content

Commit

Permalink
refactor: Write smoothed states in GX2F (acts-project#3584)
Browse files Browse the repository at this point in the history
The global chi2 fitter should write smoothed states like the other fitters since the states will contain information about previous and following measurements.

Apart from that I explicitly bound I renamed the free function `updateCovariancePredicted ` to `updateGx2fCovariance` because it is too generic for the public `Acts` namespace and bound the implementation explicitly to the namespace to avoid linker errors while renaming.
  • Loading branch information
andiwand authored Sep 3, 2024
1 parent c0220ee commit c3cbc93
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
52 changes: 26 additions & 26 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ namespace Acts::Experimental {
namespace Gx2fConstants {
constexpr std::string_view gx2fnUpdateColumn = "Gx2fnUpdateColumn";

// Mask for the track states. We don't need Smoothed and Filtered
constexpr TrackStatePropMask trackStateMask = TrackStatePropMask::Predicted |
// Mask for the track states. We don't need Predicted and Filtered
constexpr TrackStatePropMask trackStateMask = TrackStatePropMask::Smoothed |
TrackStatePropMask::Jacobian |
TrackStatePropMask::Calibrated;

Expand Down Expand Up @@ -343,7 +343,7 @@ void addMeasurementToGx2fSums(Eigen::MatrixXd& aMatrixExtended,
extendedJacobian.block<eBoundSize, 2>(0, deltaPosition) = jacPhiTheta;
}

const BoundVector predicted = trackState.predicted();
const BoundVector predicted = trackState.smoothed();

const ActsVector<kMeasDim> measurement =
trackState.template calibrated<kMeasDim>();
Expand Down Expand Up @@ -431,7 +431,7 @@ void addMaterialToGx2fSums(
"No scattering angles found for material surface.");
}

const ActsScalar sinThetaLoc = std::sin(trackState.predicted()[eBoundTheta]);
const ActsScalar sinThetaLoc = std::sin(trackState.smoothed()[eBoundTheta]);

// The position, where we need to insert the values in aMatrix and bVector
const std::size_t deltaPosition = eBoundSize + 2 * nMaterialsHandled;
Expand Down Expand Up @@ -497,9 +497,9 @@ void addMaterialToGx2fSums(
/// @param ndfSystem The number of degrees of freedom, determining the size of meaning full block
///
/// @return deltaParams The calculated delta parameters.
void updateCovariancePredicted(BoundMatrix& fullCovariancePredicted,
Eigen::MatrixXd& aMatrixExtended,
const std::size_t ndfSystem);
void updateGx2fCovarianceParams(BoundMatrix& fullCovariancePredicted,
Eigen::MatrixXd& aMatrixExtended,
const std::size_t ndfSystem);

/// Global Chi Square fitter (GX2F) implementation.
///
Expand Down Expand Up @@ -736,8 +736,8 @@ class Gx2Fitter {
}

// Fill the track state
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;
trackStateProxy.smoothed() = boundParams.parameters();
trackStateProxy.smoothedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;
Expand All @@ -746,13 +746,13 @@ class Gx2Fitter {
stepper.update(state.stepping,
transformBoundToFreeParameters(
trackStateProxy.referenceSurface(),
state.geoContext, trackStateProxy.predicted()),
trackStateProxy.predicted(),
trackStateProxy.predictedCovariance(), *surface);
state.geoContext, trackStateProxy.smoothed()),
trackStateProxy.smoothed(),
trackStateProxy.smoothedCovariance(), *surface);
}
}

// We have predicted parameters, so calibrate the uncalibrated input
// We have smoothed parameters, so calibrate the uncalibrated input
// measurement
extensions.calibrator(state.geoContext, *calibrationContext,
sourcelink_it->second, trackStateProxy);
Expand Down Expand Up @@ -837,18 +837,18 @@ class Gx2Fitter {
ACTS_VERBOSE(" boundParams after the update:\n" << boundParams);

// Fill the track state
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;
trackStateProxy.smoothed() = boundParams.parameters();
trackStateProxy.smoothedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;

stepper.update(state.stepping,
transformBoundToFreeParameters(
trackStateProxy.referenceSurface(),
state.geoContext, trackStateProxy.predicted()),
trackStateProxy.predicted(),
trackStateProxy.predictedCovariance(), *surface);
state.geoContext, trackStateProxy.smoothed()),
trackStateProxy.smoothed(),
trackStateProxy.smoothedCovariance(), *surface);
}

// Get and set the type flags
Expand Down Expand Up @@ -921,8 +921,8 @@ class Gx2Fitter {
const auto& [boundParams, jacobian, pathLength] = *res;

// Fill the track state
trackStateProxy.predicted() = boundParams.parameters();
trackStateProxy.predictedCovariance() = state.stepping.cov;
trackStateProxy.smoothed() = boundParams.parameters();
trackStateProxy.smoothedCovariance() = state.stepping.cov;

trackStateProxy.jacobian() = jacobian;
trackStateProxy.pathLength() = pathLength;
Expand Down Expand Up @@ -1334,16 +1334,16 @@ class Gx2Fitter {
ACTS_INFO("Abort with relChi2changeCutOff after "
<< nUpdate + 1 << "/" << gx2fOptions.nUpdateMax
<< " iterations.");
updateCovariancePredicted(fullCovariancePredicted, aMatrixExtended,
ndfSystem);
updateGx2fCovarianceParams(fullCovariancePredicted, aMatrixExtended,
ndfSystem);
break;
}

if (chi2sum > oldChi2sum + 1e-5) {
ACTS_DEBUG("chi2 not converging monotonically");

updateCovariancePredicted(fullCovariancePredicted, aMatrixExtended,
ndfSystem);
updateGx2fCovarianceParams(fullCovariancePredicted, aMatrixExtended,
ndfSystem);
break;
}

Expand All @@ -1361,8 +1361,8 @@ class Gx2Fitter {
return Experimental::GlobalChiSquareFitterError::DidNotConverge;
}

updateCovariancePredicted(fullCovariancePredicted, aMatrixExtended,
ndfSystem);
updateGx2fCovarianceParams(fullCovariancePredicted, aMatrixExtended,
ndfSystem);
break;
}

Expand Down
12 changes: 4 additions & 8 deletions Core/src/TrackFitting/GlobalChiSquareFitter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2023-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,11 +10,9 @@

#include "Acts/Definitions/TrackParametrization.hpp"

namespace Acts::Experimental {

void updateCovariancePredicted(BoundMatrix& fullCovariancePredicted,
Eigen::MatrixXd& aMatrixExtended,
const std::size_t ndfSystem) {
void Acts::Experimental::updateGx2fCovarianceParams(
BoundMatrix& fullCovariancePredicted, Eigen::MatrixXd& aMatrixExtended,
const std::size_t ndfSystem) {
// make invertible
for (int i = 0; i < aMatrixExtended.rows(); ++i) {
if (aMatrixExtended(i, i) == 0.) {
Expand All @@ -29,5 +27,3 @@ void updateCovariancePredicted(BoundMatrix& fullCovariancePredicted,

return;
}

} // namespace Acts::Experimental
3 changes: 2 additions & 1 deletion Examples/Io/Root/src/RootTrackStatesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ ProcessCode RootTrackStatesWriter::writeT(const AlgorithmContext& ctx,
if (ipar == eSmoothed && state.hasSmoothed()) {
return std::make_pair(state.smoothed(), state.smoothedCovariance());
}
if (ipar == eUnbiased && state.hasSmoothed() && state.hasProjector()) {
if (ipar == eUnbiased && state.hasSmoothed() && state.hasProjector() &&
state.hasCalibrated()) {
// calculate the unbiased track parameters (i.e. fitted track
// parameters with this measurement removed) using Eq.(12a)-Eq.(12c)
// of NIMA 262, 444 (1987)
Expand Down

0 comments on commit c3cbc93

Please sign in to comment.