Belle II Software development
FlipQualityModule.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/flipQualityModule/FlipQualityModule.h>
10#include <mva/interface/Interface.h>
11
12#include <boost/algorithm/string/predicate.hpp>
13#include <memory>
14
15namespace Belle2 {
21 REG_MODULE(FlipQuality);
24 {
25 setDescription("This Module is meant to apply the (index 1 or 2) mva based filter to determine if a recoTracks should be flipped");
26
28
29 addParam("identifier", m_identifier, "The database identifier or filename which is used to load the weights during the training.",
31
32 addParam("recoTracksStoreArrayName", m_recoTracksStoreArrayName, "Name of the recoTrack StoreArray.", m_recoTracksStoreArrayName);
33
34 addParam("indexOfFlippingMVA", m_flipMVAIndex, "Index of flipping MVA. (1 or 2).", m_flipMVAIndex);
35 }
36
38 {
39 // If the identifier does not end on .root or .xml, we are dealing with a database identifier
40 // so we need to create a DBObjPtr, which will fetch the weightfile from the database
42
43 if (m_flipMVAIndex == 1) {
44 m_recoTrackExtractor = std::make_unique<FlipRecoTrackExtractor>(m_variableSet);
45 } else if (m_flipMVAIndex == 2) {
46 m_recoTrackExtractor2nd = std::make_unique<FlipRecoTrackExtractor2nd>(m_variableSet);
47 } else {
48 B2FATAL("no input value extractor!");
49 }
50 // The supported methods have to be initialized once (calling it more than once is save)
51 m_mvaExpert = std::make_unique<MVAExpert>(m_identifier, m_variableSet);
52 m_mvaExpert->initialize();
53 }
54
56 {
57
58 // Just to be safe we check if the MVA::Expert is loaded
59 if (not m_mvaExpert) {
60 B2FATAL("MVA Expert is not loaded!");
61 }
62 m_mvaExpert->beginRun();
63
64 }
65
67 {
68
69 // fill the dataset
70 // The order must be the same as the order of the variables in general_options.m_variables
71 for (RecoTrack& recoTrack : m_recoTracks) {
72 // for the 1st MVA
73 // we call the corresponding class and set the Qi using setFlipQualityIndicator()
74 if (m_flipMVAIndex == 1) {
75 m_recoTrackExtractor->extractVariables(recoTrack);
76 float probability = m_mvaExpert->predict();
77 recoTrack.setFlipQualityIndicator(probability);
78
79 } else if (m_flipMVAIndex == 2) {
80 // for the 2nd MVA
81 // first check if the flipped track was created or not.
82 // then call the corresponding class and set the 2nd Qi using set2ndFlipQualityIndicator()
83 RecoTrack* RecoTrackflipped = recoTrack.getRelatedFrom<RecoTrack>("RecoTracks_flipped");
84 if (RecoTrackflipped) {
85 m_recoTrackExtractor2nd->extractVariables(recoTrack);
86 float probability = m_mvaExpert->predict();
87 recoTrack.set2ndFlipQualityIndicator(probability);
88 }
89 } else {
90 B2DEBUG(20, "Nothing will be saved into the flipping qi");
91
92 }
93
94 }
95
96 }
97
99} // Belle2 namespace
100
std::unique_ptr< MVAExpert > m_mvaExpert
Pointer to the current MVA Expert
std::vector< Named< float * > > m_variableSet
the variable set for the MVA
std::unique_ptr< FlipRecoTrackExtractor > m_recoTrackExtractor
the dataExtractor for the 1st MVA
StoreArray< RecoTrack > m_recoTracks
Store Array of the recoTracks.
std::string m_recoTracksStoreArrayName
the recoTracks StoreArray Name
int m_flipMVAIndex
index of the QI (must be 1 or 2)
std::unique_ptr< FlipRecoTrackExtractor2nd > m_recoTrackExtractor2nd
the dataExtractor for the 2nd MVA
std::string m_identifier
database identifier or filename of the weightfile
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
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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
virtual void initialize() override
Initialize the module.
virtual void event() override
Called for each event.
virtual void beginRun() override
Called at the beginning of a new run.
Abstract base class for different kinds of events.