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;
16
17
18REG_MODULE(VXDQualityEstimatorMVA);
19
21{
22 //Set module properties
23 setDescription("The quality estimator module for SpacePointTrackCandidates.");
25
26 addParam("EstimationMethod",
28 "Identifier which estimation method to use. Valid identifiers are: [tripletFit, circleFit, helixFit]",
30
31 addParam("SpacePointTrackCandsStoreArrayName",
33 "Name of StoreArray containing the SpacePointTrackCandidates to be estimated.",
35
36
37 addParam("WeightFileIdentifier",
39 "Identifier of weightfile in Database or local root/xml file.",
41
42 addParam("UseTimingInfo",
44 "Whether to use timing information available in the weight file",
46
47 addParam("ClusterInformation",
49 "How to compile information from clusters ['Average']",
51}
52
54{
56
57 m_qeResultsExtractor = std::make_unique<QEResultsExtractor>(m_EstimationMethod, m_variableSet);
58
59 m_variableSet.emplace_back("NSpacePoints", &m_nSpacePoints);
60
61 if (m_ClusterInformation == "Average") {
62 m_clusterInfoExtractor = std::make_unique<ClusterInfoExtractor>(m_variableSet, m_UseTimingInfo);
63 }
64
65 m_mvaExpert = std::make_unique<MVAExpert>(m_weightFileIdentifier, m_variableSet);
66 m_mvaExpert->initialize();
67
68 // create pointer to chosen estimator
69 if (m_EstimationMethod == "tripletFit") {
70 m_estimator = std::make_unique<QualityEstimatorTripletFit>();
71 } else if (m_EstimationMethod == "circleFit") {
72 m_estimator = std::make_unique<QualityEstimatorCircleFit>();
73 } else if (m_EstimationMethod == "helixFit") {
74 m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
75 }
76 B2ASSERT("QualityEstimator could not be initialized with method: " << m_EstimationMethod, m_estimator);
77}
78
80{
81 m_mvaExpert->beginRun();
82 // BField is required by all QualityEstimators
83 const double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
84 m_estimator->setMagneticFieldStrength(bFieldZ);
85}
86
88{
89 // assign a QI computed using the selected QualityEstimator for each given SpacePointTrackCand
90 for (SpacePointTrackCand& spacePointTrackCand : m_spacePointTrackCands) {
91 if (not spacePointTrackCand.hasRefereeStatus(SpacePointTrackCand::c_isActive)) {
92 continue;
93 }
94
95 std::vector<SpacePoint const*> const sortedHits = spacePointTrackCand.getSortedHits();
96
97 if (m_ClusterInformation == "Average") {
98 m_clusterInfoExtractor->extractVariables(sortedHits);
99 }
100
101 m_nSpacePoints = sortedHits.size();
102
103 m_qeResultsExtractor->extractVariables(m_estimator->estimateQualityAndProperties(sortedHits));
104
105 const float qi = m_mvaExpert->predict();
106 spacePointTrackCand.setQualityIndicator(qi);
107 }
108}
Base class for Modules.
Definition: Module.h:72
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
@ 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.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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::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,...
std::unique_ptr< MVAExpert > m_mvaExpert
pointer to the object to interact with the MVA package
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::vector< Named< float * > > m_variableSet
set of named variables to be used in MVA
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:91
Abstract base class for different kinds of events.