10#include <tracking/trackFindingCDC/filters/base/FilterFactory.dcl.h>
12#include <tracking/trackFindingCDC/filters/base/AndFilter.icc.h>
13#include <tracking/trackFindingCDC/filters/base/NotFilter.icc.h>
15#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
17#include <framework/core/ModuleParamList.h>
19#include <framework/logging/Logger.h>
32 namespace TrackFindingCDC {
34 template <
class AFilter>
36 : m_defaultFilterName(defaultFilterName)
40 template <
class AFilter>
43 template <
class AFilter>
47 while (filterName ==
"false_positive" or filterName ==
"false_negative") {
48 std::string truthFilterName =
"truth";
49 std::unique_ptr<AFilter> truthFilter = this->create(truthFilterName);
50 std::unique_ptr<AFilter> defaultFilter = this->create(m_defaultFilterName);
52 if (not truthFilter or not defaultFilter)
break;
54 if (filterName ==
"false_positive") {
55 std::unique_ptr<AFilter> notTruthFilter =
56 std::make_unique<NotFilter<AFilter>>(std::move(truthFilter));
57 return std::make_unique<AndFilter<AFilter>>(std::move(notTruthFilter),
58 std::move(defaultFilter));
61 if (filterName ==
"false_negative") {
62 std::unique_ptr<AFilter> notDefaultFilter =
63 std::make_unique<NotFilter<AFilter>>(std::move(defaultFilter));
64 return std::make_unique<AndFilter<AFilter>>(std::move(notDefaultFilter),
65 std::move(truthFilter));
71 B2ERROR(
"Could not create filter with name " << filterName);
72 std::ostringstream message;
73 message <<
"Known filter names are: ";
74 std::vector<std::string> quotedFilterNames;
75 for (
const auto& filterNameAndDescription : getValidFilterNamesAndDescriptions()) {
76 const std::string& validFilterName = filterNameAndDescription.first;
77 quotedFilterNames.push_back(quoted(validFilterName));
79 message << join(
", ", quotedFilterNames);
81 B2ERROR(message.str());
82 return std::unique_ptr<AFilter>(
nullptr);
85 template<
class AFilter>
89 std::ostringstream oss;
90 oss << this->getFilterPurpose();
91 oss <<
"Allowed values are: ";
92 std::vector<std::string> filterNameAndDescriptions;
93 for (
const auto& filterNameAndDescription : this->getValidFilterNamesAndDescriptions()) {
94 const std::string& filterName = filterNameAndDescription.first;
95 const std::string& filterDescription = filterNameAndDescription.second;
96 filterNameAndDescriptions.push_back(quoted(filterName) +
" " + bracketed(filterDescription));
98 oss << join(
", ", filterNameAndDescriptions);
102 template<
class AFilter>
106 std::ostringstream oss;
107 oss <<
"Key -- value pairs depending on the filter." << std::endl;
108 for (
const auto& filterNameAndDescription : this->getValidFilterNamesAndDescriptions()) {
110 const std::string& filterName = filterNameAndDescription.first;
113 std::unique_ptr<AFilter>
filter = this->create(filterName);
115 B2WARNING(
"Could not create a filter for name " << filterName);
120 const std::string prefix =
"";
121 filter->exposeParameters(&moduleParamList, prefix);
123 std::map<std::string, std::string> filterParameters;
128 oss << quoted(filterName) <<
" :\n";
129 if (filterParameters.empty()) {
130 oss <<
"(no parameters)";
132 std::vector<std::string> parameterDescriptions;
133 for (
const auto& parameterNameAndDescription : filterParameters) {
134 const std::string& parameterName = parameterNameAndDescription.first;
135 const std::string& parameterDescription = parameterNameAndDescription.second;
136 parameterDescriptions.push_back(parameterName +
" -- " + parameterDescription);
138 oss << join(
",\n", parameterDescriptions);
145 template<
class AFilter>
148 return m_defaultFilterName;
The Module parameter list class.
std::string getParameterDescription(const std::string &name) const
Returns the description of a parameter given by its name.
std::vector< std::string > getParameterNames() const
Returns the names of all parameters in this parameter list.
virtual std::string createFiltersParametersDescription() const
Create a string with a description mentioning the parameters of the chooseable filter.
virtual std::unique_ptr< AFilter > create(const std::string &filterName) const
Create a filter with the given name, does not set filter specific parameters.
virtual ~FilterFactory()
Make destructor of interface class virtual.
FilterFactory(const std::string &defaultFilterName="")
Fill the default filter name values.
const std::string & getDefaultFilterName() const
Legacy - Return the default filter suggested by the factory.
virtual std::string createFiltersNameDescription() const
Create a string with a description mentioning the names of the chooseable filter.
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double > > &runs, double cut, std::map< ExpRun, std::pair< double, double > > &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Abstract base class for different kinds of events.