Belle II Software development
QualityEstimatorMC.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
9#include "tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h"
10#include <mdst/dataobjects/MCParticle.h>
11
12using namespace Belle2;
13
14double QualityEstimatorMC::estimateQuality(std::vector<SpacePoint const*> const& measurements)
15{
16 if (measurements.empty()) return 0;
17
18 m_match = getBestMatchToMCClusters(measurements);
19
20 // assuming that each SpacePoint corresponds to two Clusters. Now valid for both SVD and PXD
21 return calculateQualityIndicator(measurements.size() * 2, m_match);
22}
23
24QualityEstimatorMC::MatchInfo QualityEstimatorMC::getBestMatchToMCClusters(std::vector<SpacePoint const*> const& measurements)
25{
26 std::map<MCRecoTrackIndex, NMatches> matches;
27
28 // if the SVD and PXD cluster names have not been set by user, try to read them from the MCRecoTracks
30 B2INFO("Trying to read StoreArray names for Clusters from first entry of " << m_mcRecoTracksStoreArrayName);
31
32 if (m_mcRecoTracks.getEntries() > 0) {
33 m_svdClustersName = m_mcRecoTracks[0]->getStoreArrayNameOfSVDHits();
34 m_pxdClustersName = m_mcRecoTracks[0]->getStoreArrayNameOfPXDHits();
36 } else {
37 B2WARNING("No Entries in mcRecoTracksStoreArray: " << m_mcRecoTracksStoreArrayName <<
38 " The default names for the clusters are used");
39 }
40 }
41
42 for (SpacePoint const* spacePoint : measurements) {
43
44 for (SVDCluster& cluster : spacePoint->getRelationsTo<SVDCluster>(m_svdClustersName)) {
45 for (RecoTrack& recoTrack : cluster.getRelationsWith<RecoTrack>(m_mcRecoTracksStoreArrayName)) {
46 // Increase number of matches to this RecoTrack
47 matches[recoTrack.getArrayIndex()]++;
48 }
49 } // end loop SVDClusters
50
51 for (PXDCluster& cluster : spacePoint->getRelationsTo<PXDCluster>(m_pxdClustersName)) {
52 for (RecoTrack& recoTrack : cluster.getRelationsWith<RecoTrack>(m_mcRecoTracksStoreArrayName)) {
53 // Increase number of matches to this RecoTrack
54 matches[recoTrack.getArrayIndex()] += 2;
55 }
56 } // end loop PXDClusters
57
58 } // end loop SpacePoints
59
60 // select best match as the one with the most matched clusters.
61 MatchInfo bestMatch = *std::max_element(matches.begin(), matches.end(),
62 [](MatchInfo const & lhs, MatchInfo const & rhs) {return lhs.second < rhs.second;});
63 return bestMatch;
64}
65
66double QualityEstimatorMC::calculateQualityIndicator(unsigned int nClusters, MatchInfo& match)
67{
68 double qualityIndicator = 0;
69 if (m_mva_target) {
70 if (nClusters == m_mcRecoTracks[match.first]->getNumberOfSVDHits()) {
71 qualityIndicator = 1 - (1. / nClusters);
72 }
73 } else if (m_strictQualityIndicator) {
74 if (nClusters == match.second) {
75 qualityIndicator = 1 - (1. / nClusters);
76 }
77 } else {
78 int nRecoTrackClusters = m_mcRecoTracks[match.first]->getNumberOfSVDHits();
79 qualityIndicator = std::pow(match.second, 3) / (nRecoTrackClusters * nClusters * nClusters);
80 }
81 return qualityIndicator;
82}
83
84
85QualityEstimationResults QualityEstimatorMC::estimateQualityAndProperties(std::vector<SpacePoint const*> const& measurements)
86{
88 if (m_results.qualityIndicator != 0) {
89 auto mcParticle = m_mcRecoTracks[m_match.first]->getRelated<MCParticle>();
90 m_results.p = B2Vector3D(mcParticle->getMomentum());
91 m_results.pt = mcParticle->get4Vector().Pt();
92 }
93 return m_results;
94}
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
virtual QualityEstimationResults estimateQualityAndProperties(std::vector< SpacePoint const * > const &measurements)
Quality estimation providing additional quantities Calculates quality indicator in range [0,...
QualityEstimationResults m_results
Result of the quality estimation This is stored as a member variable, because some values may be calc...
std::string m_svdClustersName
SVD clusters StoreArray name.
bool m_clusterNamesNeedSetting
if true cluster names need to be set, either by calling setClustersNames or read from MCRecoTracks at...
bool m_strictQualityIndicator
If true only SPTCs containing SVDClusters corresponding to a single MCRecoTrack get a QI !...
MatchInfo m_match
stores the current match for optional return values
StoreArray< RecoTrack > m_mcRecoTracks
the storeArray for RecoTracks as member
std::pair< MCRecoTrackIndex, NMatches > MatchInfo
typedef for MatchInfo
double calculateQualityIndicator(unsigned int nClusters, MatchInfo &match)
Calculate MC qualityIndicator based on MatchInfo of best matched MCRecoTrack.
bool m_mva_target
If true the SPTCs containing all the SVDCluster of the corresponding MCRecoTrack and no other SVDClus...
std::string m_pxdClustersName
PXD clusters StoreArray name.
MatchInfo getBestMatchToMCClusters(std::vector< SpacePoint const * > const &measurements)
Get MCRecoTrack index of best matching tracks and number of matched MC clusters which can be matched ...
virtual double estimateQuality(std::vector< SpacePoint const * > const &measurements) final
Performing MC based quality estimation.
virtual QualityEstimationResults estimateQualityAndProperties(std::vector< SpacePoint const * > const &measurements) override final
additionally return momentum_truth if it is a perfect match to a single MCRecoTrack
std::string m_mcRecoTracksStoreArrayName
MCRecoTracks StoreArray name.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
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
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516
Abstract base class for different kinds of events.
Container for complete fit/estimation results.
std::optional< double > pt
transverse momentum estimate from the QE
double qualityIndicator
return value of the quality estimator
std::optional< B2Vector3D > p
momentum vector estimate from the QE