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>
28 namespace TrackingUtilities {
38 std::vector<float>
predict(
const float* ,
int ,
72#include <mva/interface/Interface.h>
74#include <framework/utilities/FileSystem.h>
75#include <framework/logging/Logger.h>
80using namespace TrackingUtilities;
98 B2FATAL(
"No weight file could be loaded in tracking/trackingUtilities/mva/MVAExpert.");
104 std::unique_ptr<MVA::Weightfile> weightfile =
getWeightFile();
107 if ((weightfile->getElement<std::string>(
"method") ==
"FastBDT" and
108 (weightfile->getElement<
int>(
"FastBDT_version") == 1 or
109 weightfile->getElement<
int>(
"FastBDT_version") == 2)) or
110 (weightfile->getElement<std::string>(
"method") ==
"Python")) {
112 int nExpectedVars = weightfile->getElement<
int>(
"number_feature_variables");
115 for (
int iVar = 0; iVar < nExpectedVars; ++iVar) {
116 std::string variableElementName =
"variable" + std::to_string(iVar);
117 std::string expectedName = weightfile->getElement<std::string>(variableElementName);
121 return namedVariable.getName() == expectedName;
125 B2ERROR(
"Variable name " << iVar <<
" mismatch for FastBDT. " <<
126 "Could not find expected variable '" << expectedName <<
"'");
132 B2WARNING(
"Unpacked new kind of classifier. Consider to extend the feature variable check. Identifier name: " <<
m_identifier
133 <<
"; method name: " << weightfile->getElement<std::string>(
"method"));
137 const std::map<std::string, MVA::AbstractInterface*>& supportedInterfaces =
143 std::vector<float> dummy;
147 B2ERROR(
"Could not find weight file for identifier " <<
m_identifier);
154 std::stringstream ss((*m_weightfileRepresentation)->m_data);
165 B2ERROR(
"MVA Expert is not loaded! I will return 0");
179 std::vector<std::vector<float>> spectators;
180 std::vector<std::vector <float> > data;
182 for (
int iRow = 0; iRow < nRows; iRow += 1) {
183 data[iRow].resize(nFeature);
184 for (
int iFeature = 0; iFeature < nFeature; iFeature += 1) {
185 data[iRow][iFeature] = test_data[nFeature * iRow + iFeature];
218 return m_impl->initialize();
223 return m_impl->beginRun();
233 return m_impl->predict(test_data, nFeature, nRows);
238 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 const 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.