94 #ifndef ROOT_TMVA_Tools
132 : Configurable( theOption ),
133 fDataSetManager(
NULL ),
138 fCalculateError(kFALSE),
140 fMvaEventErrorUpper( 0 ),
143 fDataSetManager =
new DataSetManager( fDataInputHandler );
144 fDataSetManager->AddDataSetInfo(fDataSetInfo);
145 fLogger =
new MsgLogger(
this);
146 SetConfigName( GetName() );
158 fDataSetManager(
NULL ),
165 fMvaEventErrorUpper( 0 ),
177 for (std::vector<TString>::iterator ivar = inputVars.begin(); ivar != inputVars.end(); ivar++)
188 fDataSetManager(
NULL ),
195 fMvaEventErrorUpper( 0 ),
207 for (std::vector<std::string>::iterator ivar = inputVars.begin(); ivar != inputVars.end(); ivar++)
218 fDataSetManager(
NULL ),
225 fMvaEventErrorUpper( 0 ),
246 fDataSetManager(
NULL ),
253 fMvaEventErrorUpper( 0 ),
274 if (
gTools().CheckForSilentOption( GetOptions() ))
Log().InhibitOutput();
276 DeclareOptionRef( fVerbose,
"V",
"Verbose flag" );
277 DeclareOptionRef( fColor,
"Color",
"Color flag (default True)" );
278 DeclareOptionRef( fSilent,
"Silent",
"Boolean silent flag (default False)" );
279 DeclareOptionRef( fCalculateError,
"Error",
"Calculates errors (default False)" );
287 delete fDataSetManager;
309 DataInfo().AddVariable( expression,
"",
"", 0, 0,
'F',
kFALSE ,(
void*)datalink );
316 Log() <<
kFATAL <<
"Reader::AddVariable( const TString& expression, Int_t* datalink ), this function is deprecated, please provide all variables to the reader as floats" <<
Endl;
318 Log() <<
kFATAL <<
"Reader::AddVariable( const TString& expression, Int_t* datalink ), this function is deprecated, please provide all variables to the reader as floats" <<
Endl;
319 DataInfo().AddVariable(expression,
"",
"", 0, 0,
'I',
kFALSE, (
void*)datalink );
327 DataInfo().AddSpectator( expression,
"",
"", 0, 0,
'F',
kFALSE ,(
void*)datalink );
335 DataInfo().AddSpectator(expression,
"",
"", 0, 0,
'I',
kFALSE, (
void*)datalink );
343 std::ifstream fin( filename );
345 Log() <<
kFATAL <<
"<BookMVA> fatal error: "
346 <<
"unable to open input weight file: " << filename <<
Endl;
352 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,29,0)
363 fin.getline(buf,512);
368 TString methodType = fullMethodName(0,fullMethodName.
Index(
"::"));
369 if (methodType.
Contains(
" ")) methodType = methodType(methodType.
Last(
' ')+1,methodType.
Length());
379 if (fMethodMap.find( methodTag ) != fMethodMap.end())
380 Log() <<
kFATAL <<
"<BookMVA> method tag \"" << methodTag <<
"\" already exists!" <<
Endl;
382 TString methodType(GetMethodTypeFromFile(weightfile));
384 Log() <<
kINFO <<
"Booking \"" << methodTag <<
"\" of type \"" << methodType <<
"\" from " << weightfile <<
"." <<
Endl;
391 Log() <<
kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
395 return fMethodMap[methodTag] = method;
404 DataInfo(), weightfile );
408 if (method==0)
return im;
413 Log() <<
kERROR <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
439 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
447 if(!method)
return 0;
452 Log() <<
kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
473 Log() <<
kFATAL <<
"Method Reader::BookMVA(TMVA::Types::EMVA methodType = " << methodType
474 <<
", const char* xmlstr = " << xmlstr
475 <<
" ) is not available for ROOT versions prior to 5.26/00." <<
Endl;
487 IMethod* imeth = FindMVA( methodTag );
489 if(meth==0)
return 0;
492 Event* tmpEvent=
new Event(inputVec, DataInfo().GetNVariables());
493 for (
UInt_t i=0; i<inputVec.size(); i++){
495 Log() <<
kERROR << i <<
"-th variable of the event is NaN --> return MVA value -999, \n that's all I can do, please fix or remove this event." <<
Endl;
518 if(fTmpEvalVec.size() != inputVec.size())
519 fTmpEvalVec.resize(inputVec.size());
521 for (
UInt_t idx=0; idx!=inputVec.size(); idx++ )
522 fTmpEvalVec[idx]=inputVec[idx];
524 return EvaluateMVA( fTmpEvalVec, methodTag, aux );
534 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
535 if (it == fMethodMap.end()) {
536 Log() <<
kINFO <<
"<EvaluateMVA> unknown classifier in map; "
537 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
538 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
" --> " << it->first <<
Endl;
542 else method = it->second;
554 Log() <<
kERROR << i <<
"-th variable of the event is NaN --> return MVA value -999, \n that's all I can do, please fix or remove this event." <<
Endl;
558 return this->EvaluateMVA( kl, aux );
574 return method->
GetMvaValue( (fCalculateError?&fMvaEventError:0),
575 (fCalculateError?&fMvaEventErrorUpper:0) );
585 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
586 if (it == fMethodMap.end()) {
587 Log() <<
kINFO <<
"<EvaluateMVA> unknown method in map; "
588 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
589 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
" --> " << it->first <<
Endl;
592 else method = it->second;
603 Log() <<
kERROR << i <<
"-th variable of the event is NaN, \n regression values might evaluate to .. what do I know. \n sorry this warning is all I can do, please fix or remove this event." <<
Endl;
607 return this->EvaluateRegression( kl, aux );
620 Log() <<
kERROR << i <<
"-th variable of the event is NaN, \n regression values might evaluate to .. what do I know. \n sorry this warning is all I can do, please fix or remove this event." <<
Endl;
633 return EvaluateRegression(methodTag, aux).at(tgtNumber);
635 catch (std::out_of_range e) {
636 Log() <<
kWARNING <<
"Regression could not be evaluated for target-number " << tgtNumber <<
Endl;
650 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
651 if (it == fMethodMap.end()) {
652 Log() <<
kINFO <<
"<EvaluateMVA> unknown method in map; "
653 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
654 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
" --> " << it->first <<
Endl;
657 else method = it->second;
669 Log() <<
kERROR << i <<
"-th variable of the event is NaN, \n regression values might evaluate to .. what do I know. \n sorry this warning is all I can do, please fix or remove this event." <<
Endl;
673 return this->EvaluateMulticlass( kl, aux );
686 Log() <<
kERROR << i <<
"-th variable of the event is NaN, \n regression values might evaluate to .. what do I know. \n sorry this warning is all I can do, please fix or remove this event." <<
Endl;
699 return EvaluateMulticlass(methodTag, aux).at(clsNumber);
701 catch (std::out_of_range e) {
702 Log() <<
kWARNING <<
"Multiclass could not be evaluated for class-number " << clsNumber <<
Endl;
713 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
714 if (it != fMethodMap.end())
return it->second;
715 Log() <<
kERROR <<
"Method " << methodTag <<
" not found!" <<
Endl;
725 return dynamic_cast<MethodCuts*
>(FindMVA(methodTag));
734 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
735 if (it == fMethodMap.end()) {
736 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
"M" << it->first <<
Endl;
737 Log() <<
kFATAL <<
"<EvaluateMVA> unknown classifier in map: " << method <<
"; "
738 <<
"you looked for " << methodTag<<
" while the available methods are : " <<
Endl;
740 else method = it->second;
749 Log() <<
kERROR << i <<
"-th variable of the event is NaN --> return MVA value -999, \n that's all I can do, please fix or remove this event." <<
Endl;
754 if (mvaVal == -9999999) mvaVal = kl->
GetMvaValue();
756 return kl->
GetProba( mvaVal, ap_sig );
765 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
766 if (it == fMethodMap.end()) {
767 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
"M" << it->first <<
Endl;
768 Log() <<
kFATAL <<
"<EvaluateMVA> unknown classifier in map: \"" << method <<
"\"; "
769 <<
"you looked for \"" << methodTag<<
"\" while the available methods are : " <<
Endl;
771 else method = it->second;
780 Log() <<
kERROR << i <<
"-th variable of the event is NaN --> return MVA value -999, \n that's all I can do, please fix or remove this event." <<
Endl;
785 if (mvaVal == -9999999) mvaVal = kl->
GetMvaValue();
799 size_t ipos = 0,
f = 0;
800 while (
f != varNames.length()) {
801 f = varNames.find(
':', ipos );
802 if (
f > varNames.length())
f = varNames.length();
803 std::string subs = varNames.substr( ipos,
f-ipos ); ipos =
f+1;
804 DataInfo().AddVariable( subs.c_str() );
817 for (
int i=0; i< n+1 ; i++) {
818 format.
Append(varNames(i));
819 if (varNames(i) ==
':' || i == n) {
823 DataInfo().AddVariable( format_obj );
IMethod * Create(const std::string &name, const TString &job, const TString &title, DataSetInfo &dsi, const TString &option)
creates the method if needed based on the method name using the creator function the factory has stor...
static ClassifierFactory & Instance()
access to the ClassifierFactory singleton creates the instance if needed
Ssiz_t Last(char c) const
Find last occurrence of a character c.
virtual const std::vector< Float_t > & GetMulticlassValues()
const DataSetInfo & DataInfo() const
MsgLogger & Endl(MsgLogger &ml)
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
virtual ~Reader(void)
destructor
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
TString & ReplaceAll(const TString &s1, const TString &s2)
void SetTestSignalEfficiency(Double_t effS)
const std::vector< Float_t > & EvaluateRegression(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
static const char * filename()
Double_t GetRarity(const TString &methodTag, Double_t mvaVal=-9999999)
evaluates the MVA's rarity
static std::string format(double x, double y, int digits, int width)
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
const TString & GetMethodName() const
void DecodeVarNames(const std::string &varNames)
decodes "name1:name2:..." form
static Types & Instance()
the the single instance of "Types" if existin already, or create it (Signleton)
TString GetMethodTypeFromFile(const TString &filename)
read the method type from the file
DataInputHandler fDataInputHandler
void Init(TClassEdit::TInterpreterLookupHelper *helper)
void DeclareOptions()
declaration of configuration options
void ReadStateFromFile()
Function to write options and weights to file.
ClassImp(TMVA::Reader) TMVA
constructor
TString & Append(const char *cs)
virtual void ParseOptions()
options parser
virtual const char * GetName() const
Returns name of object.
void SetupMethod()
setup of methods
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
Types::EMVA GetMethodType() const
virtual Double_t GetProba(const Event *ev)
DataSetManager * fDataSetManager
UInt_t GetNVariables() const
accessor to the number of variables
void ReadStateFromXMLString(const char *xmlstr)
for reading from memory
std::string GetMethodName(TCppMethod_t)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
DataSetInfo & AddDataSetInfo(DataSetInfo &dsi)
stores a copy of the dataset info object
const Event * GetEvent() const
DataSetManager * fDataSetManager
Reader(const TString &theOption="", Bool_t verbose=0)
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
RooCmdArg Verbose(Bool_t flag=kTRUE)
Double_t EvaluateMVA(const std::vector< Float_t > &, const TString &methodTag, Double_t aux=0)
Evaluate a std::vector<float> of input data for a given method The parameter aux is obligatory for th...
void Init(void)
default initialisation (no member variables) default initialisation (no member variables) ...
void SetUseColor(Bool_t uc)
void SetConfigName(const char *n)
IMethod * FindMVA(const TString &methodTag)
return pointer to method with tag "methodTag"
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
VariableInfo & AddVariable(const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0, char varType='F', Bool_t normalized=kTRUE, void *external=0)
add a variable (can be a complex expression) to the set of variables used in the MV analysis ...
TString()
TString default ctor.
virtual Double_t GetRarity(Double_t mvaVal, Types::ESBType reftype=Types::kBackground) const
compute rarity: R(x) = Integrate_[-oo..x] { PDF(x') dx' } where PDF(x) is the PDF of the classifier's...
TString GetMethodTypeName() const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Double_t GetProba(const TString &methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999)
evaluates probability of MVA for given set of input variables
const std::vector< Float_t > & EvaluateMulticlass(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
MethodCuts * FindCutsMVA(const TString &methodTag)
special function for Cuts to avoid dynamic_casts in ROOT macros, which are not properly handled by CI...