Skip to content

Commit

Permalink
refactor: Remove GSF meta cache (#2448)
Browse files Browse the repository at this point in the history
The meta cache is a remainder of an older version and not necessary in the current implementation.

No changes in the `tracksummary_gsf.root` as expected. Difference in `trackstates_gsf.root` hashes should come from the pathlength entries, which is accumulated different now.
  • Loading branch information
benjaminhuth authored Sep 18, 2023
1 parent 8071832 commit 67be87d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 48 deletions.
60 changes: 14 additions & 46 deletions Core/include/Acts/TrackFitting/detail/GsfActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,13 @@ struct GsfActor {
/// Enforce default construction
GsfActor() = default;

/// Stores meta information about the components
struct MetaCache {
/// Where to find the parent component in the MultiTrajectory
MultiTrajectoryTraits::IndexType parentIndex = 0;

/// Other quantities TODO are they really needed here? seems they are
/// reinitialized to Identity etc.
BoundMatrix jacobian;
BoundToFreeMatrix jacToGlobal;
FreeMatrix jacTransport;
FreeVector derivative;

/// We need to preserve the path length
ActsScalar pathLength = 0;
};

/// Stores parameters of a gaussian component
struct ParameterCache {
struct ComponentCache {
ActsScalar weight = 0;
BoundVector boundPars;
BoundSquareMatrix boundCov;
BoundVector boundPars = BoundVector::Zero();
BoundSquareMatrix boundCov = BoundSquareMatrix::Identity();
};

/// Broadcast Cache Type
using ComponentCache = std::tuple<ParameterCache, MetaCache>;

/// Broadcast the result_type
using result_type = GsfResult<traj_t, ComponentCache>;

Expand Down Expand Up @@ -349,27 +330,19 @@ struct GsfActor {
for (auto [idx, cmp] : zip(tmpStates.tips, cmps)) {
auto proxy = tmpStates.traj.getTrackState(idx);

MetaCache mcache;
mcache.parentIndex = idx;
mcache.jacobian = cmp.jacobian();
mcache.jacToGlobal = cmp.jacToGlobal();
mcache.jacTransport = cmp.jacTransport();
mcache.derivative = cmp.derivative();
mcache.pathLength = cmp.pathAccumulated();

BoundTrackParameters bound(proxy.referenceSurface().getSharedPtr(),
proxy.filtered(), proxy.filteredCovariance());

applyBetheHeitler(state, navigator, bound, tmpStates.weights.at(idx),
mcache, componentCache);
componentCache);
}
}

template <typename propagator_state_t, typename navigator_t>
void applyBetheHeitler(const propagator_state_t& state,
const navigator_t& navigator,
const BoundTrackParameters& old_bound,
const double old_weight, const MetaCache& metaCache,
const double old_weight,
std::vector<ComponentCache>& componentCaches) const {
const auto& surface = *navigator.currentSurface(state.navigation);
const auto p_prev = old_bound.absoluteMomentum();
Expand Down Expand Up @@ -443,8 +416,7 @@ struct GsfActor {
"new cov not finite");

// Set the remaining things and push to vector
componentCaches.push_back(
{ParameterCache{new_weight, new_pars, new_cov}, metaCache});
componentCaches.push_back({new_weight, new_pars, new_cov});
}
}

Expand All @@ -455,7 +427,7 @@ struct GsfActor {
const auto final_cmp_number = std::min(
static_cast<std::size_t>(stepper.maxComponents), m_cfg.maxComponents);

auto proj = [](auto& a) -> decltype(auto) { return std::get<0>(a); };
auto proj = [](auto& a) -> decltype(auto) { return a; };

// We must differ between surface types, since there can be different
// local coordinates
Expand All @@ -469,7 +441,7 @@ struct GsfActor {
/// TODO This function does not expect normalized components, but this
/// could be redundant work...
void removeLowWeightComponents(std::vector<ComponentCache>& cmps) const {
auto proj = [](auto& cmp) -> double& { return std::get<0>(cmp).weight; };
auto proj = [](auto& cmp) -> double& { return cmp.weight; };

detail::normalizeWeights(cmps, proj);

Expand All @@ -482,7 +454,7 @@ struct GsfActor {
cmps = {*std::max_element(
cmps.begin(), cmps.end(),
[&](auto& a, auto& b) { return proj(a) < proj(b); })};
std::get<0>(cmps.front()).weight = 1.0;
cmps.front().weight = 1.0;
} else {
cmps.erase(new_end, cmps.end());
detail::normalizeWeights(cmps, proj);
Expand Down Expand Up @@ -531,9 +503,7 @@ struct GsfActor {
stepper.clearComponents(state.stepping);

// Finally loop over components
for (const auto& [pcache, meta] : componentCache) {
const auto& [weight, pars, cov] = pcache;

for (const auto& [weight, pars, cov] : componentCache) {
// Add the component to the stepper
BoundTrackParameters bound(surface.getSharedPtr(), pars, cov);

Expand All @@ -546,12 +516,10 @@ struct GsfActor {

auto& cmp = *res;
cmp.jacToGlobal() = surface.boundToFreeJacobian(state.geoContext, pars);
cmp.pathAccumulated() = meta.pathLength;

// TODO check if they are not anyways reset to identity or zero
cmp.jacobian() = meta.jacobian;
cmp.derivative() = meta.derivative;
cmp.jacTransport() = meta.jacTransport;
cmp.pathAccumulated() = state.stepping.pathAccumulated;
cmp.jacobian() = Acts::BoundMatrix::Identity();
cmp.derivative() = Acts::FreeVector::Zero();
cmp.jacTransport() = Acts::FreeMatrix::Identity();
}
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/Python/tests/root_file_hashes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ test_truth_tracking_kalman[odd-0.0]__performance_track_finder.root: 39aec6316cce
test_truth_tracking_kalman[odd-1000.0]__trackstates_fitter.root: a2069150737e39724829d76cc91de737be2f444ed08429ddefc7038032442af3
test_truth_tracking_kalman[odd-1000.0]__tracksummary_fitter.root: 94184e78b1f283eba74190c87fefe1123df0c9927d57ea32d2e2a3a927c126df
test_truth_tracking_kalman[odd-1000.0]__performance_track_finder.root: 39aec6316cceb90e314e16b02947faa691c18f57c3a851a25e547a8fc05a4593
test_truth_tracking_gsf[generic]__trackstates_gsf.root: 8249d82ebafe9b471cc51400b04ab3bf290ea10540109de7692bd590f52956b8
test_truth_tracking_gsf[generic]__trackstates_gsf.root: 5213bc01f5d44afd2686ab1a3775db010278c6f758e55eb78280c4750408b11c
test_truth_tracking_gsf[generic]__tracksummary_gsf.root: 4fe7e3e369d2c00244454422259a292c356f2d07d9340896a434b42ef05e55c8
test_truth_tracking_gsf[odd]__trackstates_gsf.root: a90adb31d19dedea9677864699a955cbae9787b0d55cc5eec5ab8610f0e48074
test_truth_tracking_gsf[odd]__trackstates_gsf.root: d85edebb449fb0945033ca6d29a04d293bf546be26e27bc22f987895568285db
test_truth_tracking_gsf[odd]__tracksummary_gsf.root: 14efdb194a6fa6e69587055b6f9818b4c5491235a8b8e96175f07814a3cbde97
test_particle_gun__particles.root: 8549ba6e20338004ab8ba299fc65e1ee5071985b46df8f77f887cb6fef56a8ec
test_material_mapping__material-map_tracks.root: 4e1c866038f0c06b099aa74fd01c3d875f07b89f54898f90debd9b558d8e4025
Expand Down

0 comments on commit 67be87d

Please sign in to comment.