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

test: Use deterministic RNG for tests #2694

Merged
merged 10 commits into from
Nov 20, 2023
1 change: 0 additions & 1 deletion Core/include/Acts/Surfaces/TrapezoidBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace Acts {
/// @image html TrapezoidBounds.gif
///
/// @todo can be speed optimized by calculating kappa/delta and caching it

class TrapezoidBounds : public PlanarBounds {
public:
enum BoundValues {
Expand Down
19 changes: 13 additions & 6 deletions Core/src/Surfaces/TrapezoidBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ bool Acts::TrapezoidBounds::inside(const Acts::Vector2& lposition,
double tolX = bcheck.tolerance()[eBoundLoc0];
double tolY = bcheck.tolerance()[eBoundLoc1];

if (std::abs(y) - hlY > tolY) {
// outside y range
// check outside x range + tolerance
if (std::abs(x) - std::max(hlXnY, hlXpY) > tolX) {
return false;
}

if (std::abs(x) - std::max(hlXnY, hlXpY) > tolX) {
// outside x range
// check outside y range + tolerance
if (std::abs(y) - hlY > tolY) {
return false;
}

if (std::abs(x) - std::min(hlXnY, hlXpY) <= tolX) {
// inside x range
// check inside x range + tolerance, inside y range
if ((std::abs(x) - std::min(hlXnY, hlXpY) <= tolX) &&
(std::abs(y) - hlY <= 0)) {
return true;
}

// check inside x range, inside y range + tolerance
if ((std::abs(x) - std::min(hlXnY, hlXpY) <= 0) &&
(std::abs(y) - hlY <= tolY)) {
return true;
}
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/Benchmarks/SurfaceIntersectionBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Tests/CommonHelpers/BenchmarkTools.hpp"

#include <cmath>
#include <random>

namespace bdata = boost::unit_test::data;
namespace tt = boost::test_tools;
Expand Down Expand Up @@ -90,9 +91,9 @@ MicroBenchmarkResult intersectionTest(const surface_t& surface, double phi,
BOOST_DATA_TEST_CASE(
benchmark_surface_intersections,
bdata::random(
(bdata::seed = 21,
(bdata::engine = std::mt19937(), bdata::seed = 21,
bdata::distribution = std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::seed = 22,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
bdata::distribution =
std::uniform_real_distribution<>(-0.3, 0.3))) ^
bdata::xrange(ntests),
Expand Down
6 changes: 3 additions & 3 deletions Tests/IntegrationTests/InterpolatedSolenoidBFieldTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ StreamWrapper valid(std::ofstream("magfield_lookup.csv"));
const int ntests = 10000;
BOOST_DATA_TEST_CASE(
solenoid_interpolated_bfield_comparison,
bdata::random((bdata::seed = 1, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(
1.5 * (-L / 2.), 1.5 * L / 2.))) ^
bdata::random((bdata::seed = 2, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(0, R * 1.5))) ^
bdata::random((bdata::seed = 3, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::xrange(ntests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ GeometryContext tgContext = GeometryContext();
/// guaranteed to be in on the readout/counter plane
BOOST_DATA_TEST_CASE(
readout_counter_test,
bdata::random((bdata::seed = 0,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 0,
bdata::distribution = std::uniform_real_distribution<>(
-halfX + sguardX, halfX - sguardX))) ^
bdata::random((bdata::seed = 1,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(
-halfX + sguardX, halfX - sguardX))) ^
bdata::random((bdata::seed = 2,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-halfY, halfY))) ^
bdata::random((bdata::seed = 3,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution = std::uniform_int_distribution<>(
-static_cast<int>(halfY),
static_cast<int>(halfY)))) ^
Expand Down
10 changes: 5 additions & 5 deletions Tests/UnitTests/Core/Geometry/BVHDataTestCase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ auto tg = grid.trackingGeometry;

BOOST_DATA_TEST_CASE(
bvhnavigation_test,
bdata::random((bdata::seed = 7, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 7,
bdata::distribution = std::uniform_real_distribution<>(-5,
5))) ^
bdata::random((bdata::seed = 2, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::seed = 3, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-100, 100))) ^
bdata::random((bdata::seed = 4, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<>(-100, 100))) ^
bdata::random((bdata::seed = 5, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<>(-100, 100))) ^
bdata::xrange(NTESTS),
Expand Down
28 changes: 22 additions & 6 deletions Tests/UnitTests/Core/Geometry/CylinderVolumeBoundsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,28 @@ BOOST_AUTO_TEST_CASE(CylinderVolumeBoundsAccess) {
}

/// Unit test for testing the orientedSurfaces() function
BOOST_DATA_TEST_CASE(CylinderVolumeBoundsOrientedSurfaces,
bdata::random(-M_PI, M_PI) ^ bdata::random(-M_PI, M_PI) ^
bdata::random(-M_PI, M_PI) ^ bdata::random(-10., 10.) ^
bdata::random(-10., 10.) ^ bdata::random(-10., 10.) ^
bdata::xrange(100),
alpha, beta, gamma, posX, posY, posZ, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBoundsOrientedSurfaces,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<>(-10., 10.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<>(-10., 10.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution =
std::uniform_real_distribution<>(-10., 10.))) ^
bdata::xrange(100),
alpha, beta, gamma, posX, posY, posZ, index) {
(void)index;

// Create a test context
Expand Down
87 changes: 67 additions & 20 deletions Tests/UnitTests/Core/Geometry/CylinderVolumeBuilderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ namespace Acts {
namespace Test {

/// Unit test for testing the wraps() function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_wraps,
bdata::random(-11., -15.) ^ bdata::random(11., 15.) ^
bdata::random(-10., 10.) ^ bdata::random(0., 4.) ^
bdata::random(11., 15.) ^ bdata::random(10., 15.) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_wraps,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(-11., -15.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution = std::uniform_real_distribution<>(11., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-10., 10.))) ^
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution = std::uniform_real_distribution<>(0., 4.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution = std::uniform_real_distribution<>(11., 15.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution = std::uniform_real_distribution<>(10., 15.))) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
(void)index;
// inner volume
VolumeConfig innerConfig;
Expand Down Expand Up @@ -97,12 +113,28 @@ BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_wraps,

/// Unit test for testing the contains(), containsInR() and containsInZ()
/// function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_containes,
bdata::random(-11., -15.) ^ bdata::random(11., 15.) ^
bdata::random(-10., 10.) ^ bdata::random(0., 4.) ^
bdata::random(10., 15.) ^ bdata::random(10., 15.) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_containes,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(-11., -15.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution = std::uniform_real_distribution<>(11., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-10., 10.))) ^
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution = std::uniform_real_distribution<>(0., 4.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution = std::uniform_real_distribution<>(10., 15.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution = std::uniform_real_distribution<>(10., 15.))) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
(void)index;
// inner volume
VolumeConfig innerConfig;
Expand Down Expand Up @@ -184,10 +216,16 @@ BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_containes,

/// Unit test for testing the coverlapsInR()
/// function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_overlapsInR,
bdata::random(0., 4.) ^ bdata::random(11., 15.) ^
bdata::xrange(100),
inner, outer, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_overlapsInR,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(0., 4.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution = std::uniform_real_distribution<>(11., 15.))) ^
bdata::xrange(100),
inner, outer, index) {
(void)index;
// reference volume
VolumeConfig Config0;
Expand Down Expand Up @@ -246,10 +284,19 @@ BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_overlapsInR,

/// Unit test for testing the coverlapsInZ()
/// function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_overlapsInZ,
bdata::random(-11., -15.) ^ bdata::random(11., 15.) ^
bdata::random(0., 4.) ^ bdata::xrange(100),
left, right, inner, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_overlapsInZ,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(-11., -15.))) ^
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution = std::uniform_real_distribution<>(11., 15.))) ^
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution = std::uniform_real_distribution<>(0., 4.))) ^
bdata::xrange(100),
left, right, inner, index) {
(void)index;
// inner volume
VolumeConfig Config0;
Expand Down
56 changes: 44 additions & 12 deletions Tests/UnitTests/Core/MagneticField/ConstantBFieldTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,28 @@ MagneticFieldContext mfContext = MagneticFieldContext();
/// -# ConstantBField::ConstantBField(Vector3 B)
/// -# ConstantBField::getField(const double* xyz, double* B) const
/// -# ConstantBField::getField(const Vector3& pos) const
BOOST_DATA_TEST_CASE(ConstantBField_components,
bdata::random(-2_T, 2_T) ^ bdata::random(-1_T, 4_T) ^
bdata::random(0_T, 10_T) ^ bdata::random(-10_m, 10_m) ^
bdata::random(-10_m, 10_m) ^
bdata::random(-10_m, 10_m) ^ bdata::xrange(10),
x, y, z, bx, by, bz, index) {
BOOST_DATA_TEST_CASE(
ConstantBField_components,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(-2_T, 2_T))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-1_T, 4_T))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(0_T, 10_T))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<>(-10_m, 10_m))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<>(-10_m, 10_m))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution =
std::uniform_real_distribution<>(-10_m, 10_m))) ^
bdata::xrange(10),
x, y, z, bx, by, bz, index) {
(void)index;
const Vector3 Btrue(bx, by, bz);
const Vector3 pos(x, y, z);
Expand All @@ -63,12 +79,28 @@ BOOST_DATA_TEST_CASE(ConstantBField_components,
/// -# ConstantBField::setField(const Vector3& B)
/// -# ConstantBField::getField(const double* xyz, double* B) const
/// -# ConstantBField::getField(const Vector3& pos) const
BOOST_DATA_TEST_CASE(ConstantBField_update,
bdata::random(-2_T, 2_T) ^ bdata::random(-1_T, 4_T) ^
bdata::random(0_T, 10_T) ^ bdata::random(-10_m, 10_m) ^
bdata::random(-10_m, 10_m) ^
bdata::random(-10_m, 10_m) ^ bdata::xrange(10),
x, y, z, bx, by, bz, index) {
BOOST_DATA_TEST_CASE(
ConstantBField_update,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(-2_T, 2_T))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-1_T, 4_T))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(0_T, 10_T))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<>(-10_m, 10_m))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<>(-10_m, 10_m))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution =
std::uniform_real_distribution<>(-10_m, 10_m))) ^
bdata::xrange(10),
x, y, z, bx, by, bz, index) {
(void)index;

ConstantBField BField{Vector3{0, 0, 0}};
Expand Down
10 changes: 5 additions & 5 deletions Tests/UnitTests/Core/Propagator/DirectNavigatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ void runTest(const rpropagator_t& rprop, const dpropagator_t& dprop, double pT,
// - this tests the collection of surfaces
BOOST_DATA_TEST_CASE(
test_direct_navigator,
bdata::random((bdata::seed = 20,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 20,
bdata::distribution =
std::uniform_real_distribution<>(0.15_GeV, 10_GeV))) ^
bdata::random((bdata::seed = 21,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 21,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::seed = 22,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
bdata::distribution =
std::uniform_real_distribution<>(1.0, M_PI - 1.0))) ^
bdata::random(
(bdata::seed = 23,
(bdata::engine = std::mt19937(), bdata::seed = 23,
bdata::distribution = std::uniform_int_distribution<>(0, 1))) ^
bdata::random(
(bdata::seed = 24,
(bdata::engine = std::mt19937(), bdata::seed = 24,
bdata::distribution = std::uniform_int_distribution<>(0, 100))) ^
bdata::xrange(ntests),
pT, phi, theta, charge, time, index) {
Expand Down
Loading
Loading