Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Oct 26, 2023
1 parent 07e1851 commit 08b8c77
Showing 1 changed file with 102 additions and 7 deletions.
109 changes: 102 additions & 7 deletions Tests/UnitTests/Core/TrackFitting/Gx2fTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Acts::CurvilinearTrackParameters makeParameters(
const ActsScalar x = 0.0_m, const ActsScalar y = 0.0_m,
const ActsScalar z = 0.0_m, const ActsScalar w = 42_ns,
const ActsScalar phi = 0_degree, const ActsScalar theta = 90_degree,
const ActsScalar p = 1_GeV, const ActsScalar q = 1_e) {
const ActsScalar p = 2_GeV, const ActsScalar q = 1_e) {
// create covariance matrix from reasonable standard deviations
Acts::BoundVector stddev;
stddev[Acts::eBoundLoc0] = 100_um;
Expand Down Expand Up @@ -100,7 +100,7 @@ std::shared_ptr<const TrackingGeometry> makeToyDetector(
/// Shape of the surface
// Boundaries of the surfaces
cfg.rBounds =
std::make_shared<const RectangleBounds>(RectangleBounds(0.5_m, 0.5_m));
std::make_shared<const RectangleBounds>(RectangleBounds(1_m, 1_m));

// Material of the surfaces
MaterialSlab matProp(makeBeryllium(), 0.5_mm);
Expand Down Expand Up @@ -132,14 +132,14 @@ std::shared_ptr<const TrackingGeometry> makeToyDetector(

// Inner Volume - Build volume configuration
CuboidVolumeBuilder::VolumeConfig volumeConfig;
volumeConfig.length = {(nSurfaces + 1) * 1_m, 1_m, 1_m};
volumeConfig.length = {(nSurfaces + 1) * 1_m, 2_m, 2_m};
volumeConfig.position = {volumeConfig.length.x() / 2, 0., 0.};
volumeConfig.layerCfg = layerConfig;
volumeConfig.name = "Test volume";

// Outer volume - Build TrackingGeometry configuration
CuboidVolumeBuilder::Config config;
config.length = {(nSurfaces + 1) * 1_m, 1_m, 1_m};
config.length = {(nSurfaces + 1) * 1_m, 2_m, 2_m};
config.position = {volumeConfig.length.x() / 2, 0., 0.};
config.volumeCfg = {volumeConfig};

Expand Down Expand Up @@ -198,6 +198,7 @@ BOOST_AUTO_TEST_CASE(NoFit) {
simPropagator, geoCtx, magCtx, parametersMeasurements, resolutions, rng);
auto sourceLinks = prepareSourceLinks(measurements.sourceLinks);

// Reuse the SimPropagator, since we will not actually use it
using Gx2Fitter =
Experimental::Gx2Fitter<SimPropagator, VectorMultiTrajectory>;
Gx2Fitter fitter(simPropagator, gx2fLogger->clone());
Expand All @@ -213,7 +214,7 @@ BOOST_AUTO_TEST_CASE(NoFit) {

Experimental::Gx2FitterOptions gx2fOptions(
geoCtx, magCtx, calCtx, extensions, PropagatorPlainOptions(), rSurface,
false, false, FreeToBoundCorrection(false), 0);
false, false, FreeToBoundCorrection(false), 0, true);

Acts::TrackContainer tracks{Acts::VectorTrackContainer{},
Acts::VectorMultiTrajectory{}};
Expand Down Expand Up @@ -300,7 +301,7 @@ BOOST_AUTO_TEST_CASE(Fit5Iterations) {

const Experimental::Gx2FitterOptions gx2fOptions(
tgContext, mfContext, calContext, extensions, PropagatorPlainOptions(),
rSurface, false, false, FreeToBoundCorrection(false), 5);
rSurface, false, false, FreeToBoundCorrection(false), 5, true);

Acts::TrackContainer tracks{Acts::VectorTrackContainer{},
Acts::VectorMultiTrajectory{}};
Expand Down Expand Up @@ -403,7 +404,7 @@ BOOST_AUTO_TEST_CASE(MixedDetector) {

const Experimental::Gx2FitterOptions gx2fOptions(
tgContext, mfContext, calContext, extensions, PropagatorPlainOptions(),
rSurface, false, false, FreeToBoundCorrection(false), 5);
rSurface, false, false, FreeToBoundCorrection(false), 5, true);

Acts::TrackContainer tracks{Acts::VectorTrackContainer{},
Acts::VectorMultiTrajectory{}};
Expand Down Expand Up @@ -432,6 +433,100 @@ BOOST_AUTO_TEST_CASE(MixedDetector) {
ACTS_INFO("*** Test: MixedDetector -- Finish");
}

// This test checks if we can fit QOverP, when a magnetic field is introduced
BOOST_AUTO_TEST_CASE(FitWithBfield) {
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("Gx2fTests", logLevel));
ACTS_INFO("*** Test: FitWithBfield -- Start");

// Create a test context
GeometryContext tgContext = GeometryContext();

Detector detector;
const size_t nSurfaces = 5;
detector.geometry = makeToyDetector(tgContext, nSurfaces);

ACTS_DEBUG("Go to propagator");

auto parametersMeasurements = makeParameters();
auto startParametersFit = makeParameters(7_mm, 11_mm, 15_mm, 42_ns, 10_degree,
80_degree, 1_GeV, 1_e);

// Context objects
Acts::GeometryContext geoCtx;
Acts::MagneticFieldContext magCtx;
// Acts::CalibrationContext calCtx;
std::default_random_engine rng(42);

MeasurementResolution resPixel = {MeasurementType::eLoc01, {25_um, 50_um}};
MeasurementResolutionMap resolutions = {
{Acts::GeometryIdentifier().setVolume(0), resPixel}};

using SimStepper = EigenStepper<>;
const auto simPropagator =
makeConstantFieldPropagator<SimStepper>(detector.geometry, 0.3_T);

auto measurements = createMeasurements(
simPropagator, geoCtx, magCtx, parametersMeasurements, resolutions, rng);

auto sourceLinks = prepareSourceLinks(measurements.sourceLinks);
ACTS_VERBOSE("sourceLinks.size() = " << sourceLinks.size());

BOOST_REQUIRE_EQUAL(sourceLinks.size(), nSurfaces);

ACTS_DEBUG("Start fitting");
ACTS_VERBOSE("startParameter unsmeared:\n" << parametersMeasurements);
ACTS_VERBOSE("startParameter fit:\n" << startParametersFit);

const Surface* rSurface = &parametersMeasurements.referenceSurface();

// Reuse the SimPropagator, since it already uses the EigenStepper<>
using SimPropagator = decltype(simPropagator);
using Gx2Fitter =
Experimental::Gx2Fitter<SimPropagator, VectorMultiTrajectory>;
Gx2Fitter fitter(simPropagator, gx2fLogger->clone());

Experimental::Gx2FitterExtensions<VectorMultiTrajectory> extensions;
extensions.calibrator
.connect<&testSourceLinkCalibrator<VectorMultiTrajectory>>();
TestSourceLink::SurfaceAccessor surfaceAccessor{*detector.geometry};
extensions.surfaceAccessor
.connect<&TestSourceLink::SurfaceAccessor::operator()>(&surfaceAccessor);

MagneticFieldContext mfContext;
CalibrationContext calContext;

const Experimental::Gx2FitterOptions gx2fOptions(
tgContext, mfContext, calContext, extensions, PropagatorPlainOptions(),
rSurface, false, false, FreeToBoundCorrection(false), 5, false);

Acts::TrackContainer tracks{Acts::VectorTrackContainer{},
Acts::VectorMultiTrajectory{}};

// Fit the track
auto res = fitter.fit(sourceLinks.begin(), sourceLinks.end(),
startParametersFit, gx2fOptions, tracks);

BOOST_REQUIRE(res.ok());

auto& track = *res;
BOOST_CHECK_EQUAL(track.tipIndex(), nSurfaces - 1);
BOOST_CHECK(track.hasReferenceSurface());
BOOST_CHECK_EQUAL(track.nMeasurements(), nSurfaces);
BOOST_CHECK_EQUAL(track.nHoles(), 0u);
// We need quite coarse checks here, since on different builds
// the created measurements differ in the randomness
// TODO investigate further the reference values for eBoundPhi and det(cov)
BOOST_CHECK_CLOSE(track.parameters()[eBoundLoc0], -11., 8e0);
BOOST_CHECK_CLOSE(track.parameters()[eBoundLoc1], -15., 6e0);
BOOST_CHECK_CLOSE(track.parameters()[eBoundPhi], 1e-4, 1e3);
BOOST_CHECK_CLOSE(track.parameters()[eBoundTheta], M_PI / 2, 1e-3);
BOOST_CHECK_CLOSE(track.parameters()[eBoundQOverP], 0.5, 2e-1);
BOOST_CHECK_CLOSE(track.parameters()[eBoundTime], 12591.2832360000, 1e-6);
BOOST_CHECK_CLOSE(track.covariance().determinant(), 8e-35, 4e0);

ACTS_INFO("*** Test: FitWithBfield -- Finish");
}

BOOST_AUTO_TEST_SUITE_END()
} // namespace Test
} // namespace Acts

0 comments on commit 08b8c77

Please sign in to comment.