Belle II Software development
WeightedRelationCreator.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/eventdata/utils/ClassMnemomics.h>
13
14#include <tracking/trackFindingCDC/filters/base/RelationFilterUtil.h>
15
16#include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
17
18#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
19#include <tracking/trackFindingCDC/utilities/Functional.h>
20
21#include <framework/core/ModuleParamList.h>
22#include <framework/logging/Logger.h>
23
24#include <vector>
25#include <string>
26#include <algorithm>
27
28namespace Belle2 {
35 namespace TrackFindingCDC {
36
47 template <class AObject, class ARelationFilter>
48 class WeightedRelationCreator : public Findlet<AObject* const, WeightedRelation<AObject>> {
49
50 private:
53
54 public:
57 {
59 }
60
62 std::string getDescription() final {
63 return "Constructs geometrically constrained relations between " +
64 getClassMnemomicParameterDescription((AObject*)nullptr) +
65 " filter by some acceptance criterion.";
66 }
67
69 void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) final {
70 m_relationFilter.exposeParameters(moduleParamList, prefix);
71 moduleParamList->addParameter(prefixed(prefix, "onlyBest"),
73 "Maximal number of the best relation to keep from each " +
74 getClassMnemomicParameterDescription((AObject*)nullptr),
76 }
77
79 void apply(const std::vector<AObject*>& inputObjects,
80 std::vector<WeightedRelation<AObject>>& weightedRelations) final {
81
82 B2ASSERT("Expected the objects on which relations are constructed to be sorted",
83 std::is_sorted(inputObjects.begin(), inputObjects.end(), LessOf<Deref>()));
84
85 RelationFilterUtil::appendUsing(m_relationFilter, inputObjects, weightedRelations);
86
87 if (m_param_onlyBest > 0)
88 {
89 const int nMaxRepetitions = m_param_onlyBest;
90 int nCurrentRepetitions = 1;
91 auto sameFrom =
92 [&nMaxRepetitions,
93 &nCurrentRepetitions](const WeightedRelation<AObject>& relation,
94 const WeightedRelation<AObject>& otherRelation) -> bool {
95 if (relation.getFrom() == otherRelation.getFrom())
96 {
97 ++nCurrentRepetitions;
98 return nCurrentRepetitions > nMaxRepetitions;
99 } else {
100 // cppcheck-suppress unreadVariable
101 nCurrentRepetitions = 1;
102 return false;
103 }
104 };
105
106 auto itLast = std::unique(weightedRelations.begin(), weightedRelations.end(), sameFrom);
107 weightedRelations.erase(itLast, weightedRelations.end());
108 }
109 }
110
111 private:
113 ARelationFilter m_relationFilter;
114
117 };
118 }
120}
The Module parameter list class.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
Findlet that combines geometrical constrained pairs of objects to relations and selects them by the f...
std::string getDescription() final
Short description of the findlet.
WeightedRelationCreator()
Constructor registering the subordinary findlets to the processing signal distribution machinery.
void apply(const std::vector< AObject * > &inputObjects, std::vector< WeightedRelation< AObject > > &weightedRelations) final
Main function.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
ARelationFilter m_relationFilter
Relation filter used to select relations.
int m_param_onlyBest
Parameter : Maximal number of the best relations from each item to keep.
Type for two related objects with a weight.
std::string getClassMnemomicParameterDescription(const RecoTrack *dispatchTag)
Returns a short description for class RecoTrack to be used in descriptions of parameters.
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
static void appendUsing(ARelationFilter &relationFilter, const std::vector< AObject * > &froms, const std::vector< AObject * > &tos, std::vector< WeightedRelation< AObject > > &weightedRelations, unsigned int maximumNumberOfRelations=std::numeric_limits< unsigned int >::max())
Appends relations between elements in the given AItems using the ARelationFilter.