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>
35 setDescription(
"Adds an ExtraInfo to the Particle objects in given ParticleLists which is calcuated by an expert defined by a weightfile.");
36 setPropertyFlags(c_ParallelProcessingCertified);
38 std::vector<std::string> empty;
39 addParam(
"listNames", m_listNames,
40 "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*",
42 addParam(
"extraInfoName", m_extraInfoName,
43 "Name under which the output of the expert is stored in the ExtraInfo of the Particle object.");
44 addParam(
"identifier", m_identifier,
"The database identifier which is used to load the weights during the training.");
45 addParam(
"signalFraction", m_signal_fraction_override,
46 "signalFraction to calculate probability (if -1 the signalFraction of the training data is used)", -1.0);
59 extraInfo.registerInDataStore();
62 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");
133 for (
unsigned i = 0; i < list->getListSize(); ++i) {
134 Particle* particle = list->getParticle(i);
135 float targetValue =
analyse(particle);
138 B2WARNING(
"Extra Info with given name is already set! Overwriting old value!");
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);
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
This module adds an ExtraInfo to the Particle objects in a given ParticleList.
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.
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
std::string m_extraInfoName
Name under which the SignalProbability is stored in the extraInfo of the Particle object.
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.
Class to store reconstructed particles.
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.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
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.
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 ...
Abstract base class for different kinds of events.