 |
Belle II Software
release-05-02-19
|
12 #include <mva/modules/MVAExpert/MVAExpertModule.h>
14 #include <analysis/dataobjects/Particle.h>
15 #include <analysis/dataobjects/ParticleList.h>
16 #include <analysis/dataobjects/ParticleExtraInfoMap.h>
17 #include <analysis/dataobjects/EventExtraInfo.h>
19 #include <mva/interface/Interface.h>
21 #include <boost/algorithm/string/predicate.hpp>
24 #include <framework/logging/Logger.h>
37 setDescription(
"Adds an ExtraInfo to the Particle objects in given ParticleLists which is calcuated by an expert defined by a weightfile.");
40 std::vector<std::string> empty;
42 "Particles from these ParticleLists are used as input. If no name is given the expert is applied to every event once, and one can only use variables which accept nullptr as Particle*",
44 addParam(
"extraInfoName", m_extraInfoName,
45 "Name under which the output of the expert is stored in the ExtraInfo of the Particle object.");
46 addParam(
"identifier",
m_identifier,
"The database identifier which is used to load the weights during the training.");
48 "signalFraction to calculate probability (if -1 the signalFraction of the training data is used)", -1.0);
61 extraInfo.registerInDataStore();
64 extraInfo.registerInDataStore();
80 std::stringstream ss((*m_weightfile_representation)->m_data);
95 MVA::GeneralOptions general_options;
96 weightfile.getOptions(general_options);
102 m_expert = supported_interfaces[general_options.m_method]->getExpert();
108 B2FATAL(
"One or more feature variables could not be loaded via the Variable::Manager. Check the names!");
111 std::vector<float> dummy;
113 m_dataset = std::make_unique<MVA::SingleDataset>(general_options, dummy, 0);
120 B2ERROR(
"MVA Expert is not loaded! I will return 0");
133 StoreObjPtr<ParticleList> list(listName);
135 for (
unsigned i = 0; i < list->getListSize(); ++i) {
136 Particle* particle = list->getParticle(i);
137 float targetValue =
analyse(particle);
139 B2WARNING(
"Extra Info with given name is already set! Overwriting old value!");
147 StoreObjPtr<EventExtraInfo> eventExtraInfo;
148 if (not eventExtraInfo.isValid())
149 eventExtraInfo.create();
151 B2WARNING(
"Extra Info with given name is already set! I won't set it again!");
153 float targetValue =
analyse(
nullptr);
std::string m_identifier
weight-file
std::string m_extraInfoName
Name under which the SignalProbability is stored in the extraInfo of the Particle object.
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
void setDescription(const std::string &description)
Sets the description of the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
std::unique_ptr< MVA::Expert > m_expert
Pointer to the current MVA Expert.
MVAExpertModule()
Constructor.
std::vector< std::string > m_listNames
input particle list names
virtual void initialize() override
Initialize the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
void init_mva(MVA::Weightfile &weightfile)
Initialize mva expert, dataset and features Called everytime the weightfile in the database changes i...
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation
Database pointer to the Database representation of the weightfile.
Abstract base class for different kinds of events.
Type-safe access to single objects in the data store.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
double m_signal_fraction_override
Signal Fraction which should be used.
std::string m_identifier
database identifier or filename of the weightfile
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
double m_signal_fraction_override
Signal Fraction which should be used.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
float analyse(Particle *)
Calculates expert output for given Particle pointer.
std::unique_ptr< MVA::SingleDataset > m_dataset
Pointer to the current dataset.
virtual void beginRun() override
Called at the beginning of a new run.
virtual void event() override
Called for each event.
std::vector< const Variable::Manager::Var * > m_feature_variables
Pointers to the feature variables.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Global list of available variables.
static Manager & Instance()
get singleton instance.