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