Belle II Software  release-08-01-10
MVAExpertModule.h
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 #pragma once
10 
11 #include <framework/core/Module.h>
12 
13 #include <mva/dataobjects/DatabaseRepresentationOfWeightfile.h>
14 #include <mva/interface/Weightfile.h>
15 #include <mva/interface/Expert.h>
16 
17 #include <framework/datastore/StoreArray.h>
18 #include <framework/database/DBObjPtr.h>
19 
20 #include <analysis/DecayDescriptor/DecayDescriptor.h>
21 #include <analysis/VariableManager/Manager.h>
22 #include <framework/dataobjects/EventExtraInfo.h>
23 
24 #include <vector>
25 #include <string>
26 
27 namespace Belle2 {
33  class Particle;
34 
42  class MVAExpertModule : public Module {
43  public:
44 
49 
53  virtual void initialize() override;
54 
58  virtual void beginRun() override;
59 
63  virtual void event() override;
64 
68  virtual void terminate() override;
69 
70  private:
74  float analyse(const Particle*);
75 
79  std::vector<float> analyseMulticlass(const Particle*);
80 
85  void init_mva(MVA::Weightfile& weightfile);
86 
90  void fillDataset(const Particle*);
91 
95  void setExtraInfoField(Particle*, std::string, float);
96 
100  void setEventExtraInfoField(StoreObjPtr<EventExtraInfo>, std::string, float);
101 
102 
103  private:
111  std::unordered_map<std::string, DecayDescriptor> m_decaydescriptors;
112  std::vector<std::string> m_listNames;
113  std::vector<std::string> m_targetListNames;
114  std::string m_identifier;
115  std::string m_extraInfoName;
118  std::vector<const Variable::Manager::Var*> m_feature_variables;
120  std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>
122  std::unique_ptr<MVA::Expert> m_expert;
123  std::unique_ptr<MVA::SingleDataset> m_dataset;
128  unsigned int
130  };
131 
133 } // Belle2 namespace
134 
This module adds an ExtraInfo to the Particle objects in a given ParticleList.
std::unordered_map< std::string, DecayDescriptor > m_decaydescriptors
Decay descriptor of decays to look for.
std::unique_ptr< MVA::SingleDataset > m_dataset
Pointer to the current dataset.
std::vector< const Variable::Manager::Var * > m_feature_variables
Pointers to the feature variables.
virtual void initialize() override
Initialize the module.
virtual void event() override
Called for each event.
void setEventExtraInfoField(StoreObjPtr< EventExtraInfo >, std::string, float)
Set the event extra info field.
StoreArray< Particle > m_particles
StoreArray of Particles.
virtual void terminate() override
Called at the end of the event processing.
std::unique_ptr< MVA::Expert > m_expert
Pointer to the current MVA Expert.
double m_signal_fraction_override
Signal Fraction which should be used.
std::vector< std::string > m_targetListNames
input particle list names after decay descriptor
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation
Database pointer to the Database representation of the weightfile.
std::vector< std::string > m_listNames
input particle list names
virtual void beginRun() override
Called at the beginning of a new run.
MVAExpertModule()
Constructor.
float analyse(const Particle *)
Calculates expert output for given Particle pointer.
bool m_existGivenExtraInfo
check if the given extraInfo is already defined.
int m_overwriteExistingExtraInfo
-1/0/1/2: overwrite if lower/ don't overwrite / overwrite if higher/ always overwrite,...
std::vector< float > analyseMulticlass(const Particle *)
Calculates expert output for given Particle pointer.
void init_mva(MVA::Weightfile &weightfile)
Initialize mva expert, dataset and features Called every time the weightfile in the database changes ...
std::string m_extraInfoName
Name under which the SignalProbability is stored in the extraInfo of the Particle object.
unsigned int m_nClasses
number of classes (~outputs) of the current MVA Expert.
void setExtraInfoField(Particle *, std::string, float)
Set the extra info field.
void fillDataset(const Particle *)
Evaluate the variables and fill the Dataset to be used by the expert.
std::string m_identifier
weight-file
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:38
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:75
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Abstract base class for different kinds of events.