Belle II Software  release-06-01-15
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 
12 using namespace Belle2;
13 
14 double 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 
24 QualityEstimatorMC::MatchInfo QualityEstimatorMC::getBestMatchToMCClusters(std::vector<SpacePoint const*> const& measurements)
25 {
26  std::map<MCRecoTrackIndex, NMatches> matches;
27 
28  for (SpacePoint const* spacePoint : measurements) {
29 
30  for (SVDCluster& cluster : spacePoint->getRelationsTo<SVDCluster>(m_svdClustersName)) {
31  for (RecoTrack& recoTrack : cluster.getRelationsWith<RecoTrack>(m_mcRecoTracksStoreArrayName)) {
32  // Increase number of matches to this RecoTrack
33  matches[recoTrack.getArrayIndex()]++;
34  }
35  } // end loop SVDClusters
36 
37  for (PXDCluster& cluster : spacePoint->getRelationsTo<PXDCluster>(m_pxdClustersName)) {
38  for (RecoTrack& recoTrack : cluster.getRelationsWith<RecoTrack>(m_mcRecoTracksStoreArrayName)) {
39  // Increase number of matches to this RecoTrack
40  matches[recoTrack.getArrayIndex()] += 2;
41  }
42  } // end loop PXDClusters
43 
44  } // end loop SpacePoints
45 
46  // select best match as the one with the most matched clusters.
47  MatchInfo bestMatch = *std::max_element(matches.begin(), matches.end(),
48  [](MatchInfo const & lhs, MatchInfo const & rhs) {return lhs.second < rhs.second;});
49  return bestMatch;
50 }
51 
52 double QualityEstimatorMC::calculateQualityIndicator(unsigned int nClusters, MatchInfo& match)
53 {
54  double qualityIndicator = 0;
55  if (m_mva_target) {
56  if (nClusters == m_mcRecoTracks[match.first]->getNumberOfSVDHits()) {
57  qualityIndicator = 1 - (1. / nClusters);
58  }
59  } else if (m_strictQualityIndicator) {
60  if (nClusters == match.second) {
61  qualityIndicator = 1 - (1. / nClusters);
62  }
63  } else {
64  int nRecoTrackClusters = m_mcRecoTracks[match.first]->getNumberOfSVDHits();
65  qualityIndicator = std::pow(match.second, 3) / (nRecoTrackClusters * nClusters * nClusters);
66  }
67  return qualityIndicator;
68 }
69 
70 
71 QualityEstimationResults QualityEstimatorMC::estimateQualityAndProperties(std::vector<SpacePoint const*> const& measurements)
72 {
74  if (m_results.qualityIndicator != 0) {
75  auto mcParticle = m_mcRecoTracks[m_match.first]->getRelated<MCParticle>();
76  m_results.p = mcParticle->getMomentum();
77  m_results.pt = mcParticle->get4Vector().Pt();
78  }
79  return m_results;
80 }
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_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:76
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:28
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
Abstract base class for different kinds of events.
Container for complete fit/estimation results.
double qualityIndicator
return value of the quality estimator
boost::optional< double > pt
transverse momentum estimate from the QE
boost::optional< B2Vector3D > p
momentum vector estimate from the QE