Belle II Software development
ChoosableFromVarSetFilter< ATruthVarSet > Class Template Reference

Convince template to create a filter returning on variable from a set of variables. More...

#include <ChoosableFromVarSetFilter.dcl.h>

Inheritance diagram for ChoosableFromVarSetFilter< ATruthVarSet >:
ChoosableFromVarSet< Filter< ATruthVarSet::Object > > OnVarSet< Filter< ATruthVarSet::Object > > Filter< ATruthVarSet::Object > CompositeProcessingSignalListener ProcessingSignalListener TruthVarFilter< ATruthVarSet > Sloppy< TruthVarFilter< ATruthVarSet > >

Public Types

using Object = typename ATruthVarSet::Object
 Type of the filtered object.
 
using Interface
 Mark this class as the basic interface.
 

Public Member Functions

 ChoosableFromVarSetFilter (const std::string &varName="")
 Constructor.
 
 ~ChoosableFromVarSetFilter ()
 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.
 
virtual Weight operator() (const Object &obj)
 Function to evaluate the object.
 
Weight operator() (const Object *obj)
 Function to evaluate the object.
 
virtual std::vector< float > operator() (const std::vector< Object * > &objs)
 Function to evaluate a vector of objects Base implementation applies the function to each object.
 
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.
 
void beginRun () override
 Receive and dispatch signal for the beginning of a new run.
 
void beginEvent () override
 Receive and dispatch signal for the start of a new event.
 
void endRun () override
 Receive and dispatch signal for the end of the run.
 
void terminate () override
 Receive and dispatch Signal for termination of the event processing.
 

Protected Member Functions

AVarSetgetVarSet () const
 Getter for the set of variables.
 
void setVarSet (std::unique_ptr< AVarSet > varSet)
 Setter for the set of variables.
 
void addProcessingSignalListener (ProcessingSignalListener *psl)
 Register a processing signal listener to be notified.
 
int getNProcessingSignalListener ()
 Get the number of currently registered listeners.
 

Private Types

using Super = ChoosableFromVarSet<Filter<typename ATruthVarSet::Object>>
 Type of the super class.
 
using AVarSet
 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.
 
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
 References to subordinary signal processing listener contained in this findlet.
 
bool m_initialized
 Flag to keep track whether initialization happened before.
 
bool m_terminated
 Flag to keep track whether termination happened before.
 
std::string m_initializedAs
 Name of the type during initialisation.
 

Detailed Description

template<class ATruthVarSet>
class Belle2::TrackFindingCDC::ChoosableFromVarSetFilter< ATruthVarSet >

Convince template to create a filter returning on variable from a set of variables.

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

Member Typedef Documentation

◆ AVarSet

using AVarSet
privateinherited

Type of the variable set.

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

◆ Interface

using Interface
inherited

Mark this class as the basic interface.

Definition at line 38 of file Filter.dcl.h.

◆ Object

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

Type of the filtered object.

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

◆ Super

template<class ATruthVarSet>
using Super = ChoosableFromVarSet<Filter<typename ATruthVarSet::Object>>
private

Type of the super class.

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

Constructor & Destructor Documentation

◆ ChoosableFromVarSetFilter()

template<class AVarSet>
ChoosableFromVarSetFilter ( const std::string & varName = "")

Constructor.

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

95 : Super(std::make_unique<AVarSet>(), varName)
96 {
97 }

Member Function Documentation

◆ addProcessingSignalListener()

void addProcessingSignalListener ( ProcessingSignalListener * psl)
protectedinherited

Register a processing signal listener to be notified.

Definition at line 53 of file CompositeProcessingSignalListener.cc.

56{
58}
Base class for filters on a generic object type.
Definition Filter.dcl.h:31

◆ beginEvent()

void beginEvent ( )
overrideinherited

Receive and dispatch signal for the start of a new event.

Definition at line 36 of file CompositeProcessingSignalListener.cc.

32{
35 psl->beginEvent();
36 }
37}
void beginEvent() override
Receive and dispatch signal for the start of a new event.
virtual void beginEvent()
Receive signal for the start of a new event.

◆ beginRun()

void beginRun ( )
overrideinherited

Receive and dispatch signal for the beginning of a new run.

Definition at line 33 of file CompositeProcessingSignalListener.cc.

24{
27 psl->beginRun();
28 }
29}
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
virtual void beginRun()
Receive signal for the beginning of a new run.

◆ endRun()

void endRun ( )
overrideinherited

Receive and dispatch signal for the end of the run.

Definition at line 39 of file CompositeProcessingSignalListener.cc.

40{
42 psl->endRun();
43 }
45}
void endRun() override
Receive and dispatch signal for the end of the run.
virtual void endRun()
Receive signal for the end of the run.

◆ exposeParameters()

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

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

Reimplemented from OnVarSet< Filter< ATruthVarSet::Object > >.

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

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 }

◆ getNProcessingSignalListener()

int getNProcessingSignalListener ( )
protectedinherited

Get the number of currently registered listeners.

Definition at line 56 of file CompositeProcessingSignalListener.cc.

61{
63}

◆ getVarSet()

auto getVarSet ( ) const
protectedinherited

Getter for the set of variables.

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

82 {
83 return *m_varSet;
84 }

◆ initialize()

void initialize ( )
overridevirtualinherited

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

Reimplemented from ProcessingSignalListener.

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 }

◆ needsTruthInformation()

bool needsTruthInformation ( )
overrideinherited

Checks if any variables need Monte Carlo information.

Definition at line 52 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/4]

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/4]

Weight operator() ( const Object & obj)
virtualinherited

Function to evaluate the object.

Base implementation accepts all objects.

Parameters
objThe object to be accepted or rejected.
Returns
A finite float value if the object is accepted. NAN if the object is rejected.

Reimplemented in TruthVarFilter< ATruthVarSet >.

Definition at line 59 of file Filter.icc.h.

47 {
48 return 1;
49 }

◆ operator()() [3/4]

Weight operator() ( const Object * obj)
inherited

Function to evaluate the object.

Base implementation accepts all objects, except nullptr.

Parameters
objThe object to be accepted or rejected.
Returns
A finit float value if the object is accepted. NAN if the object is rejected. Nullptr is always rejected.

Definition at line 69 of file Filter.icc.h.

53 {
54 return obj ? operator()(*obj) : NAN;
55 }

◆ operator()() [4/4]

std::vector< float > operator() ( const std::vector< Object * > & objs)
virtualinherited

Function to evaluate a vector of objects Base implementation applies the function to each object.

Can be optimized for MVA filters

Parameters
objsA vector of pointers to objects
Returns
A vector of float or NAN values. See above

Definition at line 77 of file Filter.icc.h.

59 {
60 std::vector<float> out;
61 for (const auto& obj : objs) {
62 out.push_back(operator()(obj));
63 }
64 return out;
65 }

◆ releaseVarSet()

auto releaseVarSet ( ) &&
inherited

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

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

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

◆ setVarSet()

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

Setter for the set of variables.

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

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

◆ terminate()

void terminate ( )
overrideinherited

Receive and dispatch Signal for termination of the event processing.

Definition at line 42 of file CompositeProcessingSignalListener.cc.

48{
50 psl->terminate();
51 }
53}
void terminate() override
Receive and dispatch Signal for termination of the event processing.
virtual void terminate()
Receive Signal for termination of the event processing.

Member Data Documentation

◆ m_initialized

bool m_initialized
privateinherited

Flag to keep track whether initialization happened before.

Definition at line 52 of file ProcessingSignalListener.h.

◆ m_initializedAs

std::string m_initializedAs
privateinherited

Name of the type during initialisation.

Definition at line 58 of file ProcessingSignalListener.h.

◆ 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_subordinaryProcessingSignalListeners

std::vector<ProcessingSignalListener*> m_subordinaryProcessingSignalListeners
privateinherited

References to subordinary signal processing listener contained in this findlet.

Definition at line 60 of file CompositeProcessingSignalListener.h.

◆ m_terminated

bool m_terminated
privateinherited

Flag to keep track whether termination happened before.

Definition at line 55 of file ProcessingSignalListener.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 74 of file FilterOnVarSet.dcl.h.


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