Belle II Software development
UnionRecording< AFilter > Class Template Reference

A filter that records variables form given objects. More...

#include <UnionRecordingFilter.dcl.h>

Inheritance diagram for UnionRecording< AFilter >:
Recording< AFilter > OnVarSet< AFilter >

Public Types

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

Public Member Functions

 UnionRecording (std::unique_ptr< AFilterFactory > filterFactory, const std::string &defaultRootFileName="records.root", const std::string &defaultTreeName="records")
 Constructor of the filter.
 
 ~UnionRecording ()
 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.
 
virtual std::vector< std::string > getValidVarSetNames () const
 Getter for the list of valid names of concrete variable sets.
 
virtual std::vector< std::string > getValidFilterNames () const
 Getter for the names of valid filters.
 
virtual std::unique_ptr< AVarSetcreateVarSet (const std::string &name) const
 Create a variable set for the given name.
 
const std::vector< std::string > & getVarSetNames () const
 Splits the comma separated variable names list into a vector of names.
 
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 = Recording< AFilter >
 Type of the super class.
 
using AFilterFactory = FilterFactory< AFilter >
 Type of the factory used to produce FilterVarSets to be add to the recording.
 
using AVarSet = BaseVarSet< Object >
 Type of the factory used to produce FilterVarSets to be add to the recording.
 

Private Attributes

std::vector< std::string > m_param_varSetNames
 List of varsets that should be recorded.
 
std::string m_param_skim = ""
 Name of the filter to selected to objects to be record.
 
std::unique_ptr< AFilterFactorym_filterFactory
 FilterFactory.
 
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::UnionRecording< AFilter >

A filter that records variables form given objects.

It may record native varsets and/or weights from other filters.

Definition at line 33 of file UnionRecordingFilter.dcl.h.

Member Typedef Documentation

◆ AFilterFactory

using AFilterFactory = FilterFactory<AFilter>
private

Type of the factory used to produce FilterVarSets to be add to the recording.

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

◆ AVarSet

using AVarSet = BaseVarSet<Object>
private

Type of the factory used to produce FilterVarSets to be add to the recording.

Definition at line 48 of file UnionRecordingFilter.dcl.h.

◆ Object

using Object = typename AFilter::Object

Type of the object to be analysed.

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

◆ Super

using Super = Recording<AFilter>
private

Type of the super class.

Definition at line 37 of file UnionRecordingFilter.dcl.h.

Constructor & Destructor Documentation

◆ UnionRecording()

UnionRecording ( std::unique_ptr< AFilterFactory filterFactory,
const std::string &  defaultRootFileName = "records.root",
const std::string &  defaultTreeName = "records" 
)

Constructor of the filter.

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

38 : Super(std::make_unique<UnionVarSet<Object>>(), defaultRootFileName, defaultTreeName)
39 , m_filterFactory(std::move(filterFactory))
40 {
41 }
Recording< AFilter > Super
Type of the super class.
std::unique_ptr< AFilterFactory > m_filterFactory
FilterFactory.

Member Function Documentation

◆ createVarSet()

auto createVarSet ( const std::string &  name) const
virtual

Create a variable set for the given name.

Reimplemented in UnionRecordingAxialSegmentPairFilter, UnionRecordingFacetFilter, UnionRecordingSegmentPairFilter, UnionRecordingSegmentPairRelationFilter, UnionRecordingTrackRelationFilter, UnionRecordingClusterFilter, UnionRecordingFacetRelationFilter, and UnionRecordingSegmentRelationFilter.

Definition at line 121 of file UnionRecordingFilter.icc.h.

123 {
124 if (name.find("filter(") == 0 and name.rfind(")") == name.size() - 1) {
125 B2INFO("Detected filter name");
126 std::string filterName = name.substr(7, name.size() - 8);
127 B2INFO("filterName = " << filterName);
128 std::unique_ptr<AFilter> filter = m_filterFactory->create(filterName);
129 if (not filter) {
130 B2WARNING("Could not construct filter for name " << filterName);
131 return std::unique_ptr<AVarSet>(nullptr);
132 } else {
133 AVarSet* filterVarSet = new FilterVarSet<AFilter>(filterName, std::move(filter));
134 return std::unique_ptr<AVarSet>(filterVarSet);
135 }
136 } else {
137 return std::unique_ptr<AVarSet>(nullptr);
138 }
139 }
BaseVarSet< Object > AVarSet
Type of the factory used to produce FilterVarSets to be add to the recording.
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double > > &runs, double cut, std::map< ExpRun, std::pair< double, double > > &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Definition: Splitter.cc:38

◆ 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 47 of file UnionRecordingFilter.icc.h.

48 {
49 Super::exposeParameters(moduleParamList, prefix);
50
51 moduleParamList->addParameter(prefixed(prefix, "varSets"),
53 "List of names referring to concrete variable sets."
54 "Valid names: " +
55 join(", ", this->getValidVarSetNames()),
57
58 moduleParamList->addParameter(prefixed(prefix, "skim"),
60 "Filter name which object must pass to be recorded."
61 "Valid names: " +
62 join(", ", this->getValidFilterNames()),
64 }
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the set of parameters of the filter to the module parameter list.
virtual std::vector< std::string > getValidFilterNames() const
Getter for the names of valid filters.
std::vector< std::string > m_param_varSetNames
List of varsets that should be recorded.
std::string m_param_skim
Name of the filter to selected to objects to be record.
virtual std::vector< std::string > getValidVarSetNames() const
Getter for the list of valid names of concrete variable sets.

◆ getSkimFilter()

MayBePtr< AFilter > getSkimFilter
protectedinherited

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.

◆ getValidFilterNames()

std::vector< std::string > getValidFilterNames
virtual

Getter for the names of valid filters.

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

105 {
106 // Get all filter names and make a var set name for each.
107 std::map<std::string, std::string> filterNamesAndDescriptions =
108 m_filterFactory->getValidFilterNamesAndDescriptions();
109
110 std::vector<std::string> filterNames;
111 filterNames.reserve(filterNamesAndDescriptions.size());
112 for (const auto& filterNameAndDescription :
113 filterNamesAndDescriptions) {
114 const std::string& filterName = filterNameAndDescription.first;
115 filterNames.push_back(filterName);
116 }
117 return filterNames;
118 }

◆ getValidVarSetNames()

std::vector< std::string > getValidVarSetNames
virtual

Getter for the list of valid names of concrete variable sets.

Reimplemented in UnionRecordingAxialSegmentPairFilter, UnionRecordingFacetFilter, UnionRecordingSegmentPairFilter, UnionRecordingSegmentPairRelationFilter, UnionRecordingTrackRelationFilter, UnionRecordingClusterFilter, UnionRecordingFacetRelationFilter, and UnionRecordingSegmentRelationFilter.

Definition at line 91 of file UnionRecordingFilter.icc.h.

92 {
93 // Get all filter names and make a var set name for each.
94 std::vector<std::string> varSetNames;
95 std::vector<std::string> filterNames = getValidFilterNames();
96 for (const std::string& filterName : filterNames) {
97 std::string varSetName = "filter(" + filterName + ")";
98 varSetNames.push_back(varSetName);
99 }
100 return varSetNames;
101 }

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

◆ getVarSetNames()

const std::vector< std::string > & getVarSetNames

Splits the comma separated variable names list into a vector of names.

Definition at line 142 of file UnionRecordingFilter.icc.h.

143 {
144 return m_param_varSetNames;
145 }

◆ initialize()

void initialize
override

Initialize the recorder before event processing.

Create the skimming filter

Create and add the concrete varsets from the varset parameter.

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

68 {
70 if (m_param_skim != "") {
71 std::unique_ptr<AFilter> skimFilter = m_filterFactory->create(m_param_skim);
72 this->setSkimFilter(std::move(skimFilter));
73 }
74
75 auto multiVarSet = std::make_unique<UnionVarSet<Object>>();
76
78 for (std::string name : getVarSetNames()) {
79 std::unique_ptr<AVarSet> varSet = createVarSet(name);
80 if (varSet) {
81 multiVarSet->push_back(std::move(varSet));
82 } else {
83 B2WARNING("Could not create a variable set from name " << name);
84 }
85 }
86 this->setVarSet(std::move(multiVarSet));
88 }
void setVarSet(std::unique_ptr< AVarSet > varSet)
Setter for the set of variables.
void initialize() override
Initialize the recorder before event processing.
void setSkimFilter(std::unique_ptr< AFilter > skimFilter)
Setter for the skim filter to select objects to be recorded.
const std::vector< std::string > & getVarSetNames() const
Splits the comma separated variable names list into a vector of names.
virtual std::unique_ptr< AVarSet > createVarSet(const std::string &name) const
Create a variable set for the given name.

◆ 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)
finalinherited

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.
Weight m_param_returnWeight
Returns Weight when this filter is called.
std::unique_ptr< Recorder > m_recorder
Recorder to write all variable sets of the encountered objects.

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

◆ setSkimFilter()

void setSkimFilter ( std::unique_ptr< AFilter >  skimFilter)
protectedinherited

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
overrideinherited

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_filterFactory

std::unique_ptr<AFilterFactory> m_filterFactory
private

FilterFactory.

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

◆ m_param_returnWeight

Weight m_param_returnWeight
privateinherited

Returns Weight when this filter is called.

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

◆ m_param_rootFileName

std::string m_param_rootFileName
privateinherited

Name of the ROOT file to which shall be written.

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

◆ m_param_skim

std::string m_param_skim = ""
private

Name of the filter to selected to objects to be record.

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

◆ m_param_treeName

std::string m_param_treeName
privateinherited

Name of Tree to be written.

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

◆ m_param_varSetNames

std::vector<std::string> m_param_varSetNames
private

List of varsets that should be recorded.

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

◆ m_recorder

std::unique_ptr<Recorder> m_recorder
privateinherited

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
privateinherited

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: