Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve TrackParameterHelpers.hpp #3766

Merged
merged 13 commits into from
Oct 24, 2024
19 changes: 15 additions & 4 deletions Core/include/Acts/EventData/TrackParameterHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Utilities/detail/periodic.hpp"

Expand All @@ -26,8 +25,20 @@ inline BoundVector normalizeBoundParameters(const BoundVector& boundParams) {
return result;
}

/// Add bound parameters and take care of angle periodicity for phi and theta.
/// This is intended for small differences only i.e. KF updates.
///
/// @param lhs The left hand side bound parameters
/// @param rhs The right hand side bound parameters
///
/// @return The sum of the bound parameters
inline BoundVector addBoundParameters(const BoundVector& lhs,
const BoundVector& rhs) {
return normalizeBoundParameters(lhs + rhs);
}

/// Subtract bound parameters and take care of angle periodicity for phi and
/// theta.
/// theta. This is intended for small differences only i.e. KF updates.
///
/// @param lhs The left hand side bound parameters
/// @param rhs The right hand side bound parameters
Expand All @@ -36,8 +47,8 @@ inline BoundVector normalizeBoundParameters(const BoundVector& boundParams) {
inline BoundVector subtractBoundParameters(const BoundVector& lhs,
const BoundVector& rhs) {
BoundVector result = lhs - rhs;
result[eBoundPhi] =
detail::difference_periodic(lhs[eBoundPhi], rhs[eBoundPhi], 2 * M_PI);
result[eBoundPhi] = detail::radian_sym(result[eBoundPhi]);
result[eBoundTheta] = detail::radian_sym(result[eBoundTheta]);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions Tests/UnitTests/Core/EventData/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ add_unittest(MultiTrajectoryHelpers MultiTrajectoryHelpersTests.cpp)
add_unittest(SubspaceHelpers SubspaceHelpersTests.cpp)
add_unittest(SeedEdm SeedEdmTests.cpp)
add_unittest(SpacePointContainerEdm SpacePointContainerEdmTests.cpp)
add_unittest(TrackParameterHelpers TrackParameterHelpersTests.cpp)

add_non_compile_test(MultiTrajectory TrackContainerComplianceTests.cpp)
43 changes: 43 additions & 0 deletions Tests/UnitTests/Core/EventData/TrackParameterHelpersTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include <boost/test/unit_test.hpp>

#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/TrackParameterHelpers.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"

BOOST_AUTO_TEST_SUITE(TrackParameterHelpers)

BOOST_AUTO_TEST_CASE(normalizeBoundParameters) {
CHECK_CLOSE_OR_SMALL(Acts::normalizeBoundParameters({1, 2, 3, 4, 5, 6}),
Acts::BoundVector(1, 2, -0.141593, 2.28319, 5, 6), 1e-3,
1e-3);
}

BOOST_AUTO_TEST_CASE(addBoundParameters) {
CHECK_CLOSE_OR_SMALL(
Acts::addBoundParameters({1, 2, 3, 4, 5, 6}, {0, 0, 0, 0, 0, 0}),
Acts::normalizeBoundParameters({1, 2, 3, 4, 5, 6}), 1e-3, 1e-3);
CHECK_CLOSE_OR_SMALL(
Acts::addBoundParameters({1, 2, 3, 4, 5, 6}, {0, 0, 1, 1, 0, 0}),
Acts::normalizeBoundParameters({1, 2, 4, 5, 5, 6}), 1e-3, 1e-3);
}

BOOST_AUTO_TEST_CASE(subtractBoundParameters) {
CHECK_CLOSE_OR_SMALL(
Acts::subtractBoundParameters({1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6}),
Acts::BoundVector(0, 0, 0, 0, 0, 0), 1e-3, 1e-3);
CHECK_CLOSE_OR_SMALL(
Acts::addBoundParameters(
Acts::subtractBoundParameters({1, 2, 3, 4, 5, 6}, {0, 0, 1, 1, 0, 0}),
{0, 0, 1, 1, 0, 0}),
Acts::normalizeBoundParameters({1, 2, 3, 4, 5, 6}), 1e-3, 1e-3);
}

BOOST_AUTO_TEST_SUITE_END()
Loading