Belle II Software  release-05-01-25
CutSelector.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/findlets/base/Findlet.h>
13 
14 #include <framework/core/ModuleParamList.h>
15 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
16 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <string>
21 #include <vector>
22 
23 namespace Belle2 {
28  namespace TrackFindingCDC {
43  template <class ACollectorItem, class ACollectionItem>
44  class CutSelector :
45  public Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>> {
46  public:
48  using WeightedRelationItem = WeightedRelation<ACollectorItem, const ACollectionItem>;
49 
51  using Super = Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>>;
52 
54  void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override
55  {
56  Super::exposeParameters(moduleParamList, prefix);
57  moduleParamList->addParameter(prefixed(prefix, "cutValue"), m_param_cutValue,
58  "Value to cut at.",
60  }
61 
63  void apply(std::vector<WeightedRelationItem>& weightedRelations) override
64  {
65  const auto& lessThanCutOrNaN = [this](const WeightedRelationItem & relationItem) {
66  return std::isnan(relationItem.getWeight()) or relationItem.getWeight() < m_param_cutValue;
67  };
68 
69  // Erase all items with a weight of NAN
70  weightedRelations.erase(std::remove_if(weightedRelations.begin(),
71  weightedRelations.end(),
72  lessThanCutOrNaN),
73  weightedRelations.end());
74  }
75 
77  void setCutValue(Weight cutValue)
78  {
79  m_param_cutValue = cutValue;
80  }
81 
82  private:
84  Weight m_param_cutValue = NAN;
85  };
86  }
88 }
Belle2::TrackFindingCDC::CutSelector::WeightedRelationItem
WeightedRelation< ACollectorItem, const ACollectionItem > WeightedRelationItem
Shortcut class name for a weighted relation between a collector item and a collection item.
Definition: CutSelector.h:56
Belle2::TrackFindingCDC::CutSelector::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the cut value to the module.
Definition: CutSelector.h:62
Belle2::ModuleParamList::addParameter
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Definition: ModuleParamList.templateDetails.h:38
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::Findlet< WeightedRelation< ACollectorItem, const ACollectionItem > >::exposeParameters
virtual void exposeParameters(ModuleParamList *moduleParamList __attribute__((unused)), const std::string &prefix __attribute__((unused)))
Forward prefixed parameters of this findlet to the module parameter list.
Definition: Findlet.h:79
Belle2::TrackFindingCDC::CutSelector::m_param_cutValue
Weight m_param_cutValue
The cut value to use.
Definition: CutSelector.h:92
Belle2::TrackFindingCDC::CutSelector::Super
Findlet< WeightedRelation< ACollectorItem, const ACollectionItem > > Super
The parent class.
Definition: CutSelector.h:59
Belle2::TrackFindingCDC::CutSelector::apply
void apply(std::vector< WeightedRelationItem > &weightedRelations) override
Do the cut.
Definition: CutSelector.h:71
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::CutSelector::setCutValue
void setCutValue(Weight cutValue)
Function to set the cut value (mostly for tests).
Definition: CutSelector.h:85