Belle II Software development
FilterOnVarSet.icc.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/filters/base/FilterOnVarSet.dcl.h>
11
12#include <tracking/trackFindingCDC/utilities/Named.h>
13
14#include <framework/logging/Logger.h>
15
16#include <RtypesCore.h>
17
18#include <vector>
19#include <string>
20#include <memory>
21
22#include <cmath>
23
24namespace Belle2 {
29 namespace TrackFindingCDC {
30
31 template <class AFilter>
32 OnVarSet<AFilter>::OnVarSet(std::unique_ptr<AVarSet> varSet)
33 : m_varSet(std::move(varSet))
34 {
35 B2ASSERT("Varset initialised as nullptr", m_varSet);
36 }
37
38 template <class AFilter>
40
41 template <class AFilter>
43 {
44 this->addProcessingSignalListener(m_varSet.get());
45 Super::initialize();
46 }
47
48 template <class AFilter>
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 }
65 template <class AFilter>
67 {
68 Weight weight = Super::operator()(obj);
69 if (std::isnan(weight)) return NAN;
70 bool extracted = m_varSet->extract(&obj);
71 return extracted ? weight : NAN;
72 }
73
74 template <class AFilter>
75 auto OnVarSet<AFilter>::releaseVarSet()&& -> std::unique_ptr<AVarSet> {
76 return std::move(m_varSet);
77 }
78
79 template <class AFilter>
81 {
82 return *m_varSet;
83 }
84
85 template <class AFilter>
86 void OnVarSet<AFilter>::setVarSet(std::unique_ptr<AVarSet> varSet)
87 {
88 m_varSet = std::move(varSet);
89 }
90
91 template <class AVarSet>
93 : Super(std::make_unique<AVarSet>())
94 {
95 }
96
97 template <class AVarSet>
99 }
101}
FilterOnVarSet()
Constructor of the filter.
A mixin class to attach a name to an object.
Definition: Named.h:23
Filter adapter to make a filter work on a set of variables.
void initialize() override
No reassignment of variable set possible for now.
bool needsTruthInformation() override
Checks if any variables need Monte Carlo information.
Weight operator()(const Object &obj) override
Function extracting the variables of the object into the variable set.
std::unique_ptr< AVarSet > m_varSet
Instance of the variable set to be used in the filter.
std::unique_ptr< AVarSet > releaseVarSet() &&
Steal the set of variables form this filter - filter becomes disfunctional afterwards.
AVarSet & getVarSet() const
Getter for the set of variables.
typename AFilter::Object Object
Type of pbject to be filtered.
void setVarSet(std::unique_ptr< AVarSet > varSet)
Setter for the set of variables.
OnVarSet(std::unique_ptr< AVarSet > varSet)
Constructor from the variable set the filter should use.
~OnVarSet()
Default destructor.
Abstract base class for different kinds of events.
STL namespace.