130 fDataSetManager(
NULL ),
137 fMvaEventErrorUpper( 0 ),
155 fDataSetManager(
NULL ),
162 fMvaEventErrorUpper( 0 ),
174 for (std::vector<TString>::iterator ivar = inputVars.begin(); ivar != inputVars.end(); ivar++)
185 fDataSetManager(
NULL ),
192 fMvaEventErrorUpper( 0 ),
204 for (std::vector<std::string>::iterator ivar = inputVars.begin(); ivar != inputVars.end(); ivar++)
215 fDataSetManager(
NULL ),
222 fMvaEventErrorUpper( 0 ),
243 fDataSetManager(
NULL ),
250 fMvaEventErrorUpper( 0 ),
271 if (
gTools().CheckForSilentOption( GetOptions() ))
Log().InhibitOutput();
273 DeclareOptionRef( fVerbose,
"V",
"Verbose flag" );
274 DeclareOptionRef( fColor,
"Color",
"Color flag (default True)" );
275 DeclareOptionRef( fSilent,
"Silent",
"Boolean silent flag (default False)" );
276 DeclareOptionRef( fCalculateError,
"Error",
"Calculates errors (default False)" );
284 delete fDataSetManager;
288 for (
auto it=fMethodMap.begin(); it!=fMethodMap.end(); it++){
299 if (
Verbose()) fLogger->SetMinType( kVERBOSE );
310 DataInfo().AddVariable( expression,
"",
"", 0, 0,
'F',
kFALSE ,(
void*)datalink );
317 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 Log() << kFATAL <<
"Reader::AddVariable( const TString& expression, Int_t* datalink ), this function is deprecated, please provide all variables to the reader as floats" <<
Endl;
320 DataInfo().AddVariable(expression,
"",
"", 0, 0,
'I',
kFALSE, (
void*)datalink );
328 DataInfo().AddSpectator( expression,
"",
"", 0, 0,
'F',
kFALSE ,(
void*)datalink );
336 DataInfo().AddSpectator(expression,
"",
"", 0, 0,
'I',
kFALSE, (
void*)datalink );
344 std::ifstream fin( filename );
346 Log() << kFATAL <<
"<BookMVA> fatal error: "
347 <<
"unable to open input weight file: " << filename <<
Endl;
353 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,29,0)
364 fin.getline(buf,512);
369 TString methodType = fullMethodName(0,fullMethodName.
Index(
"::"));
370 if (methodType.
Contains(
" ")) methodType = methodType(methodType.
Last(
' ')+1,methodType.
Length());
380 if (fMethodMap.find( methodTag ) != fMethodMap.end())
381 Log() << kFATAL <<
"<BookMVA> method tag \"" << methodTag <<
"\" already exists!" <<
Endl;
383 TString methodType(GetMethodTypeFromFile(weightfile));
385 Log() << kINFO <<
"Booking \"" << methodTag <<
"\" of type \"" << methodType <<
"\" from " << weightfile <<
"." <<
Endl;
392 Log() << kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
396 return fMethodMap[methodTag] = method;
405 DataInfo(), weightfile );
409 if (method==0)
return im;
414 Log() << kERROR <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
440 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
448 if(!method)
return 0;
453 Log() << kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
474 Log() << kFATAL <<
"Method Reader::BookMVA(TMVA::Types::EMVA methodType = " << methodType
475 <<
", const char* xmlstr = " << xmlstr
476 <<
" ) is not available for ROOT versions prior to 5.26/00." <<
Endl;
488 IMethod* imeth = FindMVA( methodTag );
490 if(meth==0)
return 0;
493 Event* tmpEvent=
new Event(inputVec, DataInfo().GetNVariables());
494 for (
UInt_t i=0; i<inputVec.size(); i++){
496 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;
519 if(fTmpEvalVec.size() != inputVec.size())
520 fTmpEvalVec.resize(inputVec.size());
522 for (
UInt_t idx=0; idx!=inputVec.size(); idx++ )
523 fTmpEvalVec[idx]=inputVec[idx];
525 return EvaluateMVA( fTmpEvalVec, methodTag, aux );
535 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
536 if (it == fMethodMap.end()) {
537 Log() << kINFO <<
"<EvaluateMVA> unknown classifier in map; "
538 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
539 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
" --> " << it->first <<
Endl;
540 Log() <<
"Check calling string" << kFATAL <<
Endl;
543 else method = it->second;
548 Log() << kFATAL << methodTag <<
" is not a method" <<
Endl;
555 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;
559 return this->EvaluateMVA( kl, aux );
575 return method->
GetMvaValue( (fCalculateError?&fMvaEventError:0),
576 (fCalculateError?&fMvaEventErrorUpper:0) );
586 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
587 if (it == fMethodMap.end()) {
588 Log() << kINFO <<
"<EvaluateMVA> unknown method in map; "
589 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
590 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
" --> " << it->first <<
Endl;
591 Log() <<
"Check calling string" << kFATAL <<
Endl;
593 else method = it->second;
598 Log() << kFATAL << methodTag <<
" is not a method" <<
Endl;
604 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;
608 return this->EvaluateRegression( kl, aux );
621 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;
634 return EvaluateRegression(methodTag, aux).at(tgtNumber);
636 catch (std::out_of_range
e) {
637 Log() << kWARNING <<
"Regression could not be evaluated for target-number " << tgtNumber <<
Endl;
651 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
652 if (it == fMethodMap.end()) {
653 Log() << kINFO <<
"<EvaluateMVA> unknown method in map; "
654 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
655 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
" --> " << it->first <<
Endl;
656 Log() <<
"Check calling string" << kFATAL <<
Endl;
658 else method = it->second;
663 Log() << kFATAL << methodTag <<
" is not a method" <<
Endl;
670 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;
674 return this->EvaluateMulticlass( kl, aux );
687 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;
700 return EvaluateMulticlass(methodTag, aux).at(clsNumber);
702 catch (std::out_of_range
e) {
703 Log() << kWARNING <<
"Multiclass could not be evaluated for class-number " << clsNumber <<
Endl;
714 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
715 if (it != fMethodMap.end())
return it->second;
716 Log() << kERROR <<
"Method " << methodTag <<
" not found!" <<
Endl;
726 return dynamic_cast<MethodCuts*
>(FindMVA(methodTag));
735 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
736 if (it == fMethodMap.end()) {
737 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
"M" << it->first <<
Endl;
738 Log() << kFATAL <<
"<EvaluateMVA> unknown classifier in map: " << method <<
"; "
739 <<
"you looked for " << methodTag<<
" while the available methods are : " <<
Endl;
741 else method = it->second;
750 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;
755 if (mvaVal == -9999999) mvaVal = kl->
GetMvaValue();
757 return kl->
GetProba( mvaVal, ap_sig );
766 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
767 if (it == fMethodMap.end()) {
768 for (it = fMethodMap.begin(); it!=fMethodMap.end(); it++)
Log() <<
"M" << it->first <<
Endl;
769 Log() << kFATAL <<
"<EvaluateMVA> unknown classifier in map: \"" << method <<
"\"; "
770 <<
"you looked for \"" << methodTag<<
"\" while the available methods are : " <<
Endl;
772 else method = it->second;
781 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;
786 if (mvaVal == -9999999) mvaVal = kl->
GetMvaValue();
800 size_t ipos = 0,
f = 0;
801 while (
f != varNames.length()) {
802 f = varNames.find(
':', ipos );
803 if (
f > varNames.length())
f = varNames.length();
804 std::string subs = varNames.substr( ipos,
f-ipos ); ipos =
f+1;
805 DataInfo().AddVariable( subs.c_str() );
818 for (
int i=0; i< n+1 ; i++) {
819 format.
Append(varNames(i));
820 if (varNames(i) ==
':' || i == n) {
824 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)
static Types & Instance()
the the single instance of "Types" if existing already, or create it (Singleton)
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
Virtual base Class for all MVA method.
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
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)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
const TString & GetMethodName() const
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
void DecodeVarNames(const std::string &varNames)
decodes "name1:name2:..." form
TString GetMethodTypeFromFile(const TString &filename)
read the method type from the file
DataInputHandler fDataInputHandler
void DeclareOptions()
declaration of configuration options
void ReadStateFromFile()
Function to write options and weights to file.
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
Class for categorizing the phase space.
Reader(const TString &theOption="", Bool_t verbose=0)
constructor
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...
Multivariate optimisation of signal efficiency for given background efficiency, applying rectangular ...
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
Class that contains all the data information.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
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...
ostringstream derivative to redirect and format output
void Init(void)
default initialisation (no member variables)
void SetUseColor(Bool_t uc)
void SetConfigName(const char *n)
Interface for all concrete MVA method implementations.
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: where PDF(x) is the PDF of the classifier's signal or background distribution ...
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...