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 invokation. More...

#include <RecordingFilter.dcl.h>

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

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 disfunctional 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 invokation.

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

Member Typedef Documentation

◆ AVarSet

using AVarSet = BaseVarSet<Object>
private

Type of the var set interface to be used.

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

◆ Object

using Object = typename AFilter::Object

Type of the object to be analysed.

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

◆ Super

using Super = OnVarSet<AFilter>
private

Type of the base class.

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

Constructor & Destructor Documentation

◆ Recording()

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)
38 {}
Weight m_param_returnWeight
Returns Weight when this filter is called.
OnVarSet< AFilter > Super
Type of the base class.
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.
std::unique_ptr< Recorder > m_recorder
Recorder to write all variable sets of the encountered objects.

Member Function Documentation

◆ exposeParameters()

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

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

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

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

◆ getSkimFilter()

MayBePtr< AFilter > getSkimFilter
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 }
std::unique_ptr< AFilter > m_skimFilter
Skimming filter to select a subset of objects to be recorded.

◆ 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

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());
68 m_recorder.reset(new Recorder(Super::getVarSet().getNamedVariables(),
71 }
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 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
95 }
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 disfunctional afterwards.

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

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

◆ setSkimFilter()

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()

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 }

◆ terminate()

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

Weight m_param_returnWeight
private

Returns Weight when this filter is called.

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

◆ m_param_rootFileName

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

std::string m_param_treeName
private

Name of Tree to be written.

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

◆ m_recorder

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

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

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: