Belle II Software development
VXDQualityEstimatorMVAModule.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/modules/vxdtfQualityEstimator/VXDQualityEstimatorMVAModule.h>
10#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
11#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
12#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
13#include <framework/geometry/BFieldManager.h>
14
15using namespace Belle2;
16using namespace TrackingUtilities;
17
18
19REG_MODULE(VXDQualityEstimatorMVA);
20
22{
23 //Set module properties
24 setDescription("The quality estimator module for SpacePointTrackCandidates.");
26
27 addParam("EstimationMethod",
29 "Identifier which estimation method to use. Valid identifiers are: [tripletFit, circleFit, helixFit]",
31
32 addParam("SpacePointTrackCandsStoreArrayName",
34 "Name of StoreArray containing the SpacePointTrackCandidates to be estimated.",
36
37
38 addParam("WeightFileIdentifier",
40 "Identifier of weightfile in Database or local root/xml file.",
42
43 addParam("UseTimingInfo",
45 "Whether to use timing information available in the weight file",
47
48 addParam("ClusterInformation",
50 "How to compile information from clusters ['Average']",
52}
53
55{
57
58 m_qeResultsExtractor = std::make_unique<QEResultsExtractor>(m_EstimationMethod, m_variableSet);
59
60 m_variableSet.emplace_back("NSpacePoints", &m_nSpacePoints);
61
62 if (m_ClusterInformation == "Average") {
63 m_clusterInfoExtractor = std::make_unique<ClusterInfoExtractor>(m_variableSet, m_UseTimingInfo);
64 }
65
66 m_mvaExpert = std::make_unique<MVAExpert>(m_weightFileIdentifier, m_variableSet);
67 m_mvaExpert->initialize();
68
69 // create pointer to chosen estimator
70 if (m_EstimationMethod == "tripletFit") {
71 m_estimator = std::make_unique<QualityEstimatorTripletFit>();
72 } else if (m_EstimationMethod == "circleFit") {
73 m_estimator = std::make_unique<QualityEstimatorCircleFit>();
74 } else if (m_EstimationMethod == "helixFit") {
75 m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
76 }
77 B2ASSERT("QualityEstimator could not be initialized with method: " << m_EstimationMethod, m_estimator);
78}
79
81{
82 m_mvaExpert->beginRun();
83 // BField is required by all QualityEstimators
84 const double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
85 m_estimator->setMagneticFieldStrength(bFieldZ);
86}
87
89{
90 // assign a QI computed using the selected QualityEstimator for each given SpacePointTrackCand
91 for (SpacePointTrackCand& spacePointTrackCand : m_spacePointTrackCands) {
92 if (not spacePointTrackCand.hasRefereeStatus(SpacePointTrackCand::c_isActive)) {
93 continue;
94 }
95
96 std::vector<SpacePoint const*> const sortedHits = spacePointTrackCand.getSortedHits();
97
98 if (m_ClusterInformation == "Average") {
99 m_clusterInfoExtractor->extractVariables(sortedHits);
100 }
101
102 m_nSpacePoints = sortedHits.size();
103
104 m_qeResultsExtractor->extractVariables(m_estimator->estimateQualityAndProperties(sortedHits));
105
106 const float qi = m_mvaExpert->predict();
107 spacePointTrackCand.setQualityIndicator(qi);
108 }
109}
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
Storage for (VXD) SpacePoint-based track candidates.
@ c_isActive
bit 11: SPTC is active (i.e.
static const double T
[tesla]
Definition Unit.h:120
std::string m_SpacePointTrackCandsStoreArrayName
Name of the expected StoreArray containing SpacePointTrackCands.
void initialize() override
Initializes the Module.
void event() override
Applies the selected quality estimation method for a given set of TCs.
std::unique_ptr< TrackingUtilities::MVAExpert > m_mvaExpert
pointer to the object to interact with the MVA package
std::vector< TrackingUtilities::Named< float * > > m_variableSet
set of named variables to be used in MVA
std::string m_EstimationMethod
Identifier which estimation method to use.
float m_nSpacePoints
number of SpacePoints in SPTC as additional info for MVA, type is float to be consistent with m_varia...
std::unique_ptr< QEResultsExtractor > m_qeResultsExtractor
pointer to object that extracts the results from the estimation method (including QI,...
bool m_UseTimingInfo
whether to use timing information available in the weight file
std::string m_weightFileIdentifier
identifier of weightfile in Database or local root/xml file
VXDQualityEstimatorMVAModule()
Constructor of the module.
void beginRun() override
Launches mvaExpert and sets the magnetic field strength.
std::unique_ptr< ClusterInfoExtractor > m_clusterInfoExtractor
pointer to object that extracts info from the clusters of a SPTC
std::unique_ptr< QualityEstimatorBase > m_estimator
pointer to the selected QualityEstimator
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
the storeArray for SpacePointTrackCands as member, is faster than recreating link for each event
std::string m_ClusterInformation
how to compile information from clusters ['Average']
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.