Skip to content

Commit

Permalink
fix multi stepper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Oct 18, 2024
1 parent 9675442 commit 0a02484
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
11 changes: 9 additions & 2 deletions Core/include/Acts/EventData/TrackParameterHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@

namespace Acts {

/// Check if a bound vector is valid
/// Check if a bound vector is valid. This checks the following:
/// - All values are finite
/// - The phi value is in the range [-pi, pi)
/// - The theta value is in the range [0, pi]
/// - The q/p value is non-zero
///
/// @param v The bound vector to check
/// @param epsilon The epsilon to use for the checks
///
/// @return True if the bound vector is valid
bool isBoundVectorValid(const BoundVector& v, double epsilon = 1e-6);

/// Check if a free vector is valid
/// Check if a free vector is valid. This checks the following:
/// - All values are finite
/// - Direction is normalized
/// - The q/p value is non-zero
///
/// @param v The free vector to check
/// @param epsilon The epsilon to use for the checks
Expand Down
2 changes: 1 addition & 1 deletion Core/src/EventData/TrackParameterHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Acts/EventData/TrackParameterHelpers.hpp"

bool Acts::isBoundVectorValid(const BoundVector& v, double epsilon) {
auto pi = std::numbers::pi_v<double>;
constexpr auto pi = std::numbers::pi_v<double>;

bool loc0Valid = std::isfinite(v[eBoundLoc0]);
bool loc1Valid = std::isfinite(v[eBoundLoc1]);
Expand Down
45 changes: 29 additions & 16 deletions Tests/UnitTests/Core/Propagator/MultiStepperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <cstddef>
#include <memory>
#include <optional>
#include <random>
#include <stdexcept>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -124,9 +125,30 @@ auto makeDefaultBoundPars(bool cov = true, std::size_t n = 4,
return c;
};

// note that we are using the default random device
std::mt19937 gen;
std::uniform_real_distribution<> locDis(-10.0, 10.0);
std::uniform_real_distribution<> phiDis(-M_PI, M_PI);
std::uniform_real_distribution<> thetaDis(0, M_PI);
std::uniform_real_distribution<> qOverPDis(-10.0, 10.0);
std::uniform_real_distribution<> timeDis(0.0, 100.0);

for (auto i = 0ul; i < n; ++i) {
cmps.push_back({1. / n, ext_pars ? *ext_pars : BoundVector::Random(),
cov ? Opt{make_random_sym_matrix()} : Opt{}});
BoundVector params = BoundVector::Zero();

if (ext_pars) {
params = *ext_pars;
} else {
params[eBoundLoc0] = locDis(gen);
params[eBoundLoc1] = locDis(gen);
params[eBoundPhi] = phiDis(gen);
params[eBoundTheta] = thetaDis(gen);
params[eBoundQOverP] = qOverPDis(gen);
params[eBoundTime] = timeDis(gen);
}

cmps.push_back(
{1. / n, params, cov ? Opt{make_random_sym_matrix()} : Opt{}});
}

auto surface = Acts::CurvilinearSurface(Vector3::Zero(), Vector3{1., 0., 0.})
Expand Down Expand Up @@ -430,7 +452,8 @@ void test_multi_stepper_surface_status_update() {
std::vector<std::tuple<double, BoundVector, std::optional<BoundSquareMatrix>>>
cmps(2, {0.5, BoundVector::Zero(), std::nullopt});
std::get<BoundVector>(cmps[0])[eBoundTheta] = M_PI_2;
std::get<BoundVector>(cmps[1])[eBoundTheta] = -M_PI_2;
std::get<BoundVector>(cmps[1])[eBoundPhi] = M_PI;
std::get<BoundVector>(cmps[1])[eBoundTheta] = M_PI_2;
std::get<BoundVector>(cmps[0])[eBoundQOverP] = 1.0;
std::get<BoundVector>(cmps[1])[eBoundQOverP] = 1.0;

Expand Down Expand Up @@ -541,7 +564,8 @@ void test_component_bound_state() {
std::vector<std::tuple<double, BoundVector, std::optional<BoundSquareMatrix>>>
cmps(2, {0.5, BoundVector::Zero(), std::nullopt});
std::get<BoundVector>(cmps[0])[eBoundTheta] = M_PI_2;
std::get<BoundVector>(cmps[1])[eBoundTheta] = -M_PI_2;
std::get<BoundVector>(cmps[1])[eBoundPhi] = M_PI;
std::get<BoundVector>(cmps[1])[eBoundTheta] = M_PI_2;
std::get<BoundVector>(cmps[0])[eBoundQOverP] = 1.0;
std::get<BoundVector>(cmps[1])[eBoundQOverP] = 1.0;

Expand Down Expand Up @@ -703,18 +727,7 @@ void test_single_component_interface_function() {
using MultiState = typename multi_stepper_t::State;
using MultiStepper = multi_stepper_t;

std::vector<std::tuple<double, BoundVector, std::optional<BoundSquareMatrix>>>
cmps;
for (int i = 0; i < 4; ++i) {
cmps.push_back({0.25, BoundVector::Random(), BoundSquareMatrix::Random()});
}

auto surface =
Acts::CurvilinearSurface(Vector3::Zero(), Vector3::Ones().normalized())
.planeSurface();

MultiComponentBoundTrackParameters multi_pars(surface, cmps,
particleHypothesis);
MultiComponentBoundTrackParameters multi_pars = makeDefaultBoundPars(true, 4);

MultiState multi_state(geoCtx, magCtx, defaultBField, multi_pars,
defaultStepSize);
Expand Down

0 comments on commit 0a02484

Please sign in to comment.