Skip to content

Commit

Permalink
Merge branch 'main' into int32
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 3, 2024
2 parents f791650 + 1663c02 commit f92a728
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/GridAccessHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class LocalSubspace : public IBoundToGridLocal {
}
};

class BoundCylinderToZPhi final : public IBoundToGridLocal {
class BoundCylinderToZPhi : public IBoundToGridLocal {
public:
double radius = 1.;
double shift = 0.;
Expand Down
39 changes: 24 additions & 15 deletions Core/include/Acts/Utilities/TrackHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,11 @@ calculatePredictedResidual(track_state_proxy_t trackState) {
}

auto subspaceHelper =
trackState.template fixedBoundSubspaceHelper<nMeasurementDim>();
trackState.template projectorSubspaceHelper<nMeasurementDim>();

auto measurement = trackState.calibrated();
auto measurementCovariance = trackState.calibratedCovariance();
auto measurement = trackState.template calibrated<nMeasurementDim>();
auto measurementCovariance =
trackState.template calibratedCovariance<nMeasurementDim>();
MeasurementVector predicted =
subspaceHelper.projectVector(trackState.predicted());
MeasurementMatrix predictedCovariance =
Expand Down Expand Up @@ -553,10 +554,11 @@ calculateFilteredResidual(track_state_proxy_t trackState) {
}

auto subspaceHelper =
trackState.template fixedBoundSubspaceHelper<nMeasurementDim>();
trackState.template projectorSubspaceHelper<nMeasurementDim>();

auto measurement = trackState.calibrated();
auto measurementCovariance = trackState.calibratedCovariance();
auto measurement = trackState.template calibrated<nMeasurementDim>();
auto measurementCovariance =
trackState.template calibratedCovariance<nMeasurementDim>();
MeasurementVector filtered =
subspaceHelper.projectVector(trackState.filtered());
MeasurementMatrix filteredCovariance =
Expand Down Expand Up @@ -589,10 +591,11 @@ calculateSmoothedResidual(track_state_proxy_t trackState) {
}

auto subspaceHelper =
trackState.template fixedBoundSubspaceHelper<nMeasurementDim>();
trackState.template projectorSubspaceHelper<nMeasurementDim>();

auto measurement = trackState.calibrated();
auto measurementCovariance = trackState.calibratedCovariance();
auto measurement = trackState.template calibrated<nMeasurementDim>();
auto measurementCovariance =
trackState.template calibratedCovariance<nMeasurementDim>();
MeasurementVector smoothed =
subspaceHelper.projectVector(trackState.smoothed());
MeasurementMatrix smoothedCovariance =
Expand Down Expand Up @@ -620,11 +623,13 @@ double calculatePredictedChi2(track_state_proxy_t trackState) {

return visit_measurement(
trackState.calibratedSize(),
[&]<std::size_t measdim>(std::integral_constant<std::size_t, measdim>) {
[&]<std::size_t measdim>(
std::integral_constant<std::size_t, measdim>) -> double {
auto [residual, residualCovariance] =
calculatePredictedResidual<measdim>(trackState);

return residual.transpose() * residualCovariance.inverse() * residual;
return (residual.transpose() * residualCovariance.inverse() * residual)
.eval()(0, 0);
});
}

Expand All @@ -643,11 +648,13 @@ double calculateFilteredChi2(track_state_proxy_t trackState) {

return visit_measurement(
trackState.calibratedSize(),
[&]<std::size_t measdim>(std::integral_constant<std::size_t, measdim>) {
[&]<std::size_t measdim>(
std::integral_constant<std::size_t, measdim>) -> double {
auto [residual, residualCovariance] =
calculateFilteredResidual<measdim>(trackState);

return residual.transpose() * residualCovariance.inverse() * residual;
return (residual.transpose() * residualCovariance.inverse() * residual)
.eval()(0, 0);
});
}

Expand All @@ -666,11 +673,13 @@ double calculateSmoothedChi2(track_state_proxy_t trackState) {

return visit_measurement(
trackState.calibratedSize(),
[&]<std::size_t measdim>(std::integral_constant<std::size_t, measdim>) {
[&]<std::size_t measdim>(
std::integral_constant<std::size_t, measdim>) -> double {
auto [residual, residualCovariance] =
calculateSmoothedResidual<measdim>(trackState);

return residual.transpose() * residualCovariance.inverse() * residual;
return (residual.transpose() * residualCovariance.inverse() * residual)
.eval()(0, 0);
});
}

Expand Down
5 changes: 5 additions & 0 deletions Plugins/Json/src/GridJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ nlohmann::json Acts::GridAccessJsonConverter::toJson(
jBoundToGridLocal["shift"] = boundCylinderToZPhi->shift;
}

if (jBoundToGridLocal.empty()) {
throw std::invalid_argument(
"GridAccessJsonConverter: boundToGridLocal type not supported.");
}

return jBoundToGridLocal;
}

Expand Down
74 changes: 71 additions & 3 deletions Tests/UnitTests/Core/Utilities/TrackHelpersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

#include <boost/test/unit_test.hpp>

#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/TrackContainer.hpp"
#include "Acts/EventData/TrackStateType.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Utilities/TrackHelpers.hpp"

#include <memory>
#include <span>

namespace Acts::Test {

namespace {
Expand All @@ -35,6 +34,33 @@ auto createTestTrack(TrackContainer& tc, const FlagsPerState& flagsPerState) {
return t;
}

template <typename TrackContainer>
auto createTestTrackState(TrackContainer& tc) {
auto t = tc.makeTrack();

auto ts = t.appendTrackState();

ts.allocateCalibrated(Vector2::Zero(), SquareMatrix2::Identity());
ts.setProjectorSubspaceIndices(std::array{eBoundLoc0, eBoundLoc1});

ts.predicted() = BoundVector::Zero();
ts.predicted()[eBoundLoc0] = 1.;
ts.predicted()[eBoundLoc1] = 1.;
ts.predictedCovariance() = BoundMatrix::Identity() * 1.;

ts.filtered() = BoundVector::Zero();
ts.filtered()[eBoundLoc0] = 0.5;
ts.filtered()[eBoundLoc1] = 0.5;
ts.filteredCovariance() = BoundMatrix::Identity() * 0.5;

ts.smoothed() = BoundVector::Zero();
ts.smoothed()[eBoundLoc0] = 0.1;
ts.smoothed()[eBoundLoc1] = 0.1;
ts.smoothedCovariance() = BoundMatrix::Identity() * 0.1;

return ts;
}

} // namespace

BOOST_AUTO_TEST_SUITE(Utilities)
Expand Down Expand Up @@ -106,6 +132,48 @@ BOOST_AUTO_TEST_CASE(TrimTrack) {
BOOST_CHECK_EQUAL(t.nSharedHits(), 1);
}

BOOST_AUTO_TEST_CASE(CalculatePredictedChi2) {
TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
auto ts = createTestTrackState(tc);

// reference found by running the code
BOOST_CHECK_CLOSE(calculatePredictedChi2(ts), 1., 1e-6);
}

BOOST_AUTO_TEST_CASE(CalculateFilteredChi2) {
TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
auto ts = createTestTrackState(tc);

// reference found by running the code
BOOST_CHECK_CLOSE(calculateFilteredChi2(ts), 1. / 3., 1e-6);
}

BOOST_AUTO_TEST_CASE(CalculateSmoothedChi2) {
TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
auto ts = createTestTrackState(tc);

// reference found by running the code
BOOST_CHECK_CLOSE(calculateSmoothedChi2(ts), 1. / 55., 1e-6);
}

BOOST_AUTO_TEST_CASE(CalculateUnbiasedParametersCovariance) {
TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
auto ts = createTestTrackState(tc);

auto [params, cov] = calculateUnbiasedParametersCovariance(ts);

// reference found by running the code
BoundVector refParams = BoundVector::Zero();
refParams[eBoundLoc0] = 1. / 9.;
refParams[eBoundLoc1] = 1. / 9.;
BoundMatrix refCov = BoundMatrix::Identity() * 0.1;
refCov(eBoundLoc0, eBoundLoc0) = 1. / 9.;
refCov(eBoundLoc1, eBoundLoc1) = 1. / 9.;

CHECK_CLOSE_ABS(params, refParams, 1e-6);
CHECK_CLOSE_ABS(cov, refCov, 1e-6);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace Acts::Test

0 comments on commit f92a728

Please sign in to comment.