8#include <tracking/trackFindingVXD/mva/MVAExpert.h>
11#include <mva/interface/Interface.h>
13#include <framework/utilities/FileSystem.h>
14#include <framework/logging/Logger.h>
16#include <boost/algorithm/string/predicate.hpp>
22 : m_allNamedVariables(
std::move(namedVariables))
23 , m_identifier(identifier)
30 using boost::algorithm::ends_with;
40 std::unique_ptr<MVA::Weightfile> weightfile =
getWeightFile();
43 if (weightfile->getElement<std::string>(
"method") ==
"FastBDT" and
44 (weightfile->getElement<
int>(
"FastBDT_version") == 1 or
45 weightfile->getElement<
int>(
"FastBDT_version") == 2)) {
47 int nExpectedVars = weightfile->getElement<
int>(
"number_feature_variables");
50 for (
int iVar = 0; iVar < nExpectedVars; ++iVar) {
51 std::string variableElementName =
"variable" + std::to_string(iVar);
52 std::string expectedName = weightfile->getElement<std::string>(variableElementName);
57 return namedVariable.getName() == expectedName;
61 B2ERROR(
"Variable name " << iVar <<
" mismatch for FastBDT. " <<
62 "Could not find expected variable '" << expectedName <<
"'");
68 B2WARNING(
"Unpacked new kind of classifier. Consider to extend the feature variable check.");
72 std::map<std::string, MVA::AbstractInterface*> supportedInterfaces =
75 weightfile->getOptions(generalOptions);
79 std::vector<float> dummy;
81 m_dataset = std::make_unique<MVA::SingleDataset>(generalOptions, std::move(dummy), 0);
83 B2ERROR(
"Could not find weight file for identifier " <<
m_identifier);
90 std::stringstream ss((*m_weightfileRepresentation)->m_data);
101 B2ERROR(
"MVA Expert is not loaded! I will return 0");
Class for accessing objects in the database.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
void initialize()
Initialise the mva method.
void beginRun()
Update the mva method to the new run.
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfileRepresentation
Database pointer to the Database representation of the weightfile.
MVAExpert(const std::string &identifier, std::vector< Named< float * > > namedVariables)
Construct the Expert with the specified weight folder and the name of the training that was used in t...
std::unique_ptr< MVA::Weightfile > getWeightFile()
Resolves the source of the weight file and unpacks it.
std::unique_ptr< MVA::Expert > m_expert
Pointer to the current MVA Expert.
std::vector< Named< float * > > m_selectedNamedVariables
References to the selected named values from the source variable set.
std::unique_ptr< MVA::Dataset > m_dataset
Pointer to the current dataset.
float predict()
Evaluate the MVA method and return the MVAOutput.
std::vector< Named< float * > > m_allNamedVariables
References to the named values from the source variable set.
std::string m_identifier
DB identifier of the expert or file name.
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
General options which are shared by all MVA trainings.
std::string m_method
Name of the MVA method to use.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
A mixin class to attach a name to an object. Based on class with same name in CDC package.
Abstract base class for different kinds of events.