Belle II Software  release-08-01-10
MCTruthCDCPathPairFilter.cc
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 #include <tracking/ckf/cdc/filters/pathPairs/MCTruthCDCPathPairFilter.h>
9 #include <tracking/dataobjects/RecoTrack.h>
10 
11 using namespace Belle2;
12 
13 namespace {
14  unsigned int countCorrectHits(const CDCCKFPath& path, const RecoTrack* mcRecoTrack)
15  {
16  auto correctHits = mcRecoTrack->getCDCHitList();
17  std::sort(correctHits.begin(), correctHits.end());
18 
19  unsigned int numberOfCorrectHits = 0;
20 
21  for (const auto& state : path) {
22  if (state.isSeed()) {
23  continue;
24  }
25 
26  const auto* wireHit = state.getWireHit();
27  const auto* cdcHit = wireHit->getHit();
28 
29  if (std::binary_search(correctHits.begin(), correctHits.end(), cdcHit)) {
30  numberOfCorrectHits++;
31  }
32  }
33 
34  return numberOfCorrectHits;
35  }
36 }
37 
39 {
40  const auto& lhs = *pair.first;
41  const auto& rhs = *pair.second;
42 
43  const auto& lhsSeed = lhs.front();
44  const auto& rhsSeed = rhs.front();
45 
46  const auto* lhsMCRecoTrack = lhsSeed.getMCRecoTrack();
47  const auto* rhsMCRecoTrack = rhsSeed.getMCRecoTrack();
48  // std::cout << "here " << lhsMCRecoTrack << " " << rhsMCRecoTrack << "\n";
49 
50  if (not lhsMCRecoTrack and rhsMCRecoTrack) {
51  return -1;
52  } else if (lhsMCRecoTrack and not rhsMCRecoTrack) {
53  return 1;
54  } else if (not lhsMCRecoTrack and not rhsMCRecoTrack) {
55  // Well, we do not care...
56  return 0;
57  }
58 
59  // Return the one of the highest number of correct hits
60  const unsigned int lhsCorrectHits = countCorrectHits(lhs, lhsMCRecoTrack);
61  const unsigned int rhsCorrectHits = countCorrectHits(rhs, rhsMCRecoTrack);
62 
63 
64  if (lhsCorrectHits > rhsCorrectHits) {
65  return 1;
66  } else if (lhsCorrectHits < rhsCorrectHits) {
67  return -1;
68  }
69 
70  // In case both have the same number of correct hits, return the shortest (which has the highest purity)
71  const unsigned int lhsSize = lhs.size();
72  const unsigned int rhsSize = rhs.size();
73 
74  // std::cout << "len select lhs:" << lhsSize << " rhs: " << rhsSize << "\n";
75 
76  if (lhsSize > rhsSize) {
77  return -1;
78  } else if (lhsSize < rhsSize) {
79  return 1;
80  }
81 
82  // In case both have the same number of hits, use the one which has advanced less in time
83  // TODO: better use the correct hit time here!
84  const double lhsLastArcLength = lhs.back().getArcLength();
85  const double rhsLastArcLength = rhs.back().getArcLength();
86 
87  return lhsLastArcLength < rhsLastArcLength;
88 }
TrackFindingCDC::Weight operator()(const BaseCDCPathPairFilter::Object &pair) final
Input: pair of paths, returns 1 if pair.first to be selected, 0 otherwise.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
Definition: RecoTrack.h:455
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:33
std::vector< CDCCKFState > CDCCKFPath
Shortcut for the collection of CDC CKF-algorithm states.
Definition: CDCCKFPath.h:19
Abstract base class for different kinds of events.