Skip to content

Commit

Permalink
feat: unbiased trackstates for fitters that do not smooth (#2999)
Browse files Browse the repository at this point in the history
## What?
Lets the `RootTrackStatesWriter.cpp` write unbiased states, even if there are no `smoothed` states.

## Why?
The states we are writing are based upon the Kalman Filter formalism. There, we would expect `predicted`, `filtered`, and `smoothed` states. The `smoothed` states should be the final states. Other fitters, like the GX2F, do not take this path. Therefore, the final estimate is written to `predicted`.

Until now, the `unbiased` states could only be computed from `smoothed` states. However, it is also for interest for other fitters to investigate the `unbiased` pulls and residuals.

The idea for this PR evolved while investigating the track states for the GX2F (PR #2949). Seems to be useful to have this in.

## Notes
We need to check for `state.hasCalibrated()`, since the physmon tests for the GSF were crashing. It seems, the GSF creates states without measurements. There, the programme aborted with
```
state.calibratedSize(): 4294967295
template_switch<Fn, 6, 6>(v=4294967295) is not valid (v > NMAX)
```
  • Loading branch information
AJPfleger authored Mar 4, 2024
1 parent 6fd0337 commit 9fcfb7e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
33 changes: 33 additions & 0 deletions Examples/Io/Root/src/RootTrackStatesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,39 @@ ActsExamples::ProcessCode ActsExamples::RootTrackStatesWriter::writeT(
state.smoothedCovariance() - K * H * state.smoothedCovariance();
return std::make_pair(unbiasedParamsVec, unbiasedParamsCov);
}
if (ipar == eUnbiased && !state.hasSmoothed() && state.hasFiltered() &&
state.hasProjector() && state.hasCalibrated()) {
// Same calculation as above but using the filtered states.
auto m = state.effectiveCalibrated();
auto H = state.effectiveProjector();
auto V = state.effectiveCalibratedCovariance();
auto K =
(state.filteredCovariance() * H.transpose() *
(H * state.filteredCovariance() * H.transpose() - V).inverse())
.eval();
auto unbiasedParamsVec =
state.filtered() + K * (m - H * state.filtered());
auto unbiasedParamsCov =
state.filteredCovariance() - K * H * state.filteredCovariance();
return std::make_pair(unbiasedParamsVec, unbiasedParamsCov);
}
if (ipar == eUnbiased && !state.hasSmoothed() && !state.hasFiltered() &&
state.hasPredicted() && state.hasProjector() &&
state.hasCalibrated()) {
// Same calculation as above but using the predicted states.
auto m = state.effectiveCalibrated();
auto H = state.effectiveProjector();
auto V = state.effectiveCalibratedCovariance();
auto K =
(state.predictedCovariance() * H.transpose() *
(H * state.predictedCovariance() * H.transpose() - V).inverse())
.eval();
auto unbiasedParamsVec =
state.predicted() + K * (m - H * state.predicted());
auto unbiasedParamsCov =
state.predictedCovariance() - K * H * state.predictedCovariance();
return std::make_pair(unbiasedParamsVec, unbiasedParamsCov);
}
return std::nullopt;
};

Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/tests/root_file_hashes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_truth_tracking_kalman[odd-1000.0]__tracksummary_fitter.root: 3d424dec9b172f
test_truth_tracking_kalman[odd-1000.0]__performance_track_finder.root: 39aec6316cceb90e314e16b02947faa691c18f57c3a851a25e547a8fc05a4593
test_truth_tracking_gsf[generic]__trackstates_gsf.root: e971da3dcc1997bc9f8a74e0f75a46d4b92c9cf6286b0e05dc8a1bd34df75444
test_truth_tracking_gsf[generic]__tracksummary_gsf.root: ec3ef893f7138392bcdce96322e2dd31951737271b72ac9dd3282fc187700d03
test_truth_tracking_gsf[odd]__trackstates_gsf.root: c28b23358cf88fb40eeb3c47db9af62462cc7cdd9d70dec13d0615f136065191
test_truth_tracking_gsf[odd]__trackstates_gsf.root: f4dba7c0d9a43ab2a249e624b3411c550f7462bac30fe9f85745aab742e15dea
test_truth_tracking_gsf[odd]__tracksummary_gsf.root: 3425c0974943e0dac06dfedceaf1e9e3bec3bdc6ff73588d849a234de017e230
test_particle_gun__particles.root: 7eec62018b6944fea565dad75aa41ef87d1f2737b2a814fbab189817ac8180fe
test_material_mapping__material-map_tracks.root: 6e1441c418ff0b17983c2d0483248cc1dee6b77b09d0ca9d03c742c9d1373630
Expand Down Expand Up @@ -95,9 +95,9 @@ test_truth_tracking_kalman[generic-True-1000.0]__trackstates_fitter.root: bdc70d
test_truth_tracking_kalman[generic-True-1000.0]__tracksummary_fitter.root: fc82abfc4e3016cda806e743a270bf78b6d4cc404cd52145ea1eabed85d32feb
test_truth_tracking_kalman[odd-False-0.0]__trackstates_fitter.root: d0a9203c917be9caacd1c6c4244538e2038e2472b4707b61bb5c0bb1c5e2a3ad
test_truth_tracking_kalman[odd-False-0.0]__tracksummary_fitter.root: a5af8190f5981e7fa2556f20027af32b383bc07259927a58116d2676e5971dbe
test_truth_tracking_kalman[odd-False-1000.0]__trackstates_fitter.root: b858d09a75e852a7c23f2f3a512de8c334c593e700319d4f935e844ec00c379f
test_truth_tracking_kalman[odd-False-1000.0]__trackstates_fitter.root: 24aed25ba31599d6d74919667703bc9a1c6f063d955a6e92e0ce51924a2c6a4f
test_truth_tracking_kalman[odd-False-1000.0]__tracksummary_fitter.root: 3d424dec9b172f253c8c4ffbda470f678fd1081a3d36dcfea517ab0f94995ae4
test_truth_tracking_kalman[odd-True-0.0]__trackstates_fitter.root: d0a9203c917be9caacd1c6c4244538e2038e2472b4707b61bb5c0bb1c5e2a3ad
test_truth_tracking_kalman[odd-True-0.0]__tracksummary_fitter.root: a5af8190f5981e7fa2556f20027af32b383bc07259927a58116d2676e5971dbe
test_truth_tracking_kalman[odd-True-1000.0]__trackstates_fitter.root: b858d09a75e852a7c23f2f3a512de8c334c593e700319d4f935e844ec00c379f
test_truth_tracking_kalman[odd-True-1000.0]__trackstates_fitter.root: 24aed25ba31599d6d74919667703bc9a1c6f063d955a6e92e0ce51924a2c6a4f
test_truth_tracking_kalman[odd-True-1000.0]__tracksummary_fitter.root: 3d424dec9b172f253c8c4ffbda470f678fd1081a3d36dcfea517ab0f94995ae4

0 comments on commit 9fcfb7e

Please sign in to comment.