Belle II Software  release-05-01-25
BestMatchedTruthVarSet.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Michael Eliachevitch, Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/filters/track/BestMatchedTruthVarSet.h>
11 
12 #include <tracking/trackFindingCDC/mclookup/CDCMCHitLookUp.h>
13 #include <tracking/trackFindingCDC/mclookup/CDCMCTrackLookUp.h>
14 #include <tracking/trackFindingCDC/mclookup/CDCMCManager.h>
15 #include <tracking/trackFindingCDC/mclookup/CDCMCCloneLookUp.h>
16 
17 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
18 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
19 
20 using namespace Belle2;
21 using namespace TrackFindingCDC;
22 
24 {
27 }
28 
30 {
33 }
34 
35 bool BestMatchedTruthVarSet::extract(const CDCTrack* ptrCDCTrack)
36 {
37  if (not ptrCDCTrack) return false;
38 
40  const CDCMCTrackLookUp& mcTrackLookUp = CDCMCTrackLookUp::getInstance();
41  const CDCMCHitLookUp& hitLookUp = CDCMCHitLookUp::getInstance();
43 
44  ITrackType trackMCMatch = mcTrackLookUp.getMCTrackId(ptrCDCTrack);
45  bool trackIsFake = false;
46 
47  unsigned int numberOfCorrectHits = 0;
48 
50  bool trackHasMinimalMatchPurity = (trackMCMatch != INVALID_ITRACK);
51 
52  if (not trackHasMinimalMatchPurity) {
53  trackIsFake = true;
54  } else {
56  auto hitIsCorrect = [&hitLookUp, &trackMCMatch](const CDCRecoHit3D & recoHit) {
57  return hitLookUp.getMCTrackId(recoHit.getWireHit().getHit()) == trackMCMatch;
58  };
59  numberOfCorrectHits = std::count_if(begin(*ptrCDCTrack), end(*ptrCDCTrack), hitIsCorrect);
60 
61  const double purity = (double)numberOfCorrectHits / ptrCDCTrack->size();
62  if (purity < 0.8) {
63  trackIsFake = true;
64  } else {
65  trackIsFake = false;
66  }
67  }
68 
69  bool trackIsClone = cloneLookUp.isTrackClone(*ptrCDCTrack);
70  bool matchedNotClone = (not trackIsClone) and (not trackIsFake);
71  var<named("truth")>() = matchedNotClone;
72  var<named("truth_track_is_fake")>() = trackIsFake;
73  var<named("truth_track_is_matched")>() = not trackIsFake;
74  var<named("truth_matched_hits")>() = numberOfCorrectHits;
75  var<named("truth_track_is_clone")>() = trackIsClone;
76  var<named("truth_first_nloops")>() = mcTrackLookUp.getFirstNLoops(ptrCDCTrack);
77  var<named("truth_event_id")>() = m_eventMetaData->getEvent();
78  var<named("truth_MCTrackID")>() = trackMCMatch;
79  return true;
80 }
Belle2::TrackFindingCDC::BestMatchedTruthVarSet::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
Pointer to the store array object with the EventMetaData.
Definition: BestMatchedTruthVarSet.h:82
Belle2::TrackFindingCDC::CDCRecoHit3D
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:62
Belle2::TrackFindingCDC::BestMatchedTruthVarSet::beginEvent
void beginEvent() final
Prepare the Monte Carlo truth information at start of the event.
Definition: BestMatchedTruthVarSet.cc:29
Belle2::TrackFindingCDC::CDCTrack
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:51
Belle2::TrackFindingCDC::CDCMCHitCollectionLookUp::getMCTrackId
ITrackType getMCTrackId(const ACDCHitCollection *ptrHits) const
Getter for the Monte Carlo track id matched to this collection of hits.
Definition: CDCMCHitCollectionLookUp.icc.h:101
Belle2::TrackFindingCDC::CDCMCHitCollectionLookUp::getFirstNLoops
Index getFirstNLoops(const ACDCHitCollection *ptrHits) const
Getter for number of loops till the first hit the collection of hits which has the Monte Carlo track ...
Definition: CDCMCHitCollectionLookUp.h:151
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
Belle2::TrackFindingCDC::CDCMCManager::requireTruthInformation
void requireTruthInformation()
Require the mc information store arrays.
Definition: CDCMCManager.cc:117
Belle2::TrackFindingCDC::BestMatchedTruthVarSet::initialize
void initialize() final
Require the Monte Carlo truth information at initialisation.
Definition: BestMatchedTruthVarSet.cc:23
Belle2::TrackFindingCDC::CDCMCManager::fill
void fill()
Fill Monte Carlo look up maps from the DataStore.
Definition: CDCMCManager.cc:137
Belle2::TrackFindingCDC::CDCMCHitLookUp::getMCTrackId
ITrackType getMCTrackId(const CDCHit *ptrHit) const
Returns the track id for the hit.
Definition: CDCMCHitLookUp.cc:122
Belle2::TrackFindingCDC::CDCMCTrackLookUp::getInstance
static const CDCMCTrackLookUp & getInstance()
Getter for the singletone instance.
Definition: CDCMCTrackLookUp.cc:23
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CDCMCHitLookUp
Interface class to the Monte Carlo information for individual hits.
Definition: CDCMCHitLookUp.h:41
Belle2::TrackFindingCDC::CDCMCCloneLookUp
Class providing information whether a PR CDC track is the best match or a clone.
Definition: CDCMCCloneLookUp.h:28
Belle2::TrackFindingCDC::CDCMCManager::getInstance
static CDCMCManager & getInstance()
Getter for the singletone instance.
Definition: CDCMCManager.cc:76
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::beginEvent
void beginEvent() override
Receive and dispatch signal for the start of a new event.
Definition: CompositeProcessingSignalListener.cc:33
Belle2::TrackFindingCDC::CDCMCHitLookUp::getInstance
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
Definition: CDCMCHitLookUp.cc:32
Belle2::TrackFindingCDC::VarSet< BestMatchedTruthVarNames >::named
constexpr static int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:88
Belle2::TrackFindingCDC::VarSet< BestMatchedTruthVarNames >::var
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:103
Belle2::TrackFindingCDC::CDCMCCloneLookUp::getInstance
static CDCMCCloneLookUp & getInstance()
Getter for the singletone instance.
Definition: CDCMCCloneLookUp.cc:11
Belle2::TrackFindingCDC::CDCMCTrackLookUp
Specialisation of the lookup for the truth values of reconstructed tracks.
Definition: CDCMCTrackLookUp.h:33
Belle2::TrackFindingCDC::BestMatchedTruthVarSet::extract
bool extract(const CDCTrack *ptrCDCTrack) override
Generate and assign the contained variables.
Definition: BestMatchedTruthVarSet.cc:35
Belle2::TrackFindingCDC::CDCMCCloneLookUp::isTrackClone
bool isTrackClone(const CDCTrack &cdcTrack)
getter for information from m_cdcTrackIsCloneMap
Definition: CDCMCCloneLookUp.cc:113