Belle II Software  release-05-02-19
MatcherInterface.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 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
14 
15 #include <cmath>
16 
17 namespace Belle2 {
22  namespace TrackFindingCDC {
41  template <class ACollectorItem, class ACollectionItem>
42  class MatcherInterface :
43  public Findlet<ACollectorItem,
44  const ACollectionItem,
45  WeightedRelation<ACollectorItem, const ACollectionItem>> {
46  public:
48  using WeightedRelationItem = WeightedRelation<ACollectorItem, const ACollectionItem>;
49 
54  void apply(std::vector<ACollectorItem>& collectorItems, const std::vector<ACollectionItem>& collectionItems,
55  std::vector<WeightedRelationItem>& weightedRelations) override
56  {
57  for (ACollectorItem& collectorItem : collectorItems) {
58  match(collectorItem, collectionItems, weightedRelations);
59  }
60 
61  std::sort(weightedRelations.begin(), weightedRelations.end());
62  }
63 
64  protected:
70  virtual void match(ACollectorItem& collectorItem, const std::vector<ACollectionItem>& collectionItems,
71  std::vector<WeightedRelationItem>& relationsForCollector)
72  {
73  for (const ACollectionItem& collectionItem : collectionItems) {
74  Weight weight = match(collectorItem, collectionItem);
75  relationsForCollector.emplace_back(&collectorItem, weight, &collectionItem);
76  }
77  };
78 
84  virtual Weight match(ACollectorItem& collectorItem __attribute__((unused)),
85  const ACollectionItem& collectionItem __attribute__((unused)))
86  {
87  return NAN;
88  }
89  };
90  }
92 }
Belle2::TrackFindingCDC::MatcherInterface::WeightedRelationItem
WeightedRelation< ACollectorItem, const ACollectionItem > WeightedRelationItem
Shortcut class name for a weighted relation between a collector item and a collection item.
Definition: MatcherInterface.h:56
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::MatcherInterface::match
virtual void match(ACollectorItem &collectorItem, const std::vector< ACollectionItem > &collectionItems, std::vector< WeightedRelationItem > &relationsForCollector)
Override this function to implement your own matching algorithm between one collector and many collec...
Definition: MatcherInterface.h:78
Belle2::TrackFindingCDC::MatcherInterface::apply
void apply(std::vector< ACollectorItem > &collectorItems, const std::vector< ACollectionItem > &collectionItems, std::vector< WeightedRelationItem > &weightedRelations) override
Main function: create weighted relations between collectors and collection items using the implemente...
Definition: MatcherInterface.h:62