Belle II Software  release-05-01-25
FilterOnVarSet.icc.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/filters/base/FilterOnVarSet.dcl.h>
13 
14 #include <tracking/trackFindingCDC/utilities/Named.h>
15 
16 #include <framework/logging/Logger.h>
17 
18 #include <RtypesCore.h>
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 
24 #include <cmath>
25 
26 namespace Belle2 {
31  namespace TrackFindingCDC {
32 
33  template <class AFilter>
34  OnVarSet<AFilter>::OnVarSet(std::unique_ptr<AVarSet> varSet)
35  : m_varSet(std::move(varSet))
36  {
37  B2ASSERT("Varset initialised as nullptr", m_varSet);
38  }
39 
40  template <class AFilter>
41  OnVarSet<AFilter>::~OnVarSet() = default;
42 
43  template <class AFilter>
45  {
46  this->addProcessingSignalListener(m_varSet.get());
47  Super::initialize();
48  }
49 
50  template <class AFilter>
52  {
53  bool result = Super::needsTruthInformation();
54  if (result) return true;
55 
56  const std::vector<Named<Float_t*>>& namedVariables = m_varSet->getNamedVariables();
57  for (const Named<Float_t*>& namedVariable : namedVariables) {
58  std::string name = namedVariable.getName();
59  // If the name contains the word truth it is considered to have Monte carlo information.
60  if (name.find("truth") != std::string::npos) {
61  return true;
62  }
63  }
64  return false;
65  }
66 
67  template <class AFilter>
68  Weight OnVarSet<AFilter>::operator()(const Object& obj)
69  {
70  Weight weight = Super::operator()(obj);
71  if (std::isnan(weight)) return NAN;
72  bool extracted = m_varSet->extract(&obj);
73  return extracted ? weight : NAN;
74  }
75 
76  template <class AFilter>
77  auto OnVarSet<AFilter>::releaseVarSet()&& -> std::unique_ptr<AVarSet> {
78  return std::move(m_varSet);
79  }
80 
81  template <class AFilter>
82  auto OnVarSet<AFilter>::getVarSet() const -> AVarSet&
83  {
84  return *m_varSet;
85  }
86 
87  template <class AFilter>
88  void OnVarSet<AFilter>::setVarSet(std::unique_ptr<AVarSet> varSet)
89  {
90  m_varSet = std::move(varSet);
91  }
92 
93  template <class AVarSet>
95  : Super(std::make_unique<AVarSet>())
96  {
97  }
98 
99  template <class AVarSet>
101  }
103 }
Belle2::TrackFindingCDC::Named< Float_t * >
Belle2::TrackFindingCDC::OnVarSet::OnVarSet
OnVarSet(std::unique_ptr< AVarSet > varSet)
Constructor from the variable set the filter should use.
Definition: FilterOnVarSet.icc.h:42
Belle2::TrackFindingCDC::FilterOnVarSet
Convience template to create a filter operating on a specific set of variables.
Definition: FilterOnVarSet.dcl.h:90
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::OnVarSet
Filter adapter to make a filter work on a set of variables.
Definition: FilterOnVarSet.dcl.h:37