Skip to content

Commit

Permalink
test: use ACTS logging for Navigator tests (acts-project#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger authored Jun 26, 2024
1 parent 3d9c957 commit 55f03cc
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 213 deletions.
179 changes: 71 additions & 108 deletions Tests/IntegrationTests/NavigatorConsistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ auto tGeometry = cGeometry();
const double Bz = 2_T;
auto bField = std::make_shared<ConstantBField>(Vector3{0, 0, Bz});

Acts::Logging::Level logLevel = Acts::Logging::INFO;

using SurfaceCollector = SurfaceCollector<SurfaceSelector>;

std::vector<GeometryIdentifier> collectRelevantGeoIds(
Expand All @@ -61,11 +63,11 @@ std::vector<GeometryIdentifier> collectRelevantGeoIds(
///
/// @param prop is the propagator instance
/// @param start start parameters for propagation
/// @param debugMode toggle debug mode
/// @param logger A logger instance
template <typename propagator_t>
void runSelfConsistencyTest(const propagator_t& prop,
const CurvilinearTrackParameters& start,
bool debugMode) {
const Acts::Logger& logger) {
// Action list and abort list
using ActionListType = ActionList<SurfaceCollector>;
using AbortListType = AbortList<>;
Expand All @@ -82,24 +84,18 @@ void runSelfConsistencyTest(const propagator_t& prop,
fwdSurfaceCollector.selector.selectMaterial = true;
fwdSurfaceCollector.selector.selectPassive = true;

if (debugMode) {
std::cout << ">>> Forward Propagation : start." << std::endl;
}
ACTS_DEBUG(">>> Forward Propagation : start.");
auto fwdResult = prop.propagate(start, fwdOptions).value();
auto fwdSurfaceHits =
fwdResult.template get<SurfaceCollector::result_type>().collected;
auto fwdSurfaces = collectRelevantGeoIds(
fwdResult.template get<SurfaceCollector::result_type>());

// get the forward output to the screen
if (debugMode) {
// check if the surfaces are free
std::cout << ">>> Surface hits found on ..." << std::endl;
for (const auto& fwdSteps : fwdSurfaces) {
std::cout << "--> Surface with " << fwdSteps << std::endl;
}
std::cout << ">>> Forward Propagation : end." << std::endl;
ACTS_DEBUG(">>> Surface hits found on ...");
for (const auto& fwdSteps : fwdSurfaces) {
ACTS_DEBUG("--> Surface with " << fwdSteps);
}
ACTS_DEBUG(">>> Forward Propagation : end.");

// backward surface test
Options bwdOptions(tgContext, mfContext);
Expand All @@ -115,9 +111,7 @@ void runSelfConsistencyTest(const propagator_t& prop,

const auto& startSurface = start.referenceSurface();

if (debugMode) {
std::cout << ">>> Backward Propagation : start." << std::endl;
}
ACTS_DEBUG(">>> Backward Propagation : start.");
auto bwdResult =
prop.propagate(*fwdResult.endParameters, startSurface, bwdOptions)
.value();
Expand All @@ -126,15 +120,11 @@ void runSelfConsistencyTest(const propagator_t& prop,
auto bwdSurfaces = collectRelevantGeoIds(
bwdResult.template get<SurfaceCollector::result_type>());

// get the backward output to the screen
if (debugMode) {
// check if the surfaces are free
std::cout << ">>> Surface hits found on ..." << std::endl;
for (auto& bwdSteps : bwdSurfaces) {
std::cout << "--> Surface with " << bwdSteps << std::endl;
}
std::cout << ">>> Backward Propagation : end." << std::endl;
ACTS_DEBUG(">>> Surface hits found on ...");
for (auto& bwdSteps : bwdSurfaces) {
ACTS_DEBUG("--> Surface with " << bwdSteps);
}
ACTS_DEBUG(">>> Backward Propagation : end.");

// forward-backward compatibility test
{
Expand All @@ -160,11 +150,9 @@ void runSelfConsistencyTest(const propagator_t& prop,
BoundTrackParameters sParameters = start;
std::vector<BoundTrackParameters> stepParameters;
for (auto& fwdSteps : fwdSurfaceHits) {
if (debugMode) {
std::cout << ">>> Forward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< fwdSteps.surface->geometryId() << std::endl;
}
ACTS_DEBUG(">>> Forward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< fwdSteps.surface->geometryId());

// make a forward step
auto fwdStep =
Expand All @@ -183,11 +171,9 @@ void runSelfConsistencyTest(const propagator_t& prop,
}
// final destination surface
const Surface& dSurface = fwdResult.endParameters->referenceSurface();
if (debugMode) {
std::cout << ">>> Forward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< dSurface.geometryId() << std::endl;
}
ACTS_DEBUG(">>> Forward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< dSurface.geometryId());
auto fwdStepFinal =
prop.propagate(sParameters, dSurface, fwdStepOptions).value();
auto fwdStepSurfacesTmp = collectRelevantGeoIds(
Expand All @@ -214,11 +200,9 @@ void runSelfConsistencyTest(const propagator_t& prop,
// move forward step by step through the surfaces
sParameters = *fwdResult.endParameters;
for (auto& bwdSteps : bwdSurfaceHits) {
if (debugMode) {
std::cout << ">>> Backward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< bwdSteps.surface->geometryId() << std::endl;
}
ACTS_DEBUG(">>> Backward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< bwdSteps.surface->geometryId());

// make a forward step
auto bwdStep =
Expand All @@ -237,11 +221,9 @@ void runSelfConsistencyTest(const propagator_t& prop,
}
// final destination surface
const Surface& dbSurface = start.referenceSurface();
if (debugMode) {
std::cout << ">>> Backward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< dSurface.geometryId() << std::endl;
}
ACTS_DEBUG(">>> Backward step : "
<< sParameters.referenceSurface().geometryId() << " --> "
<< dSurface.geometryId());
auto bwdStepFinal =
prop.propagate(sParameters, dbSurface, bwdStepOptions).value();
auto bwdStepSurfacesTmp = collectRelevantGeoIds(
Expand All @@ -265,12 +247,12 @@ void runSelfConsistencyTest(const propagator_t& prop,
/// @param propProbe is the probe propagator instance
/// @param propRef is the reference propagator instance
/// @param start start parameters for propagation
/// @param debugMode toggle debug mode
/// @param logger A logger instance
template <typename propagator_probe_t, typename propagator_ref_t>
void runConsistencyTest(const propagator_probe_t& propProbe,
const propagator_ref_t& propRef,
const CurvilinearTrackParameters& start,
bool debugMode) {
const Acts::Logger& logger) {
// Action list and abort list
using ActionListType = ActionList<SurfaceCollector>;
using AbortListType = AbortList<>;
Expand All @@ -293,33 +275,21 @@ void runConsistencyTest(const propagator_probe_t& propProbe,
auto fwdSurfaces = collectRelevantGeoIds(
fwdResult.template get<SurfaceCollector::result_type>());

// get the forward output to the screen
if (debugMode) {
// check if the surfaces are free
std::cout << ">>> Surface hits found on ..." << std::endl;
for (const auto& fwdSteps : fwdSurfaces) {
std::cout << "--> Surface with " << fwdSteps << std::endl;
}
ACTS_DEBUG(">>> Surface hits found on ...");
for (const auto& fwdSteps : fwdSurfaces) {
ACTS_DEBUG("--> Surface with " << fwdSteps);
}

return fwdSurfaces;
};

if (debugMode) {
std::cout << ">>> Probe Propagation : start." << std::endl;
}
ACTS_DEBUG(">>> Probe Propagation : start.");
const auto& probeSurfaces = run(propProbe);
if (debugMode) {
std::cout << ">>> Probe Propagation : end." << std::endl;
}
ACTS_DEBUG(">>> Probe Propagation : end.");

if (debugMode) {
std::cout << ">>> Reference Propagation : start." << std::endl;
}
ACTS_DEBUG(">>> Reference Propagation : start.");
const auto& refSurfaces = run(propRef);
if (debugMode) {
std::cout << ">>> Reference Propagation : end." << std::endl;
}
ACTS_DEBUG(">>> Reference Propagation : end.");

// probe-ref compatibility test
BOOST_CHECK_EQUAL_COLLECTIONS(probeSurfaces.begin(), probeSurfaces.end(),
Expand All @@ -329,7 +299,6 @@ void runConsistencyTest(const propagator_probe_t& propProbe,
const int nTestsSelfConsistency = 500;
const int nTestsRefConsistency = 500;
int skip = 0;
bool debugMode = false;

using EigenStepper = Acts::EigenStepper<>;
using EigenPropagator = Propagator<EigenStepper, Navigator>;
Expand Down Expand Up @@ -395,6 +364,8 @@ auto eventGen =
BOOST_DATA_TEST_CASE(NavigatorSelfConsistency,
eventGen ^ bdata::xrange(nTestsSelfConsistency), pT, phi,
theta, charge, index) {
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("NavigatorTest", logLevel))

if (index < skip) {
return;
}
Expand All @@ -404,26 +375,22 @@ BOOST_DATA_TEST_CASE(NavigatorSelfConsistency,
CurvilinearTrackParameters start(Vector4(0, 0, 0, 0), phi, theta, q / p,
std::nullopt, ParticleHypothesis::pion());

if (debugMode) {
std::cout << ">>> Run navigation tests with pT = " << pT
<< "; phi = " << phi << "; theta = " << theta
<< "; charge = " << charge << "; index = " << index << ";"
<< std::endl;
}
ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
<< pT << "\n phi = " << phi << "\n theta = " << theta
<< "\n charge = " << charge << "\n index = " << index);

if (debugMode) {
std::cout << ">>> Test self consistency epropagator" << std::endl;
}
runSelfConsistencyTest(epropagator, start, debugMode);
if (debugMode) {
std::cout << ">>> Test self consistency slpropagator" << std::endl;
}
runSelfConsistencyTest(slpropagator, start, debugMode);
ACTS_DEBUG(">>> Test self consistency epropagator");
runSelfConsistencyTest(epropagator, start, logger());

ACTS_DEBUG(">>> Test self consistency slpropagator");
runSelfConsistencyTest(slpropagator, start, logger());
}

BOOST_DATA_TEST_CASE(NavigatorRef1Consistency,
eventGen ^ bdata::xrange(nTestsRefConsistency), pT, phi,
theta, charge, index) {
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("NavigatorTest", logLevel))

if (index < skip) {
return;
}
Expand All @@ -433,26 +400,22 @@ BOOST_DATA_TEST_CASE(NavigatorRef1Consistency,
CurvilinearTrackParameters start(Vector4(0, 0, 0, 0), phi, theta, q / p,
std::nullopt, ParticleHypothesis::pion());

if (debugMode) {
std::cout << ">>> Run navigation tests with pT = " << pT
<< "; phi = " << phi << "; theta = " << theta
<< "; charge = " << charge << "; index = " << index << ";"
<< std::endl;
}
ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
<< pT << "\n phi = " << phi << "\n theta = " << theta
<< "\n charge = " << charge << "\n index = " << index);

if (debugMode) {
std::cout << ">>> Test reference 1 consistency epropagator" << std::endl;
}
runConsistencyTest(epropagator, refepropagator1, start, debugMode);
if (debugMode) {
std::cout << ">>> Test reference 1 consistency slpropagator" << std::endl;
}
runConsistencyTest(slpropagator, refslpropagator1, start, debugMode);
ACTS_DEBUG(">>> Test reference 1 consistency epropagator");
runConsistencyTest(epropagator, refepropagator1, start, logger());

ACTS_DEBUG(">>> Test reference 1 consistency slpropagator");
runConsistencyTest(slpropagator, refslpropagator1, start, logger());
}

BOOST_DATA_TEST_CASE(NavigatorRef2Consistency,
eventGen ^ bdata::xrange(nTestsRefConsistency), pT, phi,
theta, charge, index) {
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("NavigatorTest", logLevel))

if (index < skip) {
return;
}
Expand All @@ -462,21 +425,21 @@ BOOST_DATA_TEST_CASE(NavigatorRef2Consistency,
CurvilinearTrackParameters start(Vector4(0, 0, 0, 0), phi, theta, q / p,
std::nullopt, ParticleHypothesis::pion());

if (debugMode) {
std::cout << ">>> Run navigation tests with pT = " << pT
<< "; phi = " << phi << "; theta = " << theta
<< "; charge = " << charge << "; index = " << index << ";"
<< std::endl;
}
ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
<< pT << "\n phi = " << phi << "\n theta = " << theta
<< "\n charge = " << charge << "\n index = " << index);

if (debugMode) {
std::cout << ">>> Test reference 2 consistency epropagator" << std::endl;
}
runConsistencyTest(epropagator, refepropagator2, start, debugMode);
if (debugMode) {
std::cout << ">>> Test reference 2 consistency slpropagator" << std::endl;
}
runConsistencyTest(slpropagator, refslpropagator2, start, debugMode);
ACTS_DEBUG(">>> Test reference 1 consistency epropagator");
runConsistencyTest(epropagator, refepropagator1, start, logger());

ACTS_DEBUG(">>> Test reference 1 consistency slpropagator");
runConsistencyTest(slpropagator, refslpropagator1, start, logger());

ACTS_DEBUG(">>> Test reference 2 consistency epropagator");
runConsistencyTest(epropagator, refepropagator2, start, logger());

ACTS_DEBUG(">>> Test reference 2 consistency slpropagator");
runConsistencyTest(slpropagator, refslpropagator2, start, logger());
}

} // namespace Acts::Test
Loading

0 comments on commit 55f03cc

Please sign in to comment.