Belle II Software development
QualityEstimatorMC Class Reference

Class implementing the algorithm used for the MC based quality estimation. More...

#include <QualityEstimatorMC.h>

Inheritance diagram for QualityEstimatorMC:
QualityEstimatorBase

Public Types

typedef int MCRecoTrackIndex
 typedef for MCRecoTrackIndex
 
typedef unsigned int NMatches
 typedef for counter of number of matches
 
typedef std::pair< MCRecoTrackIndex, NMatchesMatchInfo
 typedef for MatchInfo
 

Public Member Functions

 QualityEstimatorMC (const std::string &mcRecoTracksStoreArrayName="MCRecoTracks", bool strictQualityIndicator=true, bool mva_target=false)
 Constructor.
 
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
 
void setClustersNames (const std::string &svdClustersName, const std::string &pxdClustersName)
 Setter for StoreArray names of SVD and PXD clusters, if those are not set by the user it will be tried to read them from the MCRecoTracks StoreArray.
 
void forceUpdateClusterNames ()
 Setter to force the class to update its cluster names.
 
void setMagneticFieldStrength (double magneticFieldZ=1.5)
 Setter for z component of magnetic field.
 

Protected Member Functions

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 to the given track candidate.
 
double calculateQualityIndicator (unsigned int nClusters, MatchInfo &match)
 Calculate MC qualityIndicator based on MatchInfo of best matched MCRecoTrack.
 
double calcPt (double const radius) const
 Returns a value for the transverse momentum in GeV calculated from a provided radius.
 

Protected Attributes

bool m_strictQualityIndicator
 If true only SPTCs containing SVDClusters corresponding to a single MCRecoTrack get a QI != 0.
 
bool m_mva_target
 If true the SPTCs containing all the SVDCluster of the corresponding MCRecoTrack and no other SVDCluster receive a Quality Index larger than one.
 
std::string m_mcRecoTracksStoreArrayName
 MCRecoTracks StoreArray name.
 
std::string m_svdClustersName = ""
 SVD clusters StoreArray name.
 
std::string m_pxdClustersName = ""
 PXD clusters StoreArray name.
 
bool m_clusterNamesNeedSetting
 if true cluster names need to be set, either by calling setClustersNames or read from MCRecoTracks at first call
 
MatchInfo m_match
 stores the current match for optional return values
 
StoreArray< RecoTrackm_mcRecoTracks
 the storeArray for RecoTracks as member
 
double m_magneticFieldZ = 1.5
 Member storing the z component of the magnetic field.
 
QualityEstimationResults m_results
 Result of the quality estimation This is stored as a member variable, because some values may be calculated by 'estimateQuality' anyways.
 

Detailed Description

Class implementing the algorithm used for the MC based quality estimation.

Definition at line 22 of file QualityEstimatorMC.h.

Member Typedef Documentation

◆ MatchInfo

typedef std::pair<MCRecoTrackIndex, NMatches> MatchInfo

typedef for MatchInfo

Definition at line 27 of file QualityEstimatorMC.h.

◆ MCRecoTrackIndex

typedef int MCRecoTrackIndex

typedef for MCRecoTrackIndex

Definition at line 25 of file QualityEstimatorMC.h.

◆ NMatches

typedef unsigned int NMatches

typedef for counter of number of matches

Definition at line 26 of file QualityEstimatorMC.h.

Constructor & Destructor Documentation

◆ QualityEstimatorMC()

QualityEstimatorMC ( const std::string &  mcRecoTracksStoreArrayName = "MCRecoTracks",
bool  strictQualityIndicator = true,
bool  mva_target = false 
)
inline

Constructor.

Parameters
mcRecoTracksStoreArrayName: Name of the MCRecoTracks StoreArray
strictQualityIndicator: boolean whether to perform strict estimation
mva_target: Boolean whether to perform quality estimation for MVA QE training. This overwrites the strictQualityIndicator option!

Definition at line 35 of file QualityEstimatorMC.h.

36 :
37 QualityEstimatorBase(), m_strictQualityIndicator(strictQualityIndicator), m_mva_target(mva_target),
38 m_mcRecoTracksStoreArrayName(mcRecoTracksStoreArrayName)
39 {
41 };
bool m_strictQualityIndicator
If true only SPTCs containing SVDClusters corresponding to a single MCRecoTrack get a QI !...
StoreArray< RecoTrack > m_mcRecoTracks
the storeArray for RecoTracks as member
bool m_mva_target
If true the SPTCs containing all the SVDCluster of the corresponding MCRecoTrack and no other SVDClus...
std::string m_mcRecoTracksStoreArrayName
MCRecoTracks StoreArray name.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.

Member Function Documentation

◆ calcPt()

double calcPt ( double const  radius) const
inlineprotectedinherited

Returns a value for the transverse momentum in GeV calculated from a provided radius.

Utilizing m_magneticFieldZ and hard coded speed of light

Definition at line 80 of file QualityEstimatorBase.h.

80{ return m_magneticFieldZ * radius * 0.00299792458; }
double m_magneticFieldZ
Member storing the z component of the magnetic field.

◆ calculateQualityIndicator()

double calculateQualityIndicator ( unsigned int  nClusters,
MatchInfo match 
)
protected

Calculate MC qualityIndicator based on MatchInfo of best matched MCRecoTrack.

Parameters
nClusters: number of clusters of the track candidate
match: MatchInfo for the best match
Returns
qualityIndicator

Definition at line 66 of file QualityEstimatorMC.cc.

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}

◆ estimateQuality()

double estimateQuality ( std::vector< SpacePoint const * > const &  measurements)
finalvirtual

Performing MC based quality estimation.

Parameters
measurements: SPs of the track candidate to be evaluate
Returns
quality indicator value

Implements QualityEstimatorBase.

Definition at line 14 of file QualityEstimatorMC.cc.

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}
MatchInfo m_match
stores the current match for optional return values
double calculateQualityIndicator(unsigned int nClusters, MatchInfo &match)
Calculate MC qualityIndicator based on MatchInfo of best matched MCRecoTrack.
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 ...

◆ estimateQualityAndProperties()

QualityEstimationResults estimateQualityAndProperties ( std::vector< SpacePoint const * > const &  measurements)
finaloverridevirtual

additionally return momentum_truth if it is a perfect match to a single MCRecoTrack

Reimplemented from QualityEstimatorBase.

Definition at line 85 of file QualityEstimatorMC.cc.

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
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...
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516
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

◆ forceUpdateClusterNames()

void forceUpdateClusterNames ( )
inline

Setter to force the class to update its cluster names.

The cluster names have to be set either by calling setClustersNames or will be automatically read from first entry of MCRecoTracks when calling one of the functions doing the estimation for the first time

Definition at line 67 of file QualityEstimatorMC.h.

bool m_clusterNamesNeedSetting
if true cluster names need to be set, either by calling setClustersNames or read from MCRecoTracks at...

◆ getBestMatchToMCClusters()

QualityEstimatorMC::MatchInfo getBestMatchToMCClusters ( std::vector< SpacePoint const * > const &  measurements)
protected

Get MCRecoTrack index of best matching tracks and number of matched MC clusters which can be matched to the given track candidate.

Parameters
measurements: SPs to be evaluated
Returns
MatchInfo containing the ID of the best matching MCRecoTracks and number of matched clusters

Definition at line 24 of file QualityEstimatorMC.cc.

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}
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
std::string m_svdClustersName
SVD clusters StoreArray name.
std::pair< MCRecoTrackIndex, NMatches > MatchInfo
typedef for MatchInfo
std::string m_pxdClustersName
PXD clusters StoreArray name.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
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

◆ setClustersNames()

void setClustersNames ( const std::string &  svdClustersName,
const std::string &  pxdClustersName 
)
inline

Setter for StoreArray names of SVD and PXD clusters, if those are not set by the user it will be tried to read them from the MCRecoTracks StoreArray.

Parameters
svdClustersName: SVD cluster StoreArray name
pxdClustersName: PXD cluster StoreArray name

Definition at line 56 of file QualityEstimatorMC.h.

57 {
58 m_svdClustersName = svdClustersName;
59 m_pxdClustersName = pxdClustersName;
61 };

◆ setMagneticFieldStrength()

void setMagneticFieldStrength ( double  magneticFieldZ = 1.5)
inlineinherited

Setter for z component of magnetic field.

Parameters
magneticFieldZ: value to set it to

Definition at line 53 of file QualityEstimatorBase.h.

53{m_magneticFieldZ = magneticFieldZ;}

Member Data Documentation

◆ m_clusterNamesNeedSetting

bool m_clusterNamesNeedSetting
protected
Initial value:
=
true

if true cluster names need to be set, either by calling setClustersNames or read from MCRecoTracks at first call

Definition at line 100 of file QualityEstimatorMC.h.

◆ m_magneticFieldZ

double m_magneticFieldZ = 1.5
protectedinherited

Member storing the z component of the magnetic field.

Definition at line 84 of file QualityEstimatorBase.h.

◆ m_match

MatchInfo m_match
protected

stores the current match for optional return values

Definition at line 104 of file QualityEstimatorMC.h.

◆ m_mcRecoTracks

StoreArray<RecoTrack> m_mcRecoTracks
protected

the storeArray for RecoTracks as member

Definition at line 107 of file QualityEstimatorMC.h.

◆ m_mcRecoTracksStoreArrayName

std::string m_mcRecoTracksStoreArrayName
protected

MCRecoTracks StoreArray name.

Definition at line 97 of file QualityEstimatorMC.h.

◆ m_mva_target

bool m_mva_target
protected

If true the SPTCs containing all the SVDCluster of the corresponding MCRecoTrack and no other SVDCluster receive a Quality Index larger than one.

To be used for MVA QE training if both high hit purity and hit efficiency is desired.

Definition at line 94 of file QualityEstimatorMC.h.

◆ m_pxdClustersName

std::string m_pxdClustersName = ""
protected

PXD clusters StoreArray name.

Definition at line 99 of file QualityEstimatorMC.h.

◆ m_results

QualityEstimationResults m_results
protectedinherited

Result of the quality estimation This is stored as a member variable, because some values may be calculated by 'estimateQuality' anyways.

Therefore they don't need to be calculated explicitly in 'estimateQualityAndProperties'.

Definition at line 90 of file QualityEstimatorBase.h.

◆ m_strictQualityIndicator

bool m_strictQualityIndicator
protected

If true only SPTCs containing SVDClusters corresponding to a single MCRecoTrack get a QI != 0.

If a SVDCluster corresponds to several MCRecoTracks it is still valid as long as the correct MCRecoTrack is one of them.

Definition at line 88 of file QualityEstimatorMC.h.

◆ m_svdClustersName

std::string m_svdClustersName = ""
protected

SVD clusters StoreArray name.

Definition at line 98 of file QualityEstimatorMC.h.


The documentation for this class was generated from the following files: