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