12 #include <tracking/trackFindingCDC/findlets/base/Findlet.h>
14 #include <tracking/trackFindingCDC/numerics/WeightComperator.h>
16 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
17 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
19 #include <framework/core/ModuleParamList.h>
20 #include <framework/logging/Logger.h>
27 namespace TrackFindingCDC {
45 template <
class ACollectorItem,
class ACollectionItem,
class AComparer = std::less<const ACollectionItem*>>
46 class SingleMatchSelector :
47 public Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>> {
53 using Super = Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>>;
61 "Use only the found candidate, if it is the only one. Otherwise, use the best one.",
66 void apply(std::vector<WeightedRelationItem>& weightedRelations)
override
68 B2ASSERT(
"The relations need to be sorted for this selector!",
69 std::is_sorted(weightedRelations.begin(), weightedRelations.end()));
72 std::map<const ACollectionItem*, std::vector<WeightedRelationItem>, AComparer> collectionItemToMatchedMap;
75 collectionItemToMatchedMap[relation.getTo()].push_back(relation);
79 weightedRelations.clear();
81 for (
const auto& collectionItemToMatches : collectionItemToMatchedMap) {
82 const auto& matches = collectionItemToMatches.second;
84 const auto& bestMatch = std::min_element(matches.begin(), matches.end(),
GreaterWeight());
89 weightedRelations.push_back(*bestMatch);
93 std::sort(weightedRelations.begin(), weightedRelations.end());