Skip to content

Commit

Permalink
fix(gx2f): constrain update to initial volume (#3411)
Browse files Browse the repository at this point in the history
During the Athena integration, I ran again into the issue described in
- #3267

This PR does not fix the navigation itself but avoids the GX2F ending up in a state, where the above issue would occur. I investigated different approaches to avoid ending up in a situation, where an FPE would occur.

### Simulate division
The FPE occurs, when we are calling the path correction. Checking and aborting if the x-y components for position and direction are zero would be sufficient. However, we should also apply the transformation to the position first, which seemed a bit difficult in the actor.

Using this approach too many tracks were filtered out.
I didn't not check, if all of them would fail anyhow, though.

### Constrain parameters (Used)
I had the issue only, when starting from a volume, that was different from the initial volume of the starting parameters. However, there were also cases, where I switched volumes and didn't crash. After looking into all non-crashing cases (analysed 13 tracks, because then the Athena truth tracking crashed), I saw, that all of them would later end with the error `NotEnoughMeasurements. Therefore, we effectively do not lose any tracks but detect their failure earlier. In the physmon, we also see with larger statistics no change to the current behaviour.

## Testing
I built a new detector for testing this behaviour. I tried to reuse the old one by adding extra parameters, but I didn't succeed. Somehow, I had to flip the detector to force the volume change.

I also added a visualisation script to it, that generates an `.obj` of the detector and draws the measurements. This one I used for the development since the beginning but didn't find a proper place to put it in. The new detector might be complex enough, that we maybe want to visualise it during development.

<img width="1210" alt="image" src="https://github.com/user-attachments/assets/dcf5b91f-f98c-4511-8507-0fc7e4a23ace">

## Blocked
- #3463
  • Loading branch information
AJPfleger authored Aug 1, 2024
1 parent 83bb4aa commit d224d80
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 4 deletions.
38 changes: 37 additions & 1 deletion Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/MagneticField/MagneticFieldContext.hpp"
#include "Acts/Material/MaterialSlab.hpp"
#include "Acts/Propagator/AbortList.hpp"
Expand Down Expand Up @@ -221,6 +222,10 @@ struct Gx2FitterResult {

// Count how many surfaces have been hit
std::size_t surfaceCount = 0;

// Monitor which volume we start in. We do not allow to switch the start of a
// following iteration in a different volume.
const TrackingVolume* startVolume = nullptr;
};

/// addToGx2fSums Function
Expand Down Expand Up @@ -397,6 +402,10 @@ class Gx2Fitter {
/// Calibration context for the fit
const CalibrationContext* calibrationContext{nullptr};

/// Monitor which volume we start in. We do not allow to switch the start of
/// a following iteration in a different volume.
const TrackingVolume* startVolume = nullptr;

/// @brief Gx2f actor operation
///
/// @tparam propagator_state_t is the type of Propagator state
Expand Down Expand Up @@ -424,7 +433,7 @@ class Gx2Fitter {
}

// End the propagation and return to the fitter
if (result.finished) {
if (result.finished || !result.result.ok()) {
// Remove the missing surfaces that occur after the last measurement
if (result.measurementStates > 0) {
result.missedActiveSurfaces.resize(result.measurementHoles);
Expand All @@ -433,6 +442,19 @@ class Gx2Fitter {
return;
}

if (startVolume != nullptr &&
startVolume != state.navigation.startVolume) {
ACTS_INFO("The update pushed us to a new volume from '"
<< startVolume->volumeName() << "' to '"
<< state.navigation.startVolume->volumeName()
<< "'. Starting to abort.");
result.result = Result<void>(
Experimental::GlobalChiSquareFitterError::UpdatePushedToNewVolume);

return;
}
result.startVolume = state.navigation.startVolume;

// Update:
// - Waiting for a current surface
auto surface = navigator.currentSurface(state.navigation);
Expand Down Expand Up @@ -716,6 +738,10 @@ class Gx2Fitter {
// want to fit e.g. q/p and adjusts itself later.
std::size_t ndfSystem = std::numeric_limits<std::size_t>::max();

// Monitor which volume we start in. We do not allow to switch the start of
// a following iteration in a different volume.
const TrackingVolume* startVolume = nullptr;

ACTS_VERBOSE("params:\n" << params);

/// Actual Fitting /////////////////////////////////////////////////////////
Expand Down Expand Up @@ -750,6 +776,7 @@ class Gx2Fitter {
gx2fActor.extensions = gx2fOptions.extensions;
gx2fActor.calibrationContext = &gx2fOptions.calibrationContext.get();
gx2fActor.actorLogger = m_actorLogger.get();
gx2fActor.startVolume = startVolume;

auto propagatorState = m_propagator.makeState(params, propagatorOptions);

Expand All @@ -762,6 +789,7 @@ class Gx2Fitter {

auto propagationResult = m_propagator.template propagate(propagatorState);

// Run the fitter
auto result = m_propagator.template makeResult(std::move(propagatorState),
propagationResult,
propagatorOptions, false);
Expand All @@ -776,6 +804,13 @@ class Gx2Fitter {
auto& propRes = *result;
GX2FResult gx2fResult = std::move(propRes.template get<GX2FResult>());

if (!gx2fResult.result.ok()) {
ACTS_INFO("GlobalChiSquareFitter failed in actor: "
<< gx2fResult.result.error() << ", "
<< gx2fResult.result.error().message());
return gx2fResult.result.error();
}

auto track = trackContainerTemp.makeTrack();
tipIndex = gx2fResult.lastMeasurementIndex;

Expand Down Expand Up @@ -903,6 +938,7 @@ class Gx2Fitter {
}

oldChi2sum = chi2sum;
startVolume = gx2fResult.startVolume;
}
ACTS_DEBUG("Finished to iterate");
ACTS_VERBOSE("final params:\n" << params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class GlobalChiSquareFitterError {
AIsNotInvertible = 1,
DidNotConverge = 2,
NotEnoughMeasurements = 3,
UpdatePushedToNewVolume = 4,
};

std::error_code make_error_code(
Expand Down
2 changes: 2 additions & 0 deletions Core/src/TrackFitting/GlobalChiSquareFitterError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class GlobalChiSquareFitterErrorCategory : public std::error_category {
return "Gx2f: Did not converge in 'nUpdateMax' updates.";
case GlobalChiSquareFitterError::NotEnoughMeasurements:
return "Gx2f: Not enough measurements.";
case GlobalChiSquareFitterError::UpdatePushedToNewVolume:
return "Gx2f: Update pushed the parameters to a new volume.";
default:
return "unknown";
}
Expand Down
Loading

0 comments on commit d224d80

Please sign in to comment.