Belle II Software  release-05-01-25
SVDMCUtil.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/svd/utilities/SVDMCUtil.h>
11 
12 #include <tracking/ckf/svd/entities/CKFToSVDState.h>
13 #include <tracking/mcMatcher/TrackMatchLookUp.h>
14 #include <tracking/dataobjects/RecoTrack.h>
15 #include <svd/dataobjects/SVDCluster.h>
16 #include <tracking/spacePointCreation/SpacePoint.h>
17 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
18 #include <tracking/trackFindingCDC/numerics/WithWeight.h>
19 
20 using namespace Belle2;
21 
22 bool MCUtil::hitIsCorrect(const RecoTrack* mcRecoTrack, const SpacePoint* spacePoint) const
23 {
24  const auto isSameMCTrack = [&mcRecoTrack](const RecoTrack & clusterRecoTrack) {
25  return &clusterRecoTrack == mcRecoTrack;
26  };
27 
28 
29  const std::string& mcRecoTrackStoreArrayName = mcRecoTrack->getArrayName();
30 
31  for (const SVDCluster& relatedCluster : spacePoint->getRelationsTo<SVDCluster>()) {
32  const auto& relatedMCTracksToCluster = relatedCluster.getRelationsTo<RecoTrack>(mcRecoTrackStoreArrayName);
33  if (not TrackFindingCDC::any(relatedMCTracksToCluster, isSameMCTrack)) {
34  return false;
35  }
36  }
37 
38  // Test if these clusters are on the first half of the track
39  // For this, get the reco hit information of the related hit
40  const RecoHitInformation* recoHitInformationOfHit = mcRecoTrack->getRecoHitInformation(spacePoint->getRelatedTo<SVDCluster>());
41  B2ASSERT("Invalid MC information", recoHitInformationOfHit);
42 
43  // then we also need the first exit out of this detector
44  const std::vector<RecoHitInformation*> recoHitInformationList = mcRecoTrack->getRecoHitInformations(true);
45  // For this, we get an iterator into the first entry (there must be at least one hit in this detector, so we are safe)
46  const auto& detector = recoHitInformationOfHit->getTrackingDetector();
47 
48  const auto& itToFirstEntryInDetector = std::find_if(recoHitInformationList.begin(), recoHitInformationList.end(),
49  [detector](RecoHitInformation * hitInformation) {
50  return hitInformation->getTrackingDetector() == detector;
51  });
52  const auto& itToFirstEntryAfterDetector = std::find_if(itToFirstEntryInDetector, recoHitInformationList.end(),
53  [detector](RecoHitInformation * hitInformation) {
54  return hitInformation->getTrackingDetector() != detector;
55  });
56 
57  if (itToFirstEntryAfterDetector == recoHitInformationList.end()) {
58  // This is a really strange case: it should actually not be possible to find such a hit. Better
59  // remove it.
60  return false;
61  }
62 
63  const auto* firstHitAfterDetector = *itToFirstEntryAfterDetector;
64  return firstHitAfterDetector->getSortingParameter() >= recoHitInformationOfHit->getSortingParameter();
65 }
66 
67 unsigned int MCUtil::getNumberOfCorrectHits(const RecoTrack* mcRecoTrack, const std::vector<const SpacePoint*>& hits) const
68 {
69 
70  const auto hitIsCorrectSpecialisation = [this, mcRecoTrack](const SpacePoint * spacePoint) {
71  return hitIsCorrect(mcRecoTrack, spacePoint);
72  };
73 
74  const unsigned int numberOfCorrectHits = std::count_if(hits.begin(), hits.end(), hitIsCorrectSpecialisation);
75  return numberOfCorrectHits;
76 }
77 
79 {
80  const RecoTrack* seed = states.front()->getSeed();
81 
82  B2ASSERT("Path without a seed?", seed);
83 
84  if (states.size() <= 1) {
85  // just the seed? this can not be correct...
86  return false;
87  }
88 
89  const std::string& seedTrackStoreArrayName = seed->getArrayName();
90 
91  TrackMatchLookUp mcCDCMatchLookUp("MCRecoTracks", seedTrackStoreArrayName);
92  const RecoTrack* mcTrack = mcCDCMatchLookUp.getRelatedMCRecoTrack(*seed);
93 
94  if (not mcTrack) {
95  // Track is a fake
96  B2DEBUG(100, "Seed is a fake");
97  return false;
98  }
99 
100  std::vector<const SpacePoint*> spacePoints;
101  for (const CKFToSVDState* state : states) {
102  const SpacePoint* spacePoint = state->getHit();
103  if (spacePoint) {
104  spacePoints.push_back(spacePoint);
105  }
106  }
107 
108  const unsigned int numberOfCorrectHits = getNumberOfCorrectHits(mcTrack, spacePoints);
109 
110  B2DEBUG(100, "Have found " << numberOfCorrectHits << " correct out of " << spacePoints.size() << " hits");
111  return numberOfCorrectHits == spacePoints.size();
112 }
Belle2::MCUtil::getNumberOfCorrectHits
unsigned int getNumberOfCorrectHits(const RecoTrack *mcRecoTrack, const std::vector< const SpacePoint * > &hits) const
How many of the given space points are also in the MC track? Runs hitIsCorrect on all of them.
Definition: SVDMCUtil.cc:67
Belle2::RecoHitInformation::getTrackingDetector
RecoHitDetector getTrackingDetector() const
Get the detector this hit comes from.
Definition: RecoHitInformation.h:248
Belle2::RelationsInterface::getArrayName
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Definition: RelationsObject.h:379
Belle2::RelationsInterface::getRelatedTo
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Definition: RelationsObject.h:250
Belle2::TrackMatchLookUp
Class to provide convenient methods to look up matching information between pattern recognition and M...
Definition: TrackMatchLookUp.h:43
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::RecoTrack::getRecoHitInformation
RecoHitInformation * getRecoHitInformation(HitType *hit) const
Return the reco hit information for a generic hit from the storeArray.
Definition: RecoTrack.h:309
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackMatchLookUp::getRelatedMCRecoTrack
const RecoTrack * getRelatedMCRecoTrack(const RecoTrack &prRecoTrack) const
Looks for a related Monte Carlo track for the given pattern recognition track and return it if found.
Definition: TrackMatchLookUp.cc:119
Belle2::RecoHitInformation
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
Definition: RecoHitInformation.h:48
Belle2::TrackFindingCDC::WithWeight
A mixin class to attach a weight to an object.
Definition: WithWeight.h:34
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::RecoTrack::getRecoHitInformations
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
Definition: RecoTrack.cc:531
Belle2::MCUtil::allStatesCorrect
bool allStatesCorrect(const std::vector< TrackFindingCDC::WithWeight< const CKFToPXDState * >> &states) const
Are all hits related to the same MC track the seed is related to?
Definition: PXDMCUtil.cc:77
Belle2::RecoHitInformation::getSortingParameter
unsigned int getSortingParameter() const
Get the sorting parameter.
Definition: RecoHitInformation.h:224
Belle2::CKFToSVDState
Specialized CKF State for extrapolating into the SVD.
Definition: CKFToSVDState.h:29
Belle2::MCUtil::hitIsCorrect
bool hitIsCorrect(const RecoTrack *mcRecoTrack, const SpacePoint *spacePoint) const
Returns true, of the space point is related to the mc track and if it is on the first half.
Definition: SVDMCUtil.cc:22