Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added full support for spectator variables in the TMVAEvaluator class: 74X #10206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CommonTools/Utils/interface/TMVAEvaluator.h
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
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