Skip to content

Commit

Permalink
Merge pull request #10205 from ferencek/TMVAEvaluatorSpectatorsSuppor…
Browse files Browse the repository at this point in the history
…t_from-CMSSW_7_5_0

Added full support for spectator variables in the TMVAEvaluator class: 75X
  • Loading branch information
cmsbuild committed Jul 22, 2015
2 parents 225104b + dae306f commit 815aceb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CommonTools/Utils/interface/TMVAEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TMVAEvaluator {

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);
float evaluate(const std::map<std::string,float> & inputs);
float evaluate(const std::map<std::string,float> & inputs, const bool useSpectators=false);

private:
bool mIsInitialized;
Expand Down
24 changes: 21 additions & 3 deletions CommonTools/Utils/src/TMVAEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ void TMVAEvaluator::initialize(const std::string & options, const std::string &
}


float TMVAEvaluator::evaluate(const std::map<std::string,float> & inputs)
float TMVAEvaluator::evaluate(const std::map<std::string,float> & inputs, const bool useSpectators)
{
if(!mIsInitialized)
{
edm::LogError("InitializationError") << "TMVAEvaluator not properly initialized.";
return -99.;
}

if( inputs.size() < mVariables.size() )
if( useSpectators && inputs.size() < ( mVariables.size() + mSpectators.size() ) )
{
edm::LogError("MissingInputs") << "Too few inputs provided (" << inputs.size() << " provided but " << mVariables.size() << " input and " << mSpectators.size() << " spectator variables expected).";
return -99.;
}
else if( inputs.size() < mVariables.size() )
{
edm::LogError("MissingInputVariable(s)") << "Too few input variables provided (" << inputs.size() << " provided but " << mVariables.size() << " expected).";
return -99.;
Expand All @@ -64,7 +69,20 @@ float TMVAEvaluator::evaluate(const std::map<std::string,float> & inputs)
if (inputs.count(it->first)>0)
it->second = inputs.at(it->first);
else
edm::LogError("MissingInputVariable") << "Variable " << it->first << " is missing from the list of input variables. The returned discriminator value might not be sensible.";
edm::LogError("MissingInputVariable") << "Input variable " << it->first << " is missing from the list of inputs. The returned discriminator value might not be sensible.";
}

// if using spectator variables
if(useSpectators)
{
// set the spectator variable values
for(std::map<std::string,float>::iterator it = mSpectators.begin(); it!=mSpectators.end(); ++it)
{
if (inputs.count(it->first)>0)
it->second = inputs.at(it->first);
else
edm::LogError("MissingSpectatorVariable") << "Spectator variable " << it->first << " is missing from the list of inputs. The returned discriminator value might not be sensible.";
}
}

// evaluate the MVA
Expand Down

0 comments on commit 815aceb

Please sign in to comment.