Belle II Software  release-08-01-10
SharingHitsMatcher.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/collectors/matchers/MatcherInterface.h>
11 
12 #include <tracking/trackFindingCDC/ca/AutomatonCell.h>
13 
14 #include <map>
15 #include <vector>
16 
17 namespace Belle2 {
22  namespace TrackFindingCDC {
23  class CDCWireHit;
24 
31  template <class ACollectorItem, class ACollectionItem>
32  class SharingHitsMatcher : public MatcherInterface<ACollectorItem, ACollectionItem> {
33 
36 
37  public:
39  void beginEvent() override
40  {
41  m_hitLookup.clear();
42  }
43 
45  void apply(std::vector<ACollectorItem>& collectorItems, const std::vector<ACollectionItem>& collectionItems,
46  std::vector<typename Super::WeightedRelationItem>& weightedRelations) override
47  {
48 
49  for (const ACollectionItem& collectionItem : collectionItems) {
50  const AutomatonCell& automatonCell = collectionItem.getAutomatonCell();
51 
52  if (automatonCell.hasTakenFlag() or collectionItem.empty()) {
53  continue;
54  }
55 
56  for (const auto& hit : collectionItem) {
57  const CDCWireHit& wireHit = hit.getWireHit();
58 
59  // cppcheck-suppress danglingLifetime
60  m_hitLookup.insert(std::make_pair(&wireHit, &collectionItem));
61  }
62  }
63 
64  Super::apply(collectorItems, collectionItems, weightedRelations);
65  }
66 
67  private:
72  void match(ACollectorItem& collectorItem, const std::vector<ACollectionItem>& collectionItems,
73  std::vector<typename Super::WeightedRelationItem>& relationsForCollector) override
74  {
75  std::map<const ACollectionItem*, unsigned int> numberOfIntersectionsMap;
76 
77  // Set the number of intersections to 0
78  for (const ACollectionItem& collectionItem : collectionItems) {
79  numberOfIntersectionsMap[&collectionItem] = 0;
80  }
81 
82  // For each hit in the collector item: Get all collection items for this hit and increase the number of intersections
83  for (const auto& hit : collectorItem) {
84  const CDCWireHit& wireHit = hit.getWireHit();
85 
86  // Get all matched collection items
87  const auto& relatedCollectionItems = m_hitLookup.equal_range(&wireHit);
88 
89  for (auto& relatedCollectionItemIterator : asRange(relatedCollectionItems)) {
90  const ACollectionItem* collectionItem = relatedCollectionItemIterator.second;
91  numberOfIntersectionsMap[collectionItem] += 1;
92  }
93  }
94 
95  // Add new relations to the list
96  for (const auto& collectionWithIntersections : numberOfIntersectionsMap) {
97  const ACollectionItem* collectionItem = collectionWithIntersections.first;
98  unsigned int numberOfIntersections = collectionWithIntersections.second;
99 
100  relationsForCollector.emplace_back(&collectorItem, numberOfIntersections, collectionItem);
101  }
102  }
103 
105  std::multimap<const CDCWireHit*, const ACollectionItem*> m_hitLookup;
106  };
107  }
109 }
Cell used by the cellular automata.
Definition: AutomatonCell.h:29
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Base class for a findlet, which outputs a list of weighted relations between elements in a list of Co...
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...
A generic matcher algorithm which outputs all combinations of elements with the number of shared hits...
void match(ACollectorItem &collectorItem, const std::vector< ACollectionItem > &collectionItems, std::vector< typename Super::WeightedRelationItem > &relationsForCollector) override
Output the number of shared hits - the rest of the logic (relation creation etc.) is handled by the p...
std::multimap< const CDCWireHit *, const ACollectionItem * > m_hitLookup
association of CDCWireHits with a generic collection item
void beginEvent() override
Clear the hit lookup in every event.
void apply(std::vector< ACollectorItem > &collectorItems, const std::vector< ACollectionItem > &collectionItems, std::vector< typename Super::WeightedRelationItem > &weightedRelations) override
Call the apply function of the super class - but before fill the hit lookup.
Abstract base class for different kinds of events.