#include "TTree.h"
#include "TLeaf.h"
#include "TString.h"
#include "TClass.h"
#include "TH1D.h"
#include "TKey.h"
#include "TVector.h"
#include <stdlib.h>
#include "TMVA/Reader.h"
#include "TMVA/Methods.h"
ClassImp(TMVA::Reader)
;
TMVA::Reader::Reader( Bool_t verbose )
: fDataSet( new DataSet ),
fVerbose( verbose ),
fLogger ( this )
{
Init();
}
TMVA::Reader::Reader( vector<TString>& inputVars, Bool_t verbose )
: fDataSet( new DataSet ),
fVerbose( verbose ),
fLogger ( this )
{
for (vector<TString>::iterator ivar = inputVars.begin(); ivar != inputVars.end(); ivar++)
Data().AddVariable( *ivar );
Init();
}
TMVA::Reader::Reader( vector<string>& inputVars, Bool_t verbose )
: fDataSet( new DataSet ),
fVerbose( verbose ),
fLogger ( this )
{
for (vector<string>::iterator ivar = inputVars.begin(); ivar != inputVars.end(); ivar++)
Data().AddVariable( ivar->c_str() );
Init();
}
TMVA::Reader::Reader( const string varNames, Bool_t verbose )
: fDataSet( new DataSet ),
fVerbose( verbose ),
fLogger ( this )
{
this->DecodeVarNames(varNames);
Init();
}
TMVA::Reader::Reader( const TString varNames, Bool_t verbose )
: fDataSet( new DataSet ),
fVerbose( verbose ),
fLogger ( this )
{
this->DecodeVarNames(varNames);
Init();
}
TMVA::Reader::~Reader( void )
{
}
void TMVA::Reader::Init( void )
{
}
void TMVA::Reader::AddVariable( const TString& expression, float* datalink)
{
Data().AddVariable(expression, 'F', (void*)datalink);
}
void TMVA::Reader::AddVariable( const TString& expression, int* datalink)
{
Data().AddVariable(expression, 'I', (void*)datalink);
}
TMVA::IMethod* TMVA::Reader::BookMVA( TString methodName, TString weightfile )
{
ifstream fin( weightfile );
if(!fin.good()) {
fLogger << kFATAL << "<BookMVA> fatal error: "
<< "unable to open input weight file: " << weightfile << Endl;
}
char buf[512];
fin.getline(buf,512);
while (!TString(buf).BeginsWith("Method")) fin.getline(buf,512);
TString ls(buf);
Int_t idx1 = ls.First(':')+2; Int_t idx2 = ls.Index(' ',idx1)-idx1; if (idx2<0) idx2=ls.Length();
fin.close();
TString MethodTypeFromFile = ls(idx1,idx2);
MethodBase* method = (MethodBase*)this->BookMVA( Types::Instance().GetMethodType(MethodTypeFromFile),
weightfile );
method->SetMethodTitle(methodName);
return fMethodMap[methodName] = method;
}
TMVA::IMethod* TMVA::Reader::BookMVA( TMVA::Types::EMVA methodType, TString weightfile )
{
IMethod* method = 0;
switch (methodType) {
case (TMVA::Types::kCuts):
method = new TMVA::MethodCuts( Data(), weightfile );
break;
case (TMVA::Types::kLikelihood):
method = new TMVA::MethodLikelihood( Data(), weightfile );
break;
case (TMVA::Types::kPDERS):
method = new TMVA::MethodPDERS( Data(), weightfile );
break;
case (TMVA::Types::kHMatrix):
method = new TMVA::MethodHMatrix( Data(), weightfile );
break;
case (TMVA::Types::kFisher):
method = new TMVA::MethodFisher( Data(), weightfile );
break;
case (TMVA::Types::kCFMlpANN):
method = new TMVA::MethodCFMlpANN( Data(), weightfile );
break;
case (TMVA::Types::kTMlpANN):
method = new TMVA::MethodTMlpANN( Data(), weightfile );
break;
case (TMVA::Types::kBDT):
method = new TMVA::MethodBDT( Data(), weightfile );
break;
case (TMVA::Types::kMLP):
method = new TMVA::MethodMLP( Data(), weightfile );
break;
case (TMVA::Types::kRuleFit):
method = new TMVA::MethodRuleFit( Data(), weightfile );
break;
case (TMVA::Types::kBayesClassifier):
method = new TMVA::MethodBayesClassifier( Data(), weightfile );
break;
default:
fLogger << kFATAL << "MVA method: " << methodType << " not implemented" << Endl;
return 0;
}
fLogger << kINFO << "booked MVA method: " << method->GetMethodName() << Endl;
method->ReadStateFromFile();
return method;
}
Double_t TMVA::Reader::EvaluateMVA( const std::vector<Float_t>& inputVec, TString methodName, Double_t aux )
{
for (UInt_t ivar=0; ivar<inputVec.size(); ivar++) Data().Event().SetVal( ivar, inputVec[ivar] );
return EvaluateMVA( methodName, aux );
}
Double_t TMVA::Reader::EvaluateMVA( const std::vector<Double_t>& inputVec, TString methodName, Double_t aux )
{
for (UInt_t ivar=0; ivar<inputVec.size(); ivar++) Data().Event().SetVal( ivar, (Float_t)inputVec[ivar] );
return EvaluateMVA( methodName, aux );
}
Double_t TMVA::Reader::EvaluateMVA( TString methodName, Double_t aux )
{
IMethod* method = 0;
std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodName );
if (it == fMethodMap.end()) {
for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++) fLogger << "M" << it->first << Endl;
fLogger << kFATAL << "<EvaluateMVA> unknown method in map: " << method << "; "
<< "you looked for " << methodName<< " while the available methods are : " << Endl;
}
else method = it->second;
return this->EvaluateMVA( method, aux );
}
Double_t TMVA::Reader::EvaluateMVA( IMethod* method, Double_t aux )
{
if (method->GetPreprocessingMethod() != Types::kNone) Data().BackupEvent();
if (method->GetMethodType() != Types::kLikelihood)
Data().ApplyTransformation( method->GetPreprocessingMethod(), kTRUE );
if (method->GetMethodType() == TMVA::Types::kCuts)
((TMVA::MethodCuts*)method)->SetTestSignalEfficiency( aux );
Double_t mvaVal = method->GetMvaValue();
if (method->GetPreprocessingMethod() != Types::kNone) Data().RestoreEvent();
return mvaVal;
}
void TMVA::Reader::DecodeVarNames( const string varNames )
{
size_t ipos = 0, f = 0;
while (f != varNames.length()) {
f = varNames.find( ':', ipos );
if (f > varNames.length()) f = varNames.length();
string subs = varNames.substr( ipos, f-ipos ); ipos = f+1;
Data().AddVariable( subs.c_str() );
}
}
void TMVA::Reader::DecodeVarNames( const TString varNames )
{
TString format;
Int_t n = varNames.Length();
TString format_obj;
for (int i=0; i< n+1 ; i++) {
format.Append(varNames(i));
if ( (varNames(i)==':') || (i==n)) {
format.Chop();
format_obj = TString(format.Data()).ReplaceAll("@","");
Data().AddVariable( format_obj );
format.Resize(0);
}
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.