Belle II Software  release-05-01-25
PXDMCUtil.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/pxd/utilities/PXDMCUtil.h>
11 
12 #include <tracking/ckf/pxd/entities/CKFToPXDState.h>
13 #include <tracking/mcMatcher/TrackMatchLookUp.h>
14 #include <tracking/dataobjects/RecoTrack.h>
15 #include <pxd/dataobjects/PXDCluster.h>
16 #include <tracking/spacePointCreation/SpacePoint.h>
17 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
18 
19 using namespace Belle2;
20 
21 bool MCUtil::pxdHitIsCorrect(const RecoTrack* mcRecoTrack, const SpacePoint* spacePoint) const
22 {
23  const auto isSameMCTrack = [&mcRecoTrack](const RecoTrack & clusterRecoTrack) {
24  return &clusterRecoTrack == mcRecoTrack;
25  };
26 
27 
28  const std::string& mcRecoTrackStoreArrayName = mcRecoTrack->getArrayName();
29 
30  for (const PXDCluster& relatedCluster : spacePoint->getRelationsTo<PXDCluster>()) {
31  const auto& relatedMCTracksToCluster = relatedCluster.getRelationsTo<RecoTrack>(mcRecoTrackStoreArrayName);
32  if (not TrackFindingCDC::any(relatedMCTracksToCluster, isSameMCTrack)) {
33  return false;
34  }
35  }
36 
37  // Test if these clusters are on the first half of the track
38  // For this, get the reco hit information of the related hit
39  const RecoHitInformation* recoHitInformationOfHit = mcRecoTrack->getRecoHitInformation(spacePoint->getRelatedTo<PXDCluster>());
40  B2ASSERT("Invalid MC information", recoHitInformationOfHit);
41 
42  // then we also need the first exit out of this detector
43  const std::vector<RecoHitInformation*> recoHitInformationList = mcRecoTrack->getRecoHitInformations(true);
44  // For this, we get an iterator into the first entry (there must be at least one hit in this detector, so we are safe)
45  const auto& detector = recoHitInformationOfHit->getTrackingDetector();
46 
47  const auto& itToFirstEntryInDetector = std::find_if(recoHitInformationList.begin(), recoHitInformationList.end(),
48  [detector](RecoHitInformation * hitInformation) {
49  return hitInformation->getTrackingDetector() == detector;
50  });
51  const auto& itToFirstEntryAfterDetector = std::find_if(itToFirstEntryInDetector, recoHitInformationList.end(),
52  [detector](RecoHitInformation * hitInformation) {
53  return hitInformation->getTrackingDetector() != detector;
54  });
55 
56  if (itToFirstEntryAfterDetector == recoHitInformationList.end()) {
57  // This is a really strange case: it should actually not be possible to find such a hit. Better
58  // remove it.
59  return false;
60  }
61 
62  const auto* firstHitAfterDetector = *itToFirstEntryAfterDetector;
63  return firstHitAfterDetector->getSortingParameter() >= recoHitInformationOfHit->getSortingParameter();
64 }
65 
66 unsigned int MCUtil::getNumberOfCorrectPXDHits(const RecoTrack* mcRecoTrack, const std::vector<const SpacePoint*>& hits) const
67 {
68 
69  const auto hitIsCorrectSpecialisation = [this, mcRecoTrack](const SpacePoint * spacePoint) {
70  return pxdHitIsCorrect(mcRecoTrack, spacePoint);
71  };
72 
73  const unsigned int numberOfCorrectHits = std::count_if(hits.begin(), hits.end(), hitIsCorrectSpecialisation);
74  return numberOfCorrectHits;
75 }
76 
78 {
79  const RecoTrack* seed = states.front()->getSeed();
80 
81  B2ASSERT("Path without a seed?", seed);
82 
83  if (states.size() <= 1) {
84  // just the seed? this can not be correct...
85  return false;
86  }
87 
88  const std::string& seedTrackStoreArrayName = seed->getArrayName();
89 
90  TrackMatchLookUp mcCDCMatchLookUp("MCRecoTracks", seedTrackStoreArrayName);
91  const RecoTrack* mcTrack = mcCDCMatchLookUp.getRelatedMCRecoTrack(*seed);
92 
93  if (not mcTrack) {
94  // Track is a fake
95  B2DEBUG(100, "Seed is a fake");
96  return false;
97  }
98 
99  std::vector<const SpacePoint*> spacePoints;
100  for (const CKFToPXDState* state : states) {
101  const SpacePoint* spacePoint = state->getHit();
102  if (spacePoint) {
103  spacePoints.push_back(spacePoint);
104  }
105  }
106 
107  const unsigned int numberOfCorrectHits = getNumberOfCorrectPXDHits(mcTrack, spacePoints);
108 
109  B2DEBUG(100, "Have found " << numberOfCorrectHits << " correct out of " << spacePoints.size() << " hits");
110  return numberOfCorrectHits == spacePoints.size();
111 }
Belle2::RecoHitInformation::getTrackingDetector
RecoHitDetector getTrackingDetector() const
Get the detector this hit comes from.
Definition: RecoHitInformation.h:248
Belle2::CKFToPXDState
Specialized CKF State for extrapolating into the PXD.
Definition: CKFToPXDState.h:29
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::PXDCluster
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:41
Belle2::TrackFindingCDC::WithWeight
A mixin class to attach a weight to an object.
Definition: WithWeight.h:34
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::getNumberOfCorrectPXDHits
unsigned int getNumberOfCorrectPXDHits(const RecoTrack *mcRecoTrack, const std::vector< const SpacePoint * > &hits) const
How many of the given space points are also in the MC track? Runs pxdHitIsCorrect on all of them.
Definition: PXDMCUtil.cc:66
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::MCUtil::pxdHitIsCorrect
bool pxdHitIsCorrect(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: PXDMCUtil.cc:21