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

template<class AFilter>
using AVarSet = BaseVarSet<Object>
private

Type of the variable set.

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

◆ Object

template<class AFilter>
using Object = typename AFilter::Object

Type of the filtered object.

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

◆ Super

template<class AFilter>
using Super = OnVarSet<AFilter>
private

Type of the super class.

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

Constructor & Destructor Documentation

◆ ChoosableFromVarSet()

template<class AFilter>
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 }

Member Function Documentation

◆ exposeParameters()

template<class AFilter>
void exposeParameters ( ModuleParamList * parameterList,
const std::string & prefix )
overridevirtual

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

Reimplemented from OnVarSet< AFilter >.

Reimplemented in Sloppy< TruthVarFilter< ATruthVarSet > >, and Sloppy< TruthVarFilter< ATruthVarSet > >.

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"),
48 m_param_varName,
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"),
54 m_param_varName,
55 "Choose the name of the variable "
56 "that will be put out as a weight.",
57 m_param_varName);
58 }
59 }

◆ getVarSet()

template<class AFilter>
auto getVarSet ( ) const
protectedinherited

Getter for the set of variables.

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

82 {
83 return *m_varSet;
84 }

◆ initialize()

template<class AFilter>
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 {
64 Super::initialize();
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 }

◆ needsTruthInformation()

template<class AFilter>
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()()

template<class AFilter>
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 }

◆ releaseVarSet()

template<class AFilter>
auto releaseVarSet ( ) &&
inherited

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

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

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

◆ setVarSet()

template<class AFilter>
void setVarSet ( std::unique_ptr< AVarSet > varSet)
protectedinherited

Setter for the set of variables.

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

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

Member Data Documentation

◆ m_param_varName

template<class AFilter>
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

template<class AFilter>
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

template<class AFilter>
std::unique_ptr<AVarSet> m_varSet
privateinherited

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

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


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