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

fix: GX2F: Finish material-less fit by resetting the track container #2739

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 43 additions & 67 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ struct Gx2FitterResult {
// between the first and last measurements.
std::size_t measurementHoles = 0;

// Counter for handled states
std::size_t processedStates = 0;
// Counter for handled measurements
std::size_t processedMeasurements = 0;

// Indicator if track fitting has been done
bool finished = false;
Expand Down Expand Up @@ -261,12 +261,12 @@ void collector(typename traj_t::TrackStateProxy& trackStateProxy,
predicted)
.eval();

ACTS_VERBOSE("Processing and collecting measurements in Actor:\n"
<< "\tMeasurement:\t" << measurement.transpose()
<< "\n\tPredicted:\t" << predicted.transpose()
<< "\n\tProjector:\t" << trackStateProxy.effectiveProjector()
<< "\n\tProjected Jacobian:\t" << projJacobian
<< "\n\tCovariance Measurements:\t" << covarianceMeasurement);
ACTS_VERBOSE("Processing and collecting measurements in Actor:"
<< "\n Measurement:\t" << measurement.transpose()
<< "\n Predicted:\t" << predicted.transpose()
<< "\n Projector:\t" << trackStateProxy.effectiveProjector()
<< "\n Projected Jacobian:\t" << projJacobian
<< "\n Covariance Measurements:\t" << covarianceMeasurement);

// Collect residuals, covariances, and projected jacobians
for (std::size_t i = 0; i < measDim; i++) {
Expand All @@ -280,10 +280,10 @@ void collector(typename traj_t::TrackStateProxy& trackStateProxy,
result.collectorCovariances.push_back(covarianceMeasurement(i, i));
result.collectorProjectedJacobians.push_back(projJacobian.row(i));

ACTS_VERBOSE("\tSplitting the measurement:\n"
<< "\t\tResidual:\t" << measurement[i] - projPredicted[i]
<< "\n\t\tCovariance:\t" << covarianceMeasurement(i, i)
<< "\n\t\tProjected Jacobian:\t" << projJacobian.row(i));
ACTS_VERBOSE(" Splitting the measurement:"
<< "\n Residual:\t" << measurement[i] - projPredicted[i]
<< "\n Covariance:\t" << covarianceMeasurement(i, i)
<< "\n Projected Jacobian:\t" << projJacobian.row(i));
}
}

Expand Down Expand Up @@ -397,26 +397,13 @@ class Gx2Fitter {
return;
}

// 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);
// std::string direction = state.stepping.navDir.toString();
if (surface != nullptr) {
++result.surfaceCount;
ACTS_VERBOSE("Measurement surface " << surface->geometryId()
<< " detected.");
ACTS_VERBOSE("Surface " << surface->geometryId() << " detected.");

// check if measurement surface
auto sourcelink_it = inputMeasurements->find(surface->geometryId());
Expand All @@ -431,10 +418,10 @@ class Gx2Fitter {

ACTS_VERBOSE(
"Actor - indices before processing:"
<< "\n\t"
<< "\n "
<< "result.lastMeasurementIndex: " << result.lastMeasurementIndex
<< "\n\t"
<< "result.lastTrackIndex: " << result.lastTrackIndex << "\n\t"
<< "\n "
<< "result.lastTrackIndex: " << result.lastTrackIndex << "\n "
<< "result.fittedStates->size(): " << result.fittedStates->size())

// TODO generalize the update of the currentTrackIndex
Expand All @@ -444,38 +431,12 @@ class Gx2Fitter {
TrackStatePropMask mask =
~(TrackStatePropMask::Smoothed | TrackStatePropMask::Filtered);

// Checks if an existing surface is found during the gx2f-iteration.
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved
// If not, a new index will be generated afterwards.
// During the first iteration, we will always create a new index.
std::size_t currentTrackIndex = Acts::MultiTrajectoryTraits::kInvalid;
if (nUpdate == 0) {
ACTS_VERBOSE(" processSurface: nUpdate == 0 decision");

// Add a <mask> TrackState entry multi trajectory. This allocates
// storage for all components, which we will set later.
currentTrackIndex =
fittedStates.addTrackState(mask, result.lastTrackIndex);
} else {
ACTS_VERBOSE(" processSurface: nUpdate > 0 decision");

if (result.lastTrackIndex ==
Acts::MultiTrajectoryTraits::kInvalid) {
currentTrackIndex = 0;
ACTS_VERBOSE(" processSurface: currentTrackIndex (kInv->0) = "
<< currentTrackIndex);
} else if (result.lastTrackIndex < fittedStates.size() - 1) {
currentTrackIndex = result.lastTrackIndex + 1;
ACTS_VERBOSE(" processSurface: currentTrackIndex (n+1) = "
<< currentTrackIndex);
} else {
// Add a <mask> TrackState entry multi trajectory. This allocates
// storage for all components, which we will set later.
currentTrackIndex =
fittedStates.addTrackState(mask, result.lastTrackIndex);
ACTS_VERBOSE(" processSurface: currentTrackIndex (ADD NEW)= "
<< currentTrackIndex);
}
}
ACTS_VERBOSE(" processSurface: addTrackState");

// Add a <mask> TrackState entry multi trajectory. This allocates
// storage for all components, which we will set later.
std::size_t currentTrackIndex =
fittedStates.addTrackState(mask, result.lastTrackIndex);

// now get track state proxy back
typename traj_t::TrackStateProxy trackStateProxy =
Expand Down Expand Up @@ -535,23 +496,30 @@ class Gx2Fitter {

// Set the measurement type flag
typeFlags.set(TrackStateFlag::MeasurementFlag);
// We count the processed state
++result.processedStates;
// We count the processed measurement
++result.processedMeasurements;
ACTS_VERBOSE("Actor - indices after processing, before over writing:"
<< "\n\t"
<< "\n "
<< "result.lastMeasurementIndex: "
<< result.lastMeasurementIndex << "\n\t"
<< result.lastMeasurementIndex << "\n "
<< "trackStateProxy.index(): " << trackStateProxy.index()
<< "\n\t"
<< "\n "
<< "result.lastTrackIndex: " << result.lastTrackIndex
<< "\n\t"
<< "\n "
<< "currentTrackIndex: " << currentTrackIndex)
result.lastMeasurementIndex = currentTrackIndex;
result.lastTrackIndex = currentTrackIndex;
} else {
ACTS_INFO("Actor: This case is not implemented yet")
}
}
ACTS_DEBUG("result.processedMeasurements: "
<< result.processedMeasurements << "\n"
<< "inputMeasurements.size()" << inputMeasurements->size())
if (result.processedMeasurements >= inputMeasurements->size()) {
ACTS_INFO("Actor: finish: all measurements found.");
result.finished = true;
}

if (result.surfaceCount > 900) {
ACTS_INFO("Actor: finish due to limit. Result might be garbage.");
Expand Down Expand Up @@ -681,6 +649,9 @@ class Gx2Fitter {

auto& r = inputResult.template get<Gx2FitterResult<traj_t>>();

// Clear the track container. It could be more performant to update the
// existing states, but this needs some more thinking.
trackContainer.clear();
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved
r.fittedStates = &trackContainer.trackStateContainer();
// propagate with params and return jacobians and residuals
auto result = m_propagator.template propagate(
Expand Down Expand Up @@ -744,6 +715,11 @@ class Gx2Fitter {
break;
}

// TODO investigate further
if (chi2sum > oldChi2sum + 1e-5) {
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved
ACTS_DEBUG("chi2 not converging monotonically");
}

oldChi2sum = chi2sum;
}
ACTS_DEBUG("Finished to iterate");
Expand Down
Loading