Belle II Software  release-05-01-25
QualityEstimatorMC.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Felix Metzner, Jonas Wagner *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include "tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h"
12 #include <mdst/dataobjects/MCParticle.h>
13 
14 using namespace Belle2;
15 
16 double QualityEstimatorMC::estimateQuality(std::vector<SpacePoint const*> const& measurements)
17 {
18  if (measurements.empty()) return 0;
19 
20  m_match = getBestMatchToMCClusters(measurements);
21 
22  // assuming that each SpacePoint corresponds to two Clusters. Now valid for both SVD and PXD
23  return calculateQualityIndicator(measurements.size() * 2, m_match);
24 }
25 
26 QualityEstimatorMC::MatchInfo QualityEstimatorMC::getBestMatchToMCClusters(std::vector<SpacePoint const*> const& measurements)
27 {
28  std::map<MCRecoTrackIndex, NMatches> matches;
29 
30  for (SpacePoint const* spacePoint : measurements) {
31 
32  for (SVDCluster& cluster : spacePoint->getRelationsTo<SVDCluster>(m_svdClustersName)) {
33  for (RecoTrack& recoTrack : cluster.getRelationsWith<RecoTrack>(m_mcRecoTracksStoreArrayName)) {
34  // Increase number of matches to this RecoTrack
35  matches[recoTrack.getArrayIndex()]++;
36  }
37  } // end loop SVDClusters
38 
39  for (PXDCluster& cluster : spacePoint->getRelationsTo<PXDCluster>(m_pxdClustersName)) {
40  for (RecoTrack& recoTrack : cluster.getRelationsWith<RecoTrack>(m_mcRecoTracksStoreArrayName)) {
41  // Increase number of matches to this RecoTrack
42  matches[recoTrack.getArrayIndex()] += 2;
43  }
44  } // end loop PXDClusters
45 
46  } // end loop SpacePoints
47 
48  // select best match as the one with the most matched clusters.
49  MatchInfo bestMatch = *std::max_element(matches.begin(), matches.end(),
50  [](MatchInfo const & lhs, MatchInfo const & rhs) {return lhs.second < rhs.second;});
51  return bestMatch;
52 }
53 
54 double QualityEstimatorMC::calculateQualityIndicator(unsigned int nClusters, MatchInfo& match)
55 {
56  double qualityIndicator = 0;
57  if (m_mva_target) {
58  if (nClusters == m_mcRecoTracks[match.first]->getNumberOfSVDHits()) {
59  qualityIndicator = 1 - (1. / nClusters);
60  }
61  } else if (m_strictQualityIndicator) {
62  if (nClusters == match.second) {
63  qualityIndicator = 1 - (1. / nClusters);
64  }
65  } else {
66  int nRecoTrackClusters = m_mcRecoTracks[match.first]->getNumberOfSVDHits();
67  qualityIndicator = std::pow(match.second, 3) / (nRecoTrackClusters * nClusters * nClusters);
68  }
69  return qualityIndicator;
70 }
71 
72 
73 QualityEstimationResults QualityEstimatorMC::estimateQualityAndProperties(std::vector<SpacePoint const*> const& measurements)
74 {
76  if (m_results.qualityIndicator != 0) {
77  auto mcParticle = m_mcRecoTracks[m_match.first]->getRelated<MCParticle>();
78  m_results.p = mcParticle->getMomentum();
79  m_results.pt = mcParticle->get4Vector().Pt();
80  }
81  return m_results;
82 }
Belle2::QualityEstimatorMC::MatchInfo
std::pair< MCRecoTrackIndex, NMatches > MatchInfo
typedef for MatchInfo
Definition: QualityEstimatorMC.h:37
Belle2::QualityEstimationResults::p
boost::optional< B2Vector3< double > > p
momentum vector estimate from the QE
Definition: QualityEstimatorBase.h:42
Belle2::QualityEstimationResults
Container for complete fit/estimation results.
Definition: QualityEstimatorBase.h:36
Belle2::QualityEstimatorMC::estimateQualityAndProperties
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
Definition: QualityEstimatorMC.cc:73
Belle2::QualityEstimatorMC::m_pxdClustersName
std::string m_pxdClustersName
PXD clusters StoreArray name.
Definition: QualityEstimatorMC.h:99
Belle2::QualityEstimationResults::qualityIndicator
double qualityIndicator
return value of the quality estimator
Definition: QualityEstimatorBase.h:37
Belle2::QualityEstimatorMC::m_svdClustersName
std::string m_svdClustersName
SVD clusters StoreArray name.
Definition: QualityEstimatorMC.h:98
Belle2::QualityEstimationResults::pt
boost::optional< double > pt
transverse momentum estimate from the QE
Definition: QualityEstimatorBase.h:40
Belle2::QualityEstimatorMC::getBestMatchToMCClusters
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 ...
Definition: QualityEstimatorMC.cc:26
Belle2::QualityEstimatorMC::m_mcRecoTracksStoreArrayName
std::string m_mcRecoTracksStoreArrayName
MCRecoTracks StoreArray name.
Definition: QualityEstimatorMC.h:97
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::QualityEstimatorMC::m_mva_target
bool m_mva_target
If true the SPTCs containing all the SVDCluster of the corresponding MCRecoTrack and no other SVDClus...
Definition: QualityEstimatorMC.h:94
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::QualityEstimatorMC::estimateQuality
virtual double estimateQuality(std::vector< SpacePoint const * > const &measurements) final
Performing MC based quality estimation.
Definition: QualityEstimatorMC.cc:16
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::QualityEstimatorMC::calculateQualityIndicator
double calculateQualityIndicator(unsigned int nClusters, MatchInfo &match)
Calculate MC qualityIndicator based on MatchInfo of best matched MCRecoTrack.
Definition: QualityEstimatorMC.cc:54
Belle2::PXDCluster
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:41
Belle2::QualityEstimatorMC::m_strictQualityIndicator
bool m_strictQualityIndicator
If true only SPTCs containing SVDClusters corresponding to a single MCRecoTrack get a QI !...
Definition: QualityEstimatorMC.h:88
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::QualityEstimatorMC::m_match
MatchInfo m_match
stores the current match for optional return values
Definition: QualityEstimatorMC.h:102
Belle2::QualityEstimatorBase::estimateQualityAndProperties
virtual QualityEstimationResults estimateQualityAndProperties(std::vector< SpacePoint const * > const &measurements)
Quality estimation providing additional quantities Calculates quality indicator in range [0,...
Definition: QualityEstimatorBase.h:79
Belle2::QualityEstimatorBase::m_results
QualityEstimationResults m_results
Result of the quality estimation This is stored as a member variable, because some values may be calc...
Definition: QualityEstimatorBase.h:101
Belle2::QualityEstimatorMC::m_mcRecoTracks
StoreArray< RecoTrack > m_mcRecoTracks
the storeArray for RecoTracks as member
Definition: QualityEstimatorMC.h:105