Belle II Software  release-05-02-19
FilterSelector.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 <tracking/trackFindingCDC/numerics/Weight.h>
15 
16 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
17 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
18 
19 #include <algorithm>
20 #include <vector>
21 #include <string>
22 
23 namespace Belle2 {
28  class ModuleParamList;
29  namespace TrackFindingCDC {
46  template <class ACollectorItem, class ACollectionItem, class AFilter>
47  class FilterSelector :
48  public Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>> {
49  public:
51  using WeightedRelationItem = WeightedRelation<ACollectorItem, const ACollectionItem>;
52 
54  using Super = Findlet<WeightedRelation<ACollectorItem, const ACollectionItem>>;
55 
57  FilterSelector() : Super()
58  {
60  }
61 
63  void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override
64  {
65  Super::exposeParameters(moduleParamList, prefix);
66  m_filter.exposeParameters(moduleParamList, prefix);
67  }
68 
70  void apply(std::vector<WeightedRelationItem>& weightedRelations) override
71  {
72  for (WeightedRelationItem& weightedRelation : weightedRelations) {
73  const Weight weight = m_filter(weightedRelation);
74  weightedRelation.setWeight(weight);
75  }
76 
77  const auto& weightIsNan = [](const WeightedRelationItem & item) {
78  return std::isnan(item.getWeight());
79  };
80 
81  // Erase all items with a weight of NAN
82  erase_remove_if(weightedRelations, weightIsNan);
83 
84  std::sort(weightedRelations.begin(), weightedRelations.end());
85  }
86 
87  private:
89  AFilter m_filter;
90  };
91  }
93 }
Belle2::TrackFindingCDC::Findlet< WeightedRelation< ACollectorItem, const ACollectionItem > >
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::addProcessingSignalListener
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Definition: CompositeProcessingSignalListener.cc:57
Belle2::TrackFindingCDC::FilterSelector::apply
void apply(std::vector< WeightedRelationItem > &weightedRelations) override
Main function of the class: calculate the filter result and remove all relations, where the filter re...
Definition: FilterSelector.h:78
Belle2::TrackFindingCDC::FilterSelector::WeightedRelationItem
WeightedRelation< ACollectorItem, const ACollectionItem > WeightedRelationItem
Shortcut class name for a weighted relation between a collector item and a collection item.
Definition: FilterSelector.h:59
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::FilterSelector::FilterSelector
FilterSelector()
Add the chosen filter as a process signal listener.
Definition: FilterSelector.h:65
Belle2::TrackFindingCDC::FilterSelector::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the filter.
Definition: FilterSelector.h:71
Belle2::TrackFindingCDC::FilterSelector::Super
Findlet< WeightedRelation< ACollectorItem, const ACollectionItem > > Super
The parent class.
Definition: FilterSelector.h:62
Belle2::TrackFindingCDC::WeightedRelation< Belle2::TrackFindingCDC::CDCTrack, const Belle2::TrackFindingCDC::CDCRLWireHit >
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::FilterSelector::m_filter
AFilter m_filter
The filter to use.
Definition: FilterSelector.h:97