Belle II Software development
Recording< AFilter > Class Template Reference

Filter adapter to make a filter work on a set of variables and record the observed instances on invocation. More...

#include <RecordingFilter.dcl.h>

Inheritance diagram for Recording< AFilter >:
OnVarSet< AFilter > UnionRecording< typename AFilterFactory::CreatedFilter > UnionRecording< AFilter > UnionRecordingFilter< AxialSegmentPairFilterFactory > UnionRecordingFilter< ClusterFilterFactory > UnionRecordingFilter< FacetFilterFactory > UnionRecordingFilter< FacetRelationFilterFactory > UnionRecordingFilter< SegmentPairFilterFactory > UnionRecordingFilter< SegmentPairRelationFilterFactory > UnionRecordingFilter< SegmentRelationFilterFactory > UnionRecordingFilter< TrackRelationFilterFactory >

Public Types

using Object = typename AFilter::Object
 Type of the object to be analysed.
 

Public Member Functions

 Recording (std::unique_ptr< AVarSet > varSet, const std::string &defaultRootFileName="records.root", const std::string &defaultTreeName="records")
 Constructor of the filter.
 
 ~Recording ()
 Default destructor.
 
void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix) override
 Expose the set of parameters of the filter to the module parameter list.
 
void initialize () override
 Initialize the recorder before event processing.
 
void terminate () override
 Initialize the recorder after event processing.
 
Weight operator() (const Object &obj) final
 Function to evaluate the cluster for its backgroundness.
 
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

MayBePtr< AFilter > getSkimFilter () const
 Getter for the skim filter to select objects to be recorded.
 
void setSkimFilter (std::unique_ptr< AFilter > skimFilter)
 Setter for the skim filter to select objects to be recorded.
 
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 base class.
 
using AVarSet = BaseVarSet<Object>
 Type of the var set interface to be used.
 

Private Attributes

std::unique_ptr< Recorderm_recorder
 Recorder to write all variable sets of the encountered objects.
 
std::string m_param_rootFileName
 Name of the ROOT file to which shall be written.
 
std::string m_param_treeName
 Name of Tree to be written.
 
Weight m_param_returnWeight
 Returns Weight when this filter is called.
 
std::unique_ptr< AFilter > m_skimFilter = nullptr
 Skimming filter to select a subset of objects to be recorded.
 
std::unique_ptr< AVarSetm_varSet
 Instance of the variable set to be used in the filter.
 

Detailed Description

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

Filter adapter to make a filter work on a set of variables and record the observed instances on invocation.

Definition at line 34 of file RecordingFilter.dcl.h.

Member Typedef Documentation

◆ AVarSet

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

Type of the var set interface to be used.

Definition at line 46 of file RecordingFilter.dcl.h.

◆ Object

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

Type of the object to be analysed.

Definition at line 42 of file RecordingFilter.dcl.h.

◆ Super

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

Type of the base class.

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

Constructor & Destructor Documentation

◆ Recording()

template<class AFilter>
Recording ( std::unique_ptr< AVarSet > varSet,
const std::string & defaultRootFileName = "records.root",
const std::string & defaultTreeName = "records" )

Constructor of the filter.

Definition at line 30 of file RecordingFilter.icc.h.

33 : Super(std::move(varSet))
34 , m_recorder(nullptr)
35 , m_param_rootFileName(defaultRootFileName)
36 , m_param_treeName(defaultTreeName)
37 , m_param_returnWeight(NAN)
38 {}

Member Function Documentation

◆ exposeParameters()

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

Expose the set of parameters of the filter to the module parameter list.

Reimplemented from OnVarSet< AFilter >.

Reimplemented in UnionRecording< AFilter >, UnionRecording< AFilterFactory::CreatedFilter >, UnionRecording< typename AFilterFactory::CreatedFilter >, and UnionRecording< typename AFilterFactory::CreatedFilter >.

Definition at line 44 of file RecordingFilter.icc.h.

45 {
46 Super::exposeParameters(moduleParamList, prefix);
47 moduleParamList->addParameter(prefixed(prefix, "rootFileName"),
48 m_param_rootFileName,
49 "Name of the ROOT file to be written",
50 m_param_rootFileName);
51
52 moduleParamList->addParameter(prefixed(prefix, "treeName"),
53 m_param_treeName,
54 "Name of the Tree to be written",
55 m_param_treeName);
56
57 moduleParamList->addParameter(prefixed(prefix, "returnWeight"),
58 m_param_returnWeight,
59 "Weight this filter should return when called. Defaults to NAN",
60 m_param_returnWeight);
61 }

◆ getSkimFilter()

template<class AFilter>
MayBePtr< AFilter > getSkimFilter ( ) const
protected

Getter for the skim filter to select objects to be recorded.

Definition at line 98 of file RecordingFilter.icc.h.

99 {
100 return m_skimFilter.get();
101 }

◆ 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

Initialize the recorder before event processing.

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

65 {
66 if (m_skimFilter) this->addProcessingSignalListener(m_skimFilter.get());
67 Super::initialize();
68 m_recorder.reset(new Recorder(Super::getVarSet().getNamedVariables(),
69 m_param_rootFileName,
70 m_param_treeName));
71 }

◆ 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 & obj)
final

Function to evaluate the cluster for its backgroundness.

Definition at line 82 of file RecordingFilter.icc.h.

83 {
84 if (m_skimFilter) {
85 Weight skimWeight = (*m_skimFilter)(obj);
86 if (std::isnan(skimWeight)) return NAN;
87 }
88
89 Weight extracted = Super::operator()(obj);
90 if (not std::isnan(extracted)) {
91 m_recorder->capture();
92 }
93
94 return m_param_returnWeight;
95 }

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

◆ setSkimFilter()

template<class AFilter>
void setSkimFilter ( std::unique_ptr< AFilter > skimFilter)
protected

Setter for the skim filter to select objects to be recorded.

Definition at line 104 of file RecordingFilter.icc.h.

105 {
106 m_skimFilter = std::move(skimFilter);
107 }

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

◆ terminate()

template<class AFilter>
void terminate ( )
override

Initialize the recorder after event processing.

Definition at line 74 of file RecordingFilter.icc.h.

75 {
76 m_recorder->write();
77 m_recorder.reset();
78 Super::terminate();
79 }

Member Data Documentation

◆ m_param_returnWeight

template<class AFilter>
Weight m_param_returnWeight
private

Returns Weight when this filter is called.

Definition at line 88 of file RecordingFilter.dcl.h.

◆ m_param_rootFileName

template<class AFilter>
std::string m_param_rootFileName
private

Name of the ROOT file to which shall be written.

Definition at line 82 of file RecordingFilter.dcl.h.

◆ m_param_treeName

template<class AFilter>
std::string m_param_treeName
private

Name of Tree to be written.

Definition at line 85 of file RecordingFilter.dcl.h.

◆ m_recorder

template<class AFilter>
std::unique_ptr<Recorder> m_recorder
private

Recorder to write all variable sets of the encountered objects.

Definition at line 79 of file RecordingFilter.dcl.h.

◆ m_skimFilter

template<class AFilter>
std::unique_ptr<AFilter> m_skimFilter = nullptr
private

Skimming filter to select a subset of objects to be recorded.

Definition at line 91 of file RecordingFilter.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: