10 #include <mva/modules/MVAExpert/MVAMultipleExpertsModule.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 ExtraInfos to the Particle objects in given ParticleLists which is calcuated by multiple experts defined by the given weightfiles.");
34 std::vector<std::string> empty;
36 "Particles from these ParticleLists are used as input. If no name is given the experts are applied to every event once, and one can only use variables which accept nullptr as Particle*",
39 "Names under which the output of the experts is stored in the ExtraInfo of the Particle object.");
40 addParam(
"identifiers",
m_identifiers,
"The database identifiers 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);
43 std::vector<bool> empty_bool;
45 "If true, when the given extraInfo has already defined, the old extraInfo value is overwritten. If false, the original value is kept.",
59 extraInfo.registerInDataStore();
62 extraInfo.registerInDataStore();
66 B2FATAL(
"The number of given m_extraInfoNames is not equal to the number of m_identifiers. The output the ith method in m_identifiers is saved as extraInfo under the ith name in m_extraInfoNames! Set also different names for each method!");
104 }
else B2FATAL(
"No m_identifiers given. At least one is needed!");
121 m_experts[i] = supported_interfaces[general_options.m_method]->getExpert();
127 B2FATAL(
"One or more feature variables could not be loaded via the Variable::Manager. Check the names!");
136 std::vector<float> dummy;
138 m_datasets[i] = std::make_unique<MVA::SingleDataset>(general_options, dummy, 0);
145 std::vector<float> targetValues;
148 if (iVariable.first->variabletype == Variable::Manager::VariableDataType::c_double) {
149 m_feature_variables[iVariable.first] = std::get<double>(iVariable.first->function(particle));
150 }
else if (iVariable.first->variabletype == Variable::Manager::VariableDataType::c_int) {
152 }
else if (iVariable.first->variabletype == Variable::Manager::VariableDataType::c_bool) {
153 m_feature_variables[iVariable.first] = std::get<bool>(iVariable.first->function(particle));
173 for (
unsigned i = 0; i < list->getListSize(); ++i) {
174 Particle* particle = list->getParticle(i);
175 std::vector<float> targetValues =
analyse(particle);
192 if (not eventExtraInfo.isValid())
193 eventExtraInfo.create();
194 std::vector<float> targetValues =
analyse(
nullptr);
215 B2WARNING(
"The extraInfo " <<
m_extraInfoNames[i] <<
" has already been set! It was overwritten by this module!");
217 B2WARNING(
"The extraInfo " <<
m_extraInfoNames[i] <<
" has already been set! "
218 <<
"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...
void init_mva(MVA::Weightfile &weightfile, unsigned int i)
Initialize mva expert, dataset and features Called every time the weightfile in the database changes ...
std::vector< std::unique_ptr< MVA::Expert > > m_experts
Vector of pointers to the current MVA Experts.
virtual void initialize() override
Initialize the module.
std::vector< std::unique_ptr< MVA::SingleDataset > > m_datasets
Vector of pointers to the current input datasets.
std::vector< float > analyse(Particle *)
Calculates expert output for given Particle pointer.
virtual void event() override
Called for each event.
std::vector< bool > m_existGivenExtraInfo
check if the given extraInfo is already defined.
std::vector< std::vector< const Variable::Manager::Var * > > m_individual_feature_variables
Vector of pointers to the feature variables for each expert.
virtual void terminate() override
Called at the end of the event processing.
double m_signal_fraction_override
Signal Fraction which should be used.
std::vector< std::string > m_identifiers
weight-files
std::vector< std::string > m_listNames
input particle list names
MVAMultipleExpertsModule()
Constructor.
virtual void beginRun() override
Called at the beginning of a new run.
std::map< const Variable::Manager::Var *, float > m_feature_variables
Map containing the values of all needed feature variables.
std::vector< std::string > m_extraInfoNames
Names under which the SignalProbability is stored in the extraInfo of the Particle object.
std::vector< std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > > m_weightfile_representations
Vector of database pointers to the Database representation of the weightfile.
std::vector< bool > m_overwriteExistingExtraInfo
if true, when the given extraInfo is already defined, the old extraInfo value is overwritten
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.