8#include <tracking/trackingUtilities/mva/MVAExpert.h>
11#include <mva/dataobjects/DatabaseRepresentationOfWeightfile.h>
12#include <mva/interface/Expert.h>
13#include <mva/interface/Weightfile.h>
14#include <framework/database/DBObjPtr.h>
15#include <boost/algorithm/string/predicate.hpp>
29 namespace TrackingUtilities {
39 std::vector<float>
predict(
float* ,
int ,
int );
68#include <mva/interface/Interface.h>
70#include <framework/utilities/FileSystem.h>
71#include <framework/logging/Logger.h>
76using namespace TrackingUtilities;
88 using boost::algorithm::ends_with;
95 B2FATAL(
"No weight file could be loaded in tracking/trackingUtilities/mva/MVAExpert.");
101 std::unique_ptr<MVA::Weightfile> weightfile =
getWeightFile();
103 if ((weightfile->getElement<std::string>(
"method") ==
"FastBDT" and
104 (weightfile->getElement<
int>(
"FastBDT_version") == 1 or
105 weightfile->getElement<
int>(
"FastBDT_version") == 2)) or
106 (weightfile->getElement<std::string>(
"method") ==
"Python")) {
108 int nExpectedVars = weightfile->getElement<
int>(
"number_feature_variables");
111 for (
int iVar = 0; iVar < nExpectedVars; ++iVar) {
112 std::string variableElementName =
"variable" + std::to_string(iVar);
113 std::string expectedName = weightfile->getElement<std::string>(variableElementName);
117 return namedVariable.getName() == expectedName;
121 B2ERROR(
"Variable name " << iVar <<
" mismatch for FastBDT. " <<
122 "Could not find expected variable '" << expectedName <<
"'");
128 B2WARNING(
"Unpacked new kind of classifier. Consider to extend the feature variable check. Identifier name: " <<
m_identifier
129 <<
"; method name: " << weightfile->getElement<std::string>(
"method"));
133 std::map<std::string, MVA::AbstractInterface*> supportedInterfaces =
139 std::vector<float> dummy;
143 B2ERROR(
"Could not find weight file for identifier " <<
m_identifier);
150 std::stringstream ss((*m_weightfileRepresentation)->m_data);
161 B2ERROR(
"MVA Expert is not loaded! I will return 0");
174 std::vector<std::vector<float>> spectators;
175 std::vector<std::vector <float> > data;
177 for (
int iRow = 0; iRow < nRows; iRow += 1) {
178 data[iRow].resize(nFeature);
179 for (
int iFeature = 0; iFeature < nFeature; iFeature += 1) {
180 data[iRow][iFeature] = test_data[nFeature * iRow + iFeature];
213 return m_impl->initialize();
218 return m_impl->beginRun();
228 return m_impl->predict(test_data, nFeature, nRows);
233 return m_impl->getVariableNames();
Class for accessing objects in the database.
Database representation of a Weightfile object.
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...
static void initSupportedInterfaces()
Static function which initializes all supported interfaces, has to be called once before getSupported...
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Abstract base class of all Expert Each MVA library has its own implementation of this class,...
General options which are shared by all MVA trainings.
Wraps the data of a multiple event into a Dataset.
Wraps the data of a single event into a Dataset.
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.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
Implementation of the class to interact with the MVA package.
void initialize()
Signal the beginning of the event processing.
void beginRun()
Called once before a new run begins.
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfileRepresentation
Database pointer to the Database representation of the weightfile.
std::unique_ptr< MVA::Weightfile > getWeightFile()
Get the weight file.
std::unique_ptr< MVA::Expert > m_expert
Pointer to the current MVA Expert.
std::vector< Named< Float_t * > > m_selectedNamedVariables
References to the selected named values from the source variable set.
Impl(const std::string &identifier, std::vector< Named< Float_t * > > namedVariables)
constructor
std::unique_ptr< MVA::Dataset > m_dataset
Pointer to the current dataset.
std::vector< Named< Float_t * > > m_allNamedVariables
References to the all named values from the source variable set.
MVA::GeneralOptions m_generalOptions
General options.
double predict()
Get the MVA prediction.
std::vector< std::string > getVariableNames()
Get selected variable names.
std::string m_identifier
DB identifier of the expert or file name.
void initialize()
Initialise the mva method.
void beginRun()
Update the mva method to the new run.
std::unique_ptr< Impl > m_impl
Pointer to implementation hiding the details.
~MVAExpert()
Destructor must be defined in cpp because of PImpl pointer.
MVAExpert(const std::string &identifier, std::vector< Named< Float_t * > > namedVariables)
Construct the Expert with the specified weight folder and the name of the training that was used in t...
double predict()
Evaluate the MVA method and return the MVAOutput.
std::vector< std::string > getVariableNames()
Get selected variable names.
A mixin class to attach a name to an object.
Abstract base class for different kinds of events.