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(
float* ,
int ,
int );
67#include <mva/interface/Interface.h>
69#include <framework/utilities/FileSystem.h>
70#include <framework/logging/Logger.h>
75using namespace TrackingUtilities;
93 B2FATAL(
"No weight file could be loaded in tracking/trackingUtilities/mva/MVAExpert.");
99 std::unique_ptr<MVA::Weightfile> weightfile =
getWeightFile();
101 if ((weightfile->getElement<std::string>(
"method") ==
"FastBDT" and
102 (weightfile->getElement<
int>(
"FastBDT_version") == 1 or
103 weightfile->getElement<
int>(
"FastBDT_version") == 2)) or
104 (weightfile->getElement<std::string>(
"method") ==
"Python")) {
106 int nExpectedVars = weightfile->getElement<
int>(
"number_feature_variables");
109 for (
int iVar = 0; iVar < nExpectedVars; ++iVar) {
110 std::string variableElementName =
"variable" + std::to_string(iVar);
111 std::string expectedName = weightfile->getElement<std::string>(variableElementName);
115 return namedVariable.getName() == expectedName;
119 B2ERROR(
"Variable name " << iVar <<
" mismatch for FastBDT. " <<
120 "Could not find expected variable '" << expectedName <<
"'");
126 B2WARNING(
"Unpacked new kind of classifier. Consider to extend the feature variable check. Identifier name: " <<
m_identifier
127 <<
"; method name: " << weightfile->getElement<std::string>(
"method"));
131 std::map<std::string, MVA::AbstractInterface*> supportedInterfaces =
137 std::vector<float> dummy;
141 B2ERROR(
"Could not find weight file for identifier " <<
m_identifier);
148 std::stringstream ss((*m_weightfileRepresentation)->m_data);
159 B2ERROR(
"MVA Expert is not loaded! I will return 0");
172 std::vector<std::vector<float>> spectators;
173 std::vector<std::vector <float> > data;
175 for (
int iRow = 0; iRow < nRows; iRow += 1) {
176 data[iRow].resize(nFeature);
177 for (
int iFeature = 0; iFeature < nFeature; iFeature += 1) {
178 data[iRow][iFeature] = test_data[nFeature * iRow + iFeature];
211 return m_impl->initialize();
216 return m_impl->beginRun();
226 return m_impl->predict(test_data, nFeature, nRows);
231 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.