Belle II Software development
ChoosableFromVarSet< AFilter > Class Template Reference

Filter adapter to make a filter work on a set of variables and return on variable as the result of the filter. More...

#include <ChoosableFromVarSetFilter.dcl.h>

Inheritance diagram for ChoosableFromVarSet< AFilter >:
OnVarSet< AFilter >

Public Types

using Object = typename AFilter::Object
 Type of the filtered object.
 

Public Member Functions

 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 be used.
 
 ~ChoosableFromVarSet ()
 Default destructor.
 
void exposeParameters (ModuleParamList *parameterList, const std::string &prefix) override
 Add the parameters of this filter to the given parameter list.
 
void initialize () override
 Initialisation method sets up a reference to the value in the variable set to be returned.
 
Weight operator() (const Object &object) override
 Returns the variable with the set requested name from the variable set.
 
bool needsTruthInformation () override
 Checks if any variables need Monte Carlo information.
 
std::unique_ptr< AVarSetreleaseVarSet () &&
 Steal the set of variables form this filter - filter becomes dysfunctional afterwards.
 

Protected Member Functions

AVarSetgetVarSet () const
 Getter for the set of variables.
 
void setVarSet (std::unique_ptr< AVarSet > varSet)
 Setter for the set of variables.
 

Private Types

using Super = OnVarSet< AFilter >
 Type of the super class.
 
using AVarSet = BaseVarSet< Object >
 Type of the variable set.
 

Private Attributes

std::string m_param_varName
 Memory for the name of the variable selected as the return value of the filter.
 
Float_t * m_variable = nullptr
 Reference to the location of the value in the variable set to be returned.
 
std::unique_ptr< AVarSetm_varSet
 Instance of the variable set to be used in the filter.
 

Detailed Description

template<class AFilter>
class Belle2::TrackFindingCDC::ChoosableFromVarSet< AFilter >

Filter adapter to make a filter work on a set of variables and return on variable as the result of the filter.

Definition at line 32 of file ChoosableFromVarSetFilter.dcl.h.

Member Typedef Documentation

◆ AVarSet

using AVarSet = BaseVarSet<Object>
private

Type of the variable set.

Definition at line 44 of file ChoosableFromVarSetFilter.dcl.h.

◆ Object

using Object = typename AFilter::Object

Type of the filtered object.

Definition at line 40 of file ChoosableFromVarSetFilter.dcl.h.

◆ Super

using Super = OnVarSet<AFilter>
private

Type of the super class.

Definition at line 36 of file ChoosableFromVarSetFilter.dcl.h.

Constructor & Destructor Documentation

◆ 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 be used.

Definition at line 29 of file ChoosableFromVarSetFilter.icc.h.

31 : Super(std::move(varSet))
32 , m_param_varName(varName)
33 {
34 }
OnVarSet< AFilter > Super
Type of the super class.
std::string m_param_varName
Memory for the name of the variable selected as the return value of the filter.

Member Function Documentation

◆ exposeParameters()

void exposeParameters ( ModuleParamList parameterList,
const std::string &  prefix 
)
override

Add the parameters of this filter to the given parameter list.

Definition at line 40 of file ChoosableFromVarSetFilter.icc.h.

42 {
43 Super::exposeParameters(moduleParamList, prefix);
44
45 if (m_param_varName == "") {
46 // Make a forced parameter if no default variable name is present
47 moduleParamList->addParameter(prefixed(prefix, "chosenVariable"),
49 "Choose the name of the variable "
50 "that will be put out as a weight.");
51 } else {
52 // Normal unforced parameter if default name is present
53 moduleParamList->addParameter(prefixed(prefix, "chosenVariable"),
55 "Choose the name of the variable "
56 "that will be put out as a weight.",
58 }
59 }

◆ getVarSet()

auto getVarSet
protectedinherited

Getter for the set of variables.

Definition at line 80 of file FilterOnVarSet.icc.h.

81 {
82 return *m_varSet;
83 }
std::unique_ptr< AVarSet > m_varSet
Instance of the variable set to be used in the filter.

◆ initialize()

void initialize
override

Initialisation method sets up a reference to the value in the variable set to be returned.

Definition at line 62 of file ChoosableFromVarSetFilter.icc.h.

63 {
65 MayBePtr<Float_t> foundVariable = Super::getVarSet().find(m_param_varName);
66 if (not foundVariable) {
67 B2ERROR("Could not find request variable name " << m_param_varName << " in variable set");
68 B2INFO("Valid names are: ");
69 std::vector<Named<Float_t*>> namedVariables = Super::getVarSet().getNamedVariables();
70 for (const Named<Float_t*>& namedVariable : namedVariables) {
71 std::string name = namedVariable.getName();
72 B2INFO("* " << name);
73 }
74 }
75 m_variable = foundVariable;
76 }
virtual MayBePtr< Float_t > find(const std::string &varName)
Pointer to the variable with the given name.
Definition: BaseVarSet.h:105
virtual std::vector< Named< Float_t * > > getNamedVariables(const std::string &prefix)
Getter for the named references to the individual variables Base implementation returns empty vector.
Definition: BaseVarSet.h:67
Float_t * m_variable
Reference to the location of the value in the variable set to be returned.
void initialize() override
No reassignment of variable set possible for now.
AVarSet & getVarSet() const
Getter for the set of variables.

◆ needsTruthInformation()

bool needsTruthInformation
overrideinherited

Checks if any variables need Monte Carlo information.

Definition at line 49 of file FilterOnVarSet.icc.h.

50 {
51 bool result = Super::needsTruthInformation();
52 if (result) return true;
53
54 const std::vector<Named<Float_t*>>& namedVariables = m_varSet->getNamedVariables();
55 for (const Named<Float_t*>& namedVariable : namedVariables) {
56 std::string name = namedVariable.getName();
57 // If the name contains the word truth it is considered to have Monte carlo information.
58 if (name.find("truth") != std::string::npos) {
59 return true;
60 }
61 }
62 return false;
63 }

◆ operator()()

Weight operator() ( const Object object)
override

Returns the variable with the set requested name from the variable set.

Definition at line 79 of file ChoosableFromVarSetFilter.icc.h.

80 {
81 Weight extracted = Super::operator()(object);
82 if (std::isnan(extracted)) {
83 return NAN;
84 } else {
85 if (m_variable) {
86 return *m_variable;
87 } else {
88 return NAN;
89 }
90 }
91 }
Weight operator()(const Object &obj) override
Function extracting the variables of the object into the variable set.

◆ releaseVarSet()

auto releaseVarSet ( ) &&
inherited

Steal the set of variables form this filter - filter becomes dysfunctional afterwards.

Definition at line 75 of file FilterOnVarSet.icc.h.

75 {
76 return std::move(m_varSet);
77 }

◆ setVarSet()

void setVarSet ( std::unique_ptr< AVarSet varSet)
protectedinherited

Setter for the set of variables.

Definition at line 86 of file FilterOnVarSet.icc.h.

87 {
88 m_varSet = std::move(varSet);
89 }

Member Data Documentation

◆ m_param_varName

std::string m_param_varName
private

Memory for the name of the variable selected as the return value of the filter.

Definition at line 67 of file ChoosableFromVarSetFilter.dcl.h.

◆ m_variable

Float_t* m_variable = nullptr
private

Reference to the location of the value in the variable set to be returned.

Definition at line 70 of file ChoosableFromVarSetFilter.dcl.h.

◆ m_varSet

std::unique_ptr<AVarSet> m_varSet
privateinherited

Instance of the variable set to be used in the filter.

Definition at line 71 of file FilterOnVarSet.dcl.h.


The documentation for this class was generated from the following files: