Belle II Software development
TruthVarFilter< ATruthVarSet > Class Template Reference

MC Filter Type using a VarSet and the truth variable in it. More...

#include <TruthVarFilter.dcl.h>

Inheritance diagram for TruthVarFilter< ATruthVarSet >:
ChoosableFromVarSetFilter< ATruthVarSet > ChoosableFromVarSet< Filter< ATruthVarSet::Object > > OnVarSet< AFilter >

Public Types

using Object = typename Super::Object
 Type of the handled object.
 

Public Member Functions

 TruthVarFilter ()
 Constructor.
 
 ~TruthVarFilter ()
 Default destructor.
 
Weight operator() (const Object &object) override
 Reject an item if the truth variable is 0, else accept it.
 
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 = ChoosableFromVarSetFilter< ATruthVarSet >
 Type of the base 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
 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 ATruthVarSet>
class Belle2::TrackFindingCDC::TruthVarFilter< ATruthVarSet >

MC Filter Type using a VarSet and the truth variable in it.

Definition at line 20 of file TruthVarFilter.dcl.h.

Member Typedef Documentation

◆ AVarSet

using AVarSet = BaseVarSet<Object>
privateinherited

Type of the variable set.

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

◆ Object

using Object = typename Super::Object

Type of the handled object.

Definition at line 28 of file TruthVarFilter.dcl.h.

◆ Super

using Super = ChoosableFromVarSetFilter<ATruthVarSet>
private

Type of the base class.

Definition at line 24 of file TruthVarFilter.dcl.h.

Constructor & Destructor Documentation

◆ TruthVarFilter()

Constructor.

Definition at line 26 of file TruthVarFilter.icc.h.

27 : Super("truth")
28 {
29 }
ChoosableFromVarSetFilter< ATruthVarSet > Super
Type of the base class.

Member Function Documentation

◆ exposeParameters()

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

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

Definition at line 57 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()

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
overrideinherited

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

Definition at line 60 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 }
Float_t * m_variable
Reference to the location of the value in the variable set to be returned.

◆ 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()() [1/2]

Weight operator() ( const Object object)
overrideinherited

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

Definition at line 63 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 }

◆ operator()() [2/2]

auto operator() ( const Object object)
override

Reject an item if the truth variable is 0, else accept it.

Definition at line 35 of file TruthVarFilter.icc.h.

35 {
36 Weight value = Super::operator()(object);
37 if (std::isnan(value) or value == 0) return NAN;
38 return 1.0;
39 }
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
privateinherited

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
privateinherited

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: