Skip to content

Commit

Permalink
refactor!: Move Navigator external surfaces into options (#3189)
Browse files Browse the repository at this point in the history
After #3181 and
#3182 we can properly
initialize the external surfaces for the `Navigator` via options without
modifying the state while propagation.

blocked by:
- #3181
- #3182
- #3190
  • Loading branch information
andiwand authored Jul 17, 2024
1 parent 625f3bc commit 8054963
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 51 deletions.
5 changes: 0 additions & 5 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ class DetectorNavigator {
state.navigationBreak = navigationBreak;
}

void insertExternalSurface(State& /*state*/,
GeometryIdentifier /*geoid*/) const {
// TODO what about external surfaces?
}

/// Initialize call - start of propagation
///
/// @tparam propagator_state_t The state type of the propagator
Expand Down
24 changes: 12 additions & 12 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class Navigator {
};

struct Options : public NavigatorPlainOptions {
/// Externally provided surfaces - these are tried to be hit
ExternalSurfaces externalSurfaces = {};

void insertExternalSurface(GeometryIdentifier geoid) {
externalSurfaces.insert(
std::pair<std::uint64_t, GeometryIdentifier>(geoid.layer(), geoid));
}

void setPlainOptions(const NavigatorPlainOptions& options) {
static_cast<NavigatorPlainOptions&>(*this) = options;
}
Expand Down Expand Up @@ -147,9 +155,6 @@ class Navigator {
auto navLayer() const { return navLayers.at(navLayerIndex); }
auto navBoundary() const { return navBoundaries.at(navBoundaryIndex); }

/// Externally provided surfaces - these are tried to be hit
ExternalSurfaces externalSurfaces = {};

/// Navigation state: the world volume
const TrackingVolume* worldVolume = nullptr;

Expand Down Expand Up @@ -251,11 +256,6 @@ class Navigator {
state.navigationBreak = navigationBreak;
}

void insertExternalSurface(State& state, GeometryIdentifier geoid) const {
state.externalSurfaces.insert(
std::pair<std::uint64_t, GeometryIdentifier>(geoid.layer(), geoid));
}

/// @brief Initialize call - start of navigation
///
/// @tparam propagator_state_t The state type of the propagator
Expand Down Expand Up @@ -627,7 +627,7 @@ class Navigator {
auto layerID = state.navigation.navSurface().object()->geometryId().layer();
std::pair<ExternalSurfaces::iterator, ExternalSurfaces::iterator>
externalSurfaceRange =
state.navigation.externalSurfaces.equal_range(layerID);
state.navigation.options.externalSurfaces.equal_range(layerID);
// Loop over the remaining navigation surfaces
while (state.navigation.navSurfaceIndex !=
state.navigation.navSurfaces.size()) {
Expand Down Expand Up @@ -1039,12 +1039,12 @@ class Navigator {
navOpts.endObject = state.navigation.targetSurface;

std::vector<GeometryIdentifier> externalSurfaces;
if (!state.navigation.externalSurfaces.empty()) {
if (!state.navigation.options.externalSurfaces.empty()) {
auto layerID = layerSurface->geometryId().layer();
auto externalSurfaceRange =
state.navigation.externalSurfaces.equal_range(layerID);
state.navigation.options.externalSurfaces.equal_range(layerID);
navOpts.externalSurfaces.reserve(
state.navigation.externalSurfaces.count(layerID));
state.navigation.options.externalSurfaces.count(layerID));
for (auto itSurface = externalSurfaceRange.first;
itSurface != externalSurfaceRange.second; itSurface++) {
navOpts.externalSurfaces.push_back(itSurface->second);
Expand Down
17 changes: 7 additions & 10 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,6 @@ class Gx2Fitter {
return;
}

// Add the measurement surface as external surface to the navigator.
// We will try to hit those surface by ignoring boundary checks.
if (state.navigation.externalSurfaces.size() == 0) {
for (auto measurementIt = inputMeasurements->begin();
measurementIt != inputMeasurements->end(); measurementIt++) {
navigator.insertExternalSurface(state.navigation,
measurementIt->first);
}
}

// Update:
// - Waiting for a current surface
auto surface = navigator.currentSurface(state.navigation);
Expand Down Expand Up @@ -748,6 +738,13 @@ class Gx2Fitter {
Acts::MagneticFieldContext magCtx = gx2fOptions.magFieldContext;
// Set options for propagator
PropagatorOptions propagatorOptions(geoCtx, magCtx);

// Add the measurement surface as external surface to the navigator.
// We will try to hit those surface by ignoring boundary checks.
for (const auto& [surfaceId, _] : inputMeasurements) {
propagatorOptions.navigation.insertExternalSurface(surfaceId);
}

auto& gx2fActor = propagatorOptions.actionList.template get<GX2FActor>();
gx2fActor.inputMeasurements = &inputMeasurements;
gx2fActor.extensions = gx2fOptions.extensions;
Expand Down
18 changes: 6 additions & 12 deletions Core/include/Acts/TrackFitting/KalmanFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,6 @@ class KalmanFitter {
<< " momentum: "
<< stepper.absoluteMomentum(state.stepping));

// Add the measurement surface as external surface to navigator.
// We will try to hit those surface by ignoring boundary checks.
if constexpr (!isDirectNavigator) {
if (result.processedStates == 0) {
for (auto measurementIt = inputMeasurements->begin();
measurementIt != inputMeasurements->end(); measurementIt++) {
navigator.insertExternalSurface(state.navigation,
measurementIt->first);
}
}
}

// Update:
// - Waiting for a current surface
auto surface = navigator.currentSurface(state.navigation);
Expand Down Expand Up @@ -1134,6 +1122,12 @@ class KalmanFitter {
// Set the trivial propagator options
propagatorOptions.setPlainOptions(kfOptions.propagatorPlainOptions);

// Add the measurement surface as external surface to navigator.
// We will try to hit those surface by ignoring boundary checks.
for (const auto& [surfaceId, _] : inputMeasurements) {
propagatorOptions.navigation.insertExternalSurface(surfaceId);
}

// Catch the actor and set the measurements
auto& kalmanActor =
propagatorOptions.actionList.template get<KalmanActor>();
Expand Down
22 changes: 10 additions & 12 deletions Tests/UnitTests/Core/Propagator/NavigatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,10 @@ void step(stepper_state_t& sstate) {
/// @param [in] navBound Number of navigation boundaries
/// @param [in] extSurf Number of external surfaces
bool testNavigatorStateVectors(Navigator::State& state, std::size_t navSurf,
std::size_t navLay, std::size_t navBound,
std::size_t extSurf) {
std::size_t navLay, std::size_t navBound) {
return ((state.navSurfaces.size() == navSurf) &&
(state.navLayers.size() == navLay) &&
(state.navBoundaries.size() == navBound) &&
(state.externalSurfaces.size() == extSurf));
(state.navBoundaries.size() == navBound));
}

/// @brief Method for testing pointers in @c Navigator::State
Expand Down Expand Up @@ -342,7 +340,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
Navigator navigator{navCfg};

navigator.postStep(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(state.navigation, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
Expand All @@ -358,7 +356,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
Navigator navigator{navCfg};

navigator.postStep(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(state.navigation, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
Expand All @@ -379,7 +377,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
ACTS_INFO(" i) Because target is reached");
state.navigation.targetReached = true;
navigator.postStep(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(state.navigation, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
Expand All @@ -388,7 +386,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
state.navigation.targetReached = false;
state.navigation.targetSurface = nullptr;
navigator.postStep(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(state.navigation, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
Expand All @@ -399,7 +397,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
const Surface* targetSurf = startSurf;
state.navigation.targetSurface = targetSurf;
navigator.postStep(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(
state.navigation, nullptr, nullptr, nullptr, nullptr, targetSurf,
nullptr, nullptr, nullptr, targetSurf));
Expand All @@ -414,7 +412,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
const Layer* startLay = startVol->associatedLayer(
state.geoContext, stepper.position(state.stepping));
navigator.initialize(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(state.navigation, worldVol, startVol,
startLay, nullptr, nullptr, startVol,
nullptr, nullptr, nullptr));
Expand All @@ -423,7 +421,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
state.navigation = Navigator::State();
state.navigation.startSurface = startSurf;
navigator.initialize(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(
state.navigation, worldVol, startVol, startLay, startSurf, startSurf,
startVol, nullptr, nullptr, nullptr));
Expand All @@ -432,7 +430,7 @@ BOOST_AUTO_TEST_CASE(Navigator_status_methods) {
state.navigation = Navigator::State();
state.navigation.startVolume = startVol;
navigator.initialize(state, stepper);
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStateVectors(state.navigation, 0u, 0u, 0u));
BOOST_CHECK(testNavigatorStatePointers(state.navigation, worldVol, startVol,
startLay, nullptr, nullptr, startVol,
nullptr, nullptr, nullptr));
Expand Down

0 comments on commit 8054963

Please sign in to comment.