Belle II Software  release-08-01-10
MatcherInterface.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/findlets/base/Findlet.h>
11 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
12 
13 #include <cmath>
14 
15 namespace Belle2 {
20  namespace TrackFindingCDC {
39  template <class ACollectorItem, class ACollectionItem>
41  public Findlet<ACollectorItem,
42  const ACollectionItem,
43  WeightedRelation<ACollectorItem, const ACollectionItem>> {
44  public:
47 
52  void apply(std::vector<ACollectorItem>& collectorItems, const std::vector<ACollectionItem>& collectionItems,
53  std::vector<WeightedRelationItem>& weightedRelations) override
54  {
55  for (ACollectorItem& collectorItem : collectorItems) {
56  match(collectorItem, collectionItems, weightedRelations);
57  }
58 
59  std::sort(weightedRelations.begin(), weightedRelations.end());
60  }
61 
62  protected:
68  virtual void match(ACollectorItem& collectorItem, const std::vector<ACollectionItem>& collectionItems,
69  std::vector<WeightedRelationItem>& relationsForCollector)
70  {
71  for (const ACollectionItem& collectionItem : collectionItems) {
72  Weight weight = match(collectorItem, collectionItem);
73  relationsForCollector.emplace_back(&collectorItem, weight, &collectionItem);
74  }
75  };
76 
82  virtual Weight match(ACollectorItem& collectorItem __attribute__((unused)),
83  const ACollectionItem& collectionItem __attribute__((unused)))
84  {
85  return NAN;
86  }
87  };
88  }
90 }
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
Base class for a findlet, which outputs a list of weighted relations between elements in a list of Co...
virtual Weight match(ACollectorItem &collectorItem, const ACollectionItem &collectionItem)
Override this function to implement your own matching algorithm between one collector and one collect...
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...
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...
Type for two related objects with a weight.
Abstract base class for different kinds of events.