10 #include <mva/modules/MVAExpert/MVAExpertModule.h>
12 #include <analysis/dataobjects/Particle.h>
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <analysis/dataobjects/ParticleExtraInfoMap.h>
15 #include <analysis/dataobjects/EventExtraInfo.h>
17 #include <mva/interface/Interface.h>
19 #include <boost/algorithm/string/predicate.hpp>
22 #include <framework/logging/Logger.h>
31 setDescription(
"Adds an ExtraInfo to the Particle objects in given ParticleLists which is calcuated by an expert defined by a weightfile.");
34 std::vector<std::string> empty;
36 "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*",
39 "Name under which the output of the expert is stored in the ExtraInfo of the Particle object.");
40 addParam(
"identifier",
m_identifier,
"The database identifier which is used to load the weights during the training.");
42 "signalFraction to calculate probability (if -1 the signalFraction of the training data is used)", -1.0);
44 "If true, when the given extraInfo has already defined, the old extraInfo value is overwritten. If false, the original value is kept.",
58 extraInfo.registerInDataStore();
61 extraInfo.registerInDataStore();
78 std::stringstream ss((*m_weightfile_representation)->m_data);
100 m_expert = supported_interfaces[general_options.m_method]->getExpert();
106 B2FATAL(
"One or more feature variables could not be loaded via the Variable::Manager. Check the names!");
109 std::vector<float> dummy;
111 m_dataset = std::make_unique<MVA::SingleDataset>(general_options, dummy, 0);
118 B2ERROR(
"MVA Expert is not loaded! I will return 0");
123 if (std::holds_alternative<double>(var_result)) {
124 m_dataset->m_input[i] = std::get<double>(var_result);
125 }
else if (std::holds_alternative<int>(var_result)) {
126 m_dataset->m_input[i] = std::get<int>(var_result);
127 }
else if (std::holds_alternative<bool>(var_result)) {
128 m_dataset->m_input[i] = std::get<bool>(var_result);
140 for (
unsigned i = 0; i < list->getListSize(); ++i) {
141 Particle* particle = list->getParticle(i);
142 float targetValue =
analyse(particle);
156 if (not eventExtraInfo.isValid())
157 eventExtraInfo.create();
159 float targetValue =
analyse(
nullptr);
177 B2WARNING(
"The extraInfo " <<
m_extraInfoName <<
" has already been set! It was overwritten by this module!");
179 B2WARNING(
"The extraInfo " <<
m_extraInfoName <<
" has already been set! "
180 <<
"The original value was kept and this module did not overwrite it!");
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
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.
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::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.
bool m_existGivenExtraInfo
check if the given extraInfo is already defined.
float analyse(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.
bool m_overwriteExistingExtraInfo
if true, when the given extraInfo is already defined, the old extraInfo value is overwritten
std::string m_identifier
weight-file
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
General options which are shared by all MVA trainings.
The Weightfile class serializes all information about a training into an xml tree.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
void getOptions(Options &options) const
Fills an Option object from the xml tree.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
void addSignalFraction(float signal_fraction)
Saves the signal fraction in the xml tree.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class to store reconstructed particles.
void setExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
double getExtraInfo(const std::string &name) const
Return given value if set.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
Global list of available variables.
static Manager & Instance()
get singleton instance.
REG_MODULE(B2BIIConvertBeamParams)
Register the module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.