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

Improve assertions in Kálmán filter and fitter #900

Merged
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions device/common/include/traccc/finding/device/impl/build_tracks.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ TRACCC_DEVICE inline void build_tracks(const global_index_t globalIndex,
scalar ndf_sum = 0.f;
scalar chi2_sum = 0.f;

[[maybe_unused]] std::size_t num_inserted = 0;

// Reversely iterate to fill the track candidates
for (auto it = cands_per_track.rbegin(); it != cands_per_track.rend();
it++) {
Expand All @@ -91,6 +93,7 @@ TRACCC_DEVICE inline void build_tracks(const global_index_t globalIndex,
}

*it = {measurements.at(L.meas_idx)};
num_inserted++;

// Sanity check on chi2
assert(L.chi2 < std::numeric_limits<traccc::scalar>::max());
Expand All @@ -111,6 +114,24 @@ TRACCC_DEVICE inline void build_tracks(const global_index_t globalIndex,
}
}

#ifndef NDEBUG
if (success) {
// Assert that we inserted exactly as many elements as we reserved
// space for.
assert(num_inserted == cands_per_track.size());

// Assert that we did not make any duplicate track states.
for (unsigned int i = 0; i < cands_per_track.size(); ++i) {
for (unsigned int j = 0; j < cands_per_track.size(); ++j) {
if (i != j) {
assert(cands_per_track.at(i).measurement_id !=
cands_per_track.at(j).measurement_id);
}
}
}
}
#endif

// NOTE: We may at some point want to assert that `success` is true

// Criteria for valid tracks
Expand Down
5 changes: 3 additions & 2 deletions device/common/include/traccc/fitting/device/impl/fit.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ TRACCC_HOST_DEVICE inline void fit(
// Run fitting
kalman_fitter_status fit_status = fitter.fit(seed_param, fitter_state);

// TODO: Process fit failures more elegantly
assert(fit_status == kalman_fitter_status::SUCCESS);
if (fitter_state.m_fit_res.fit_outcome == fitter_outcome::SUCCESS) {
assert(fit_status == kalman_fitter_status::SUCCESS);
}

// Get the final fitting information
track_states.at(param_id).header = fitter_state.m_fit_res;
Expand Down
Loading