File indexing completed on 2025-01-18 09:11:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/TrackFitting/GsfMixtureReduction.hpp"
0010
0011 #include "Acts/TrackFitting/detail/SymmetricKlDistanceMatrix.hpp"
0012
0013 #include <algorithm>
0014
0015 template <typename proj_t, typename angle_desc_t>
0016 void reduceWithKLDistanceImpl(std::vector<Acts::GsfComponent> &cmpCache,
0017 std::size_t maxCmpsAfterMerge, const proj_t &proj,
0018 const angle_desc_t &desc) {
0019 Acts::detail::SymmetricKLDistanceMatrix distances(cmpCache, proj);
0020
0021 auto remainingComponents = cmpCache.size();
0022
0023 while (remainingComponents > maxCmpsAfterMerge) {
0024 const auto [minI, minJ] = distances.minDistancePair();
0025
0026
0027 cmpCache[minI] =
0028 mergeComponents(cmpCache[minI], cmpCache[minJ], proj, desc);
0029 distances.recomputeAssociatedDistances(minI, cmpCache, proj);
0030
0031
0032
0033 proj(cmpCache[minJ]).weight = -1.0;
0034 distances.maskAssociatedDistances(minJ);
0035
0036 remainingComponents--;
0037 }
0038
0039
0040 std::ranges::sort(cmpCache, {},
0041 [&](const auto &c) { return proj(c).weight; });
0042 cmpCache.erase(
0043 std::remove_if(cmpCache.begin(), cmpCache.end(),
0044 [&](const auto &a) { return proj(a).weight == -1.0; }),
0045 cmpCache.end());
0046
0047 assert(cmpCache.size() == maxCmpsAfterMerge && "size mismatch");
0048 }
0049
0050 namespace Acts {
0051
0052 void reduceMixtureLargestWeights(std::vector<GsfComponent> &cmpCache,
0053 std::size_t maxCmpsAfterMerge,
0054 const Surface & ) {
0055 if (cmpCache.size() <= maxCmpsAfterMerge) {
0056 return;
0057 }
0058
0059 std::nth_element(
0060 cmpCache.begin(), cmpCache.begin() + maxCmpsAfterMerge, cmpCache.end(),
0061 [](const auto &a, const auto &b) { return a.weight > b.weight; });
0062 cmpCache.resize(maxCmpsAfterMerge);
0063 }
0064
0065 void reduceMixtureWithKLDistance(std::vector<Acts::GsfComponent> &cmpCache,
0066 std::size_t maxCmpsAfterMerge,
0067 const Surface &surface) {
0068 if (cmpCache.size() <= maxCmpsAfterMerge) {
0069 return;
0070 }
0071
0072 auto proj = [](auto &a) -> decltype(auto) { return a; };
0073
0074
0075
0076 detail::angleDescriptionSwitch(surface, [&](const auto &desc) {
0077 reduceWithKLDistanceImpl(cmpCache, maxCmpsAfterMerge, proj, desc);
0078 });
0079 }
0080
0081 }