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