7 #include "TMVA/MethodBDT.h"
16 const std::vector<std::string> &
variables,
const std::vector<std::string> & spectators,
bool useGBRForest,
bool useAdaBoost)
19 mReader.reset(
new TMVA::Reader(options.c_str()));
24 for(std::vector<std::string>::const_iterator it = variables.begin(); it!=variables.end(); ++it)
26 mVariables.insert( std::make_pair( *it, std::make_pair( it - variables.begin(), 0. ) ) );
31 for(std::vector<std::string>::const_iterator it = spectators.begin(); it!=spectators.end(); ++it)
33 mSpectators.insert( std::make_pair( *it, std::make_pair( it - spectators.begin(), 0. ) ) );
38 #if ROOT_VERSION_CODE < ROOT_VERSION(6,7,0)
50 #if ROOT_VERSION_CODE < ROOT_VERSION(6,7,0)
51 mIMethod.reset(
nullptr);
63 const std::vector<std::string> & spectators,
bool useAdaBoost)
66 for(std::vector<std::string>::const_iterator it = variables.begin(); it!=variables.end(); ++it)
67 mVariables.insert( std::make_pair( *it, std::make_pair( it - variables.begin(), 0. ) ) );
70 for(std::vector<std::string>::const_iterator it = spectators.begin(); it!=spectators.end(); ++it)
71 mSpectators.insert( std::make_pair( *it, std::make_pair( it - spectators.begin(), 0. ) ) );
83 const std::vector<std::string> &
variables,
const std::vector<std::string> & spectators,
bool useAdaBoost)
104 if (inputs.count(it->first)>0)
105 it->second.second = inputs.at(it->first);
107 edm::LogError(
"MissingInputVariable") <<
"Input variable " << it->first <<
" is missing from the list of inputs. The returned discriminator value might not be sensible.";
116 if (inputs.count(it->first)>0)
117 it->second.second = inputs.at(it->first);
119 edm::LogError(
"MissingSpectatorVariable") <<
"Spectator variable " << it->first <<
" is missing from the list of inputs. The returned discriminator value might not be sensible.";
135 std::unique_ptr<float[]> vars(
new float[
mVariables.size()]);
140 if (inputs.count(it->first)>0)
141 vars[it->second.first] = inputs.at(it->first);
143 edm::LogError(
"MissingInputVariable") <<
"Input variable " << it->first <<
" is missing from the list of inputs. The returned discriminator value might not be sensible.";
148 value =
mGBRForest->GetAdaBoostClassifier(vars.get());
150 value =
mGBRForest->GetGradBoostClassifier(vars.get());
162 edm::LogError(
"InitializationError") <<
"TMVAEvaluator not properly initialized.";
168 edm::LogError(
"MissingInputs") <<
"Too few inputs provided (" << inputs.size() <<
" provided but " <<
mVariables.size() <<
" input and " <<
mSpectators.size() <<
" spectator variables expected).";
173 edm::LogError(
"MissingInputVariable(s)") <<
"Too few input variables provided (" << inputs.size() <<
" provided but " <<
mVariables.size() <<
" expected).";
180 edm::LogWarning(
"UnsupportedFunctionality") <<
"Use of spectator variables with GBRForest is not supported. Spectator variables will be ignored.";
std::map< std::string, std::pair< size_t, float > > mVariables
void initializeGBRForest(const GBRForest *gbrForest, const std::vector< std::string > &variables, const std::vector< std::string > &spectators, bool useAdaBoost=false)
void initialize(const std::string &options, const std::string &method, const std::string &weightFile, const std::vector< std::string > &variables, const std::vector< std::string > &spectators, bool useGBRForest=false, bool useAdaBoost=false)
std::map< std::string, std::pair< size_t, float > > mSpectators
float evaluateTMVA(const std::map< std::string, float > &inputs, bool useSpectators) const
std::shared_ptr< const GBRForest > mGBRForest
T const * product() const
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
std::unique_ptr< TMVA::Reader > mReader
float evaluate(const std::map< std::string, float > &inputs, bool useSpectators=false) const
volatile std::atomic< bool > shutdown_flag false
float evaluateGBRForest(const std::map< std::string, float > &inputs) const