Belle II Software  release-05-01-25
ChoosableFromVarSetFilter.icc.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/filters/base/ChoosableFromVarSetFilter.dcl.h>
13 
14 #include <tracking/trackFindingCDC/filters/base/FilterOnVarSet.icc.h>
15 
16 #include <framework/core/ModuleParamList.templateDetails.h>
17 
18 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
19 
20 #include <string>
21 #include <memory>
22 
23 namespace Belle2 {
28  namespace TrackFindingCDC {
29 
30  template <class AFilter>
31  ChoosableFromVarSet<AFilter>::ChoosableFromVarSet(std::unique_ptr<AVarSet> varSet,
32  std::string varName)
33  : Super(std::move(varSet))
34  , m_param_varName(varName)
35  {
36  }
37 
38  template <class AFilter>
40 
41  template <class AFilter>
43  const std::string& prefix)
44  {
45  Super::exposeParameters(moduleParamList, prefix);
46 
47  if (m_param_varName == "") {
48  // Make a forced parameter if no default variable name is present
49  moduleParamList->addParameter(prefixed(prefix, "chosenVariable"),
50  m_param_varName,
51  "Choose the name of the variable "
52  "that will be put out as a weight.");
53  } else {
54  // Normal unforced parameter if default name is present
55  moduleParamList->addParameter(prefixed(prefix, "chosenVariable"),
56  m_param_varName,
57  "Choose the name of the variable "
58  "that will be put out as a weight.",
59  m_param_varName);
60  }
61  }
62 
63  template <class AFilter>
64  void ChoosableFromVarSet<AFilter>::initialize()
65  {
66  Super::initialize();
67  MayBePtr<Float_t> foundVariable = Super::getVarSet().find(m_param_varName);
68  if (not foundVariable) {
69  B2ERROR("Could not find request variable name " << m_param_varName << " in variable set");
70  B2INFO("Valid names are: ");
71  std::vector<Named<Float_t*>> namedVariables = Super::getVarSet().getNamedVariables();
72  for (const Named<Float_t*>& namedVariable : namedVariables) {
73  std::string name = namedVariable.getName();
74  B2INFO("* " << name);
75  }
76  }
77  m_variable = foundVariable;
78  }
79 
80  template <class AFilter>
81  Weight ChoosableFromVarSet<AFilter>::operator()(const Object& object)
82  {
83  Weight extracted = Super::operator()(object);
84  if (std::isnan(extracted)) {
85  return NAN;
86  } else {
87  if (m_variable) {
88  return *m_variable;
89  } else {
90  return NAN;
91  }
92  }
93  }
94 
95  template <class AVarSet>
96  ChoosableFromVarSetFilter<AVarSet>::ChoosableFromVarSetFilter(const std::string& varName)
97  : Super(std::make_unique<AVarSet>(), varName)
98  {
99  }
100 
101  template <class AVarSet>
102  ChoosableFromVarSetFilter<AVarSet>::~ChoosableFromVarSetFilter() = default;
103  }
105 }
Belle2::TrackFindingCDC::Named< Float_t * >
Belle2::TrackFindingCDC::ChoosableFromVarSet
Filter adapter to make a filter work on a set of variables and return on variable as the result of th...
Definition: ChoosableFromVarSetFilter.dcl.h:42
Belle2::ModuleParamList::addParameter
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Definition: ModuleParamList.templateDetails.h:38
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ChoosableFromVarSet::ChoosableFromVarSet
ChoosableFromVarSet(std::unique_ptr< AVarSet > varSet, std::string varName="")
Constructor taking the variable set the filter should work on and the default name of the variable to...
Definition: ChoosableFromVarSetFilter.icc.h:39
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46