Belle II Software  release-05-02-19
CDCCKFPathMerger.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - 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/ckf/cdc/entities/CDCCKFPath.h>
14 
15 #include <boost/range/adaptor/reversed.hpp>
16 #include <boost/functional/hash.hpp>
17 
18 namespace Belle2 {
23  class CDCCKFPathMerger : public TrackFindingCDC::Findlet<CDCCKFPath> {
25  public:
27  void apply(std::vector<CDCCKFPath>& newPaths) override
28  {
30  std::unordered_map<size_t, CDCCKFPath> hashToPathList;
31  for (const CDCCKFPath& path : newPaths) {
32  const auto lastHitsHash = lastThreeHitHash(path);
33  if (hashToPathList.find(lastHitsHash) != hashToPathList.end()) {
34  if (hashToPathList[lastHitsHash].size() < path.size()) {
35  hashToPathList[lastHitsHash] = path;
36  }
37  } else {
38  hashToPathList[lastHitsHash] = path;
39  }
40  }
41 
42  newPaths.clear();
43  for (const auto& hashAndPathList : hashToPathList) {
44  const CDCCKFPath& path = hashAndPathList.second;
45  newPaths.push_back(path);
46  }
47  }
48 
49  private:
51  size_t lastThreeHitHash(const CDCCKFPath& path)
52  {
53  size_t seed = 0;
54  unsigned int counter = 0;
55 
56  for (const CDCCKFState& state : boost::adaptors::reverse(path)) {
57  if (counter >= 3) {
58  break;
59  }
60  if (not state.isSeed()) {
61  boost::hash_combine(seed, state.getWireHit());
62  }
63  counter++;
64  }
65  return seed;
66  };
67 
68  };
70 }
Belle2::CDCCKFPathMerger::apply
void apply(std::vector< CDCCKFPath > &newPaths) override
main method of the findlet, reads/returns merged paths
Definition: CDCCKFPathMerger.h:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCCKFPath
std::vector< CDCCKFState > CDCCKFPath
Shortcut for the collection of CDC CKF-algorithm states.
Definition: CDCCKFPath.h:29
Belle2::CDCCKFPathMerger::lastThreeHitHash
size_t lastThreeHitHash(const CDCCKFPath &path)
helper function, returns has of the last 3 wire hits on the path
Definition: CDCCKFPathMerger.h:59