Belle II Software  release-05-01-25
SharingHitsMatcher.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/collectors/matchers/MatcherInterface.h>
13 
14 #include <tracking/trackFindingCDC/ca/AutomatonCell.h>
15 
16 #include <map>
17 #include <vector>
18 
19 namespace Belle2 {
24  namespace TrackFindingCDC {
25  class CDCWireHit;
26 
33  template <class ACollectorItem, class ACollectionItem>
34  class SharingHitsMatcher : public MatcherInterface<ACollectorItem, ACollectionItem> {
35 
37  using Super = MatcherInterface<ACollectorItem, ACollectionItem>;
38 
39  public:
41  void beginEvent() override
42  {
43  m_hitLookup.clear();
44  }
45 
47  void apply(std::vector<ACollectorItem>& collectorItems, const std::vector<ACollectionItem>& collectionItems,
48  std::vector<typename Super::WeightedRelationItem>& weightedRelations) override
49  {
50 
51  for (const ACollectionItem& collectionItem : collectionItems) {
52  const AutomatonCell& automatonCell = collectionItem.getAutomatonCell();
53 
54  if (automatonCell.hasTakenFlag() or collectionItem.empty()) {
55  continue;
56  }
57 
58  for (const auto& hit : collectionItem) {
59  const CDCWireHit& wireHit = hit.getWireHit();
60 
61  m_hitLookup.insert(std::make_pair(&wireHit, &collectionItem));
62  }
63  }
64 
65  Super::apply(collectorItems, collectionItems, weightedRelations);
66  }
67 
68  private:
73  void match(ACollectorItem& collectorItem, const std::vector<ACollectionItem>& collectionItems,
74  std::vector<typename Super::WeightedRelationItem>& relationsForCollector) override
75  {
76  std::map<const ACollectionItem*, unsigned int> numberOfIntersectionsMap;
77 
78  // Set the number of intersections to 0
79  for (const ACollectionItem& collectionItem : collectionItems) {
80  numberOfIntersectionsMap[&collectionItem] = 0;
81  }
82 
83  // For each hit in the collector item: Get all collection items for this hit and increase the number of intersections
84  for (const auto& hit : collectorItem) {
85  const CDCWireHit& wireHit = hit.getWireHit();
86 
87  // Get all matched collection items
88  const auto& relatedCollectionItems = m_hitLookup.equal_range(&wireHit);
89 
90  for (auto& relatedCollectionItemIterator : asRange(relatedCollectionItems)) {
91  const ACollectionItem* collectionItem = relatedCollectionItemIterator.second;
92  numberOfIntersectionsMap[collectionItem] += 1;
93  }
94  }
95 
96  // Add new relations to the list
97  for (const auto& collectionWithIntersections : numberOfIntersectionsMap) {
98  const ACollectionItem* collectionItem = collectionWithIntersections.first;
99  unsigned int numberOfIntersections = collectionWithIntersections.second;
100 
101  relationsForCollector.emplace_back(&collectorItem, numberOfIntersections, collectionItem);
102  }
103  }
104 
106  std::multimap<const CDCWireHit*, const ACollectionItem*> m_hitLookup;
107  };
108  }
110 }
Belle2::TrackFindingCDC::SharingHitsMatcher::apply
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.
Definition: SharingHitsMatcher.h:55
Belle2::TrackFindingCDC::SharingHitsMatcher::m_hitLookup
std::multimap< const CDCWireHit *, const ACollectionItem * > m_hitLookup
association of CDCWireHits with a generic collection item
Definition: SharingHitsMatcher.h:114
Belle2::TrackFindingCDC::SharingHitsMatcher::Super
MatcherInterface< ACollectorItem, ACollectionItem > Super
The parent class.
Definition: SharingHitsMatcher.h:45
Belle2::TrackFindingCDC::SharingHitsMatcher::match
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...
Definition: SharingHitsMatcher.h:81
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::AutomatonCell
Cell used by the cellular automata.
Definition: AutomatonCell.h:39
Belle2::TrackFindingCDC::SharingHitsMatcher::beginEvent
void beginEvent() override
Clear the hit lookup in every event.
Definition: SharingHitsMatcher.h:49
Belle2::TrackFindingCDC::AutomatonCell::hasTakenFlag
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Definition: AutomatonCell.h:249
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
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65