 |
Belle II Software
release-05-02-19
|
12 #include <mva/modules/MVAExpert/MVAMultipleExpertsModule.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 ExtraInfos to the Particle objects in given ParticleLists which is calcuated by multiple experts defined by the given weightfiles.");
40 std::vector<std::string> empty;
42 "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*",
44 addParam(
"extraInfoNames", m_extraInfoNames,
45 "Names under which the output of the experts is stored in the ExtraInfo of the Particle object.");
46 addParam(
"identifiers", m_identifiers,
"The database identifiers 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();
68 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!");
114 MVA::GeneralOptions general_options;
115 weightfile.getOptions(general_options);
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;
165 StoreObjPtr<ParticleList> list(listName);
167 for (
unsigned i = 0; i < list->getListSize(); ++i) {
168 Particle* particle = list->getParticle(i);
169 std::vector<float> targetValues =
analyse(particle);
173 B2WARNING(
"Extra Info with given name is already set! Overwriting old value!");
182 StoreObjPtr<EventExtraInfo> eventExtraInfo;
183 if (not eventExtraInfo.isValid())
184 eventExtraInfo.create();
185 std::vector<float> targetValues =
analyse(
nullptr);
188 B2WARNING(
"Extra Info with given name is already set! I won't set it again!");
void init_mva(MVA::Weightfile &weightfile, unsigned int i)
Initialize mva expert, dataset and features Called everytime the weightfile in the database changes i...
std::vector< std::unique_ptr< MVA::SingleDataset > > m_datasets
Vector of pointers to the current input datasets.
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::vector< std::unique_ptr< MVA::Expert > > m_experts
Vector of pointers to the current MVA Experts.
double m_signal_fraction_override
Signal Fraction which should be used.
std::vector< std::string > m_listNames
input particle list names
virtual void initialize() override
Initialize the module.
MVAMultipleExpertsModule()
Constructor.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
std::vector< std::string > m_extraInfoNames
Names under which the SignalProbability is stored in the extraInfo of the Particle object.
std::vector< float > analyse(Particle *)
Calculates expert output for given Particle pointer.
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.
std::vector< std::string > m_identifiers
weight-files
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.
std::vector< std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > > m_weightfile_representations
Vector of database pointers to the Database representation of the weightfile.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
std::vector< std::string > m_listNames
input particle list names
virtual void beginRun() override
Called at the beginning of a new run.
virtual void event() override
Called for each event.
std::map< const Variable::Manager::Var *, float > m_feature_variables
Map containing the values of all needed feature variables.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
std::vector< std::vector< const Variable::Manager::Var * > > m_individual_feature_variables
Vector of pointers to the feature variables for each expert.
static Manager & Instance()
get singleton instance.