Skip to content

Commit

Permalink
Merge pull request #17185 from cms-sw/backport-CMSSW_9_0_X-15737
Browse files Browse the repository at this point in the history
Replace TMVA::Factory->SetInputTrees with TMVA::DataLoader
  • Loading branch information
smuzaffar committed Jan 17, 2017
2 parents 903c3dc + 4a1b99c commit 1112a16
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions PhysicsTools/MVATrainer/plugins/ProcTMVA.cc
Expand Up @@ -18,6 +18,7 @@

#include <TMVA/Types.h>
#include <TMVA/Factory.h>
#include <TMVA/DataLoader.h>

#include "FWCore/Utilities/interface/Exception.h"

Expand Down Expand Up @@ -340,34 +341,38 @@ void ProcTMVA::runTMVATrainer()
<< "Could not open TMVA ROOT file for writing."
<< std::endl;

std::auto_ptr<TMVA::Factory> factory(
std::unique_ptr<TMVA::Factory> factory(
new TMVA::Factory(getTreeName().c_str(), file.get(), ""));

factory->SetInputTrees(treeSig, treeBkg);
std::unique_ptr<TMVA::DataLoader> loader(new TMVA::DataLoader("ProcTMVA"));

loader->SetInputTrees(treeSig, treeBkg);

for(std::vector<std::string>::const_iterator iter = names.begin();
iter != names.end(); iter++)
factory->AddVariable(iter->c_str(), 'D');
loader->AddVariable(iter->c_str(), 'D');

factory->SetWeightExpression("__WEIGHT__");
loader->SetWeightExpression("__WEIGHT__");

if (doUserTreeSetup)
factory->PrepareTrainingAndTestTree(
if (doUserTreeSetup) {
loader->PrepareTrainingAndTestTree(
setupCuts.c_str(), setupOptions);
else
factory->PrepareTrainingAndTestTree(
} else {
loader->PrepareTrainingAndTestTree(
"", 0, 0, 0, 0,
"SplitMode=Block:!V");
}

for(std::vector<Method>::const_iterator iter = methods.begin();
iter != methods.end(); ++iter)
factory->BookMethod(iter->type, iter->name, iter->description);
factory->BookMethod(loader.get(), iter->type, iter->name, iter->description);

factory->TrainAllMethods();
factory->TestAllMethods();
factory->EvaluateAllMethods();

factory.release(); // ROOT seems to take care of destruction?!
loader.release();

file->Close();

Expand Down

0 comments on commit 1112a16

Please sign in to comment.