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