Belle II Software development
BestMatchSelector.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/findlets/base/Findlet.h>
11
12#include <tracking/trackFindingCDC/numerics/WeightComperator.h>
13
14#include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
15#include <tracking/trackFindingCDC/utilities/Algorithms.h>
16
17#include <algorithm>
18#include <vector>
19
20namespace Belle2 {
25 namespace TrackFindingCDC {
42 template <class ACollectorItem, class ACollectionItem>
44 public Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>> {
45 public:
48
51
53 void apply(std::vector<WeightedRelationItem>& weightedRelations) override
54 {
55 std::vector<WeightedRelationItem> selectedWeightedRelations;
56
57 // Do until there are no more relations left:
58 // (1) find the relation with the maximum weight
59 // (2) store this and delete all relations, which share a "To" or a "From" item with this maximal relation
60 // (3) repeat
61 while (not weightedRelations.empty()) {
62 // std:min_element is strange... this actually returns the element with the largest weight
63 const auto maxElement = *(std::min_element(weightedRelations.begin(), weightedRelations.end(), GreaterWeight()));
64 selectedWeightedRelations.push_back(maxElement);
65
66 const auto itemSharesFromOrTo = [&maxElement](const WeightedRelationItem & item) {
67 return item.getFrom() == maxElement.getFrom() or item.getTo() == maxElement.getTo();
68 };
69
70 erase_remove_if(weightedRelations, itemSharesFromOrTo);
71 }
72
73 std::sort(selectedWeightedRelations.begin(), selectedWeightedRelations.end());
74 weightedRelations.swap(selectedWeightedRelations);
75 }
76 };
77 }
79}
Selector to remove all relations in the list, which share the same collection item - except the one w...
void apply(std::vector< WeightedRelationItem > &weightedRelations) override
Main function of this class doing the relation selection.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
Type for two related objects with a weight.
Abstract base class for different kinds of events.
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:127