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;
360 fin.getline(buf,512);
365 TString methodType = fullMethodName(0,fullMethodName.
Index(
"::"));
366 if (methodType.
Contains(
" ")) methodType = methodType(methodType.
Last(
' ')+1,methodType.
Length());
376 if (fMethodMap.find( methodTag ) != fMethodMap.end())
377 Log() << kFATAL <<
"<BookMVA> method tag \"" << methodTag <<
"\" already exists!" <<
Endl;
379 TString methodType(GetMethodTypeFromFile(weightfile));
381 Log() << kINFO <<
"Booking \"" << methodTag <<
"\" of type \"" << methodType <<
"\" from " << weightfile <<
"." <<
Endl;
388 Log() << kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
392 return fMethodMap[methodTag] = method;
405 if (method==0)
return im;
410 Log() << kERROR <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
442 if(!method)
return 0;
447 Log() << kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Reader" <<
Endl;
476 IMethod* imeth = FindMVA( methodTag );
478 if(meth==0)
return 0;
481 Event* tmpEvent=
new Event(inputVec, DataInfo().GetNVariables());
482 for (
UInt_t i=0; i<inputVec.size(); i++){
484 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;
507 if(fTmpEvalVec.size() != inputVec.size())
508 fTmpEvalVec.resize(inputVec.size());
510 for (
UInt_t idx=0; idx!=inputVec.size(); idx++ )
511 fTmpEvalVec[idx]=inputVec[idx];
513 return EvaluateMVA( fTmpEvalVec, methodTag, aux );
523 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
524 if (it == fMethodMap.end()) {
525 Log() << kINFO <<
"<EvaluateMVA> unknown classifier in map; "
526 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
527 for (it = fMethodMap.begin(); it!=fMethodMap.end(); ++it)
Log() <<
"--> " << it->first <<
Endl;
528 Log() <<
"Check calling string" << kFATAL <<
Endl;
531 else method = it->second;
536 Log() << kFATAL << methodTag <<
" is not a method" <<
Endl;
543 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;
547 return this->EvaluateMVA( kl, aux );
563 return method->
GetMvaValue( (fCalculateError?&fMvaEventError:0),
564 (fCalculateError?&fMvaEventErrorUpper:0) );
574 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
575 if (it == fMethodMap.end()) {
576 Log() << kINFO <<
"<EvaluateMVA> unknown method in map; "
577 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
578 for (it = fMethodMap.begin(); it!=fMethodMap.end(); ++it)
Log() <<
"--> " << it->first <<
Endl;
579 Log() <<
"Check calling string" << kFATAL <<
Endl;
581 else method = it->second;
586 Log() << kFATAL << methodTag <<
" is not a method" <<
Endl;
592 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;
596 return this->EvaluateRegression( kl, aux );
609 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;
622 return EvaluateRegression(methodTag, aux).at(tgtNumber);
624 catch (std::out_of_range &) {
625 Log() << kWARNING <<
"Regression could not be evaluated for target-number " << tgtNumber <<
Endl;
639 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
640 if (it == fMethodMap.end()) {
641 Log() << kINFO <<
"<EvaluateMVA> unknown method in map; "
642 <<
"you looked for \"" << methodTag <<
"\" within available methods: " <<
Endl;
643 for (it = fMethodMap.begin(); it!=fMethodMap.end(); ++it)
Log() <<
"--> " << it->first <<
Endl;
644 Log() <<
"Check calling string" << kFATAL <<
Endl;
646 else method = it->second;
651 Log() << kFATAL << methodTag <<
" is not a method" <<
Endl;
658 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;
662 return this->EvaluateMulticlass( kl, aux );
675 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;
688 return EvaluateMulticlass(methodTag, aux).at(clsNumber);
690 catch (std::out_of_range &) {
691 Log() << kWARNING <<
"Multiclass could not be evaluated for class-number " << clsNumber <<
Endl;
702 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
703 if (it != fMethodMap.end())
return it->second;
704 Log() << kERROR <<
"Method " << methodTag <<
" not found!" <<
Endl;
714 return dynamic_cast<MethodCuts*
>(FindMVA(methodTag));
723 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
724 if (it == fMethodMap.end()) {
725 for (it = fMethodMap.begin(); it!=fMethodMap.end(); ++it)
Log() <<
"M" << it->first <<
Endl;
726 Log() << kFATAL <<
"<EvaluateMVA> unknown classifier in map: " << method <<
"; "
727 <<
"you looked for " << methodTag<<
" while the available methods are : " <<
Endl;
729 else method = it->second;
738 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;
743 if (mvaVal == -9999999) mvaVal = kl->
GetMvaValue();
745 return kl->
GetProba( mvaVal, ap_sig );
754 std::map<TString, IMethod*>::iterator it = fMethodMap.find( methodTag );
755 if (it == fMethodMap.end()) {
756 for (it = fMethodMap.begin(); it!=fMethodMap.end(); ++it)
Log() <<
"M" << it->first <<
Endl;
757 Log() << kFATAL <<
"<EvaluateMVA> unknown classifier in map: \"" << method <<
"\"; "
758 <<
"you looked for \"" << methodTag<<
"\" while the available methods are : " <<
Endl;
760 else method = it->second;
769 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;
774 if (mvaVal == -9999999) mvaVal = kl->
GetMvaValue();
788 size_t ipos = 0,
f = 0;
789 while (
f != varNames.length()) {
790 f = varNames.find(
':', ipos );
791 if (
f > varNames.length())
f = varNames.length();
792 std::string subs = varNames.substr( ipos,
f-ipos ); ipos =
f+1;
793 DataInfo().AddVariable( subs.c_str() );
806 for (
int i=0; i<
n+1 ; i++) {
807 format.
Append(varNames(i));
808 if (varNames(i) ==
':' || i ==
n) {
812 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
void SetUseColor(Bool_t uc)
void SetConfigName(const char *n)
virtual void ParseOptions()
options parser
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
Class that contains all the data information.
DataSetInfo & AddDataSetInfo(DataSetInfo &dsi)
stores a copy of the dataset info object
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
UInt_t GetNVariables() const
accessor to the number of variables
Interface for all concrete MVA method implementations.
Virtual base Class for all MVA method.
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
TString GetMethodTypeName() const
virtual Double_t GetProba(const Event *ev)
virtual const std::vector< Float_t > & GetMulticlassValues()
void SetupMethod()
setup of methods
const TString & GetMethodName() const
const Event * GetEvent() const
void ReadStateFromXMLString(const char *xmlstr)
for reading from memory
void ReadStateFromFile()
Function to write options and weights to file.
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
virtual Double_t GetRarity(Double_t mvaVal, Types::ESBType reftype=Types::kBackground) const
compute rarity:
Types::EMVA GetMethodType() const
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
Class for categorizing the phase space.
DataSetManager * fDataSetManager
Multivariate optimisation of signal efficiency for given background efficiency, applying rectangular ...
void SetTestSignalEfficiency(Double_t effS)
ostringstream derivative to redirect and format output
const std::vector< Float_t > & EvaluateRegression(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
virtual const char * GetName() const
Returns name of object.
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...
Double_t GetRarity(const TString &methodTag, Double_t mvaVal=-9999999)
evaluates the MVA's rarity
IMethod * FindMVA(const TString &methodTag)
return pointer to method with tag "methodTag"
void Init(void)
default initialisation (no member variables)
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
MethodCuts * FindCutsMVA(const TString &methodTag)
special function for Cuts to avoid dynamic_casts in ROOT macros, which are not properly handled by CI...
TString GetMethodTypeFromFile(const TString &filename)
read the method type from the file
DataSetManager * fDataSetManager
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
Reader(const TString &theOption="", Bool_t verbose=0)
constructor
const std::vector< Float_t > & EvaluateMulticlass(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
DataInputHandler fDataInputHandler
void DecodeVarNames(const std::string &varNames)
decodes "name1:name2:..." form
void DeclareOptions()
declaration of configuration options
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
virtual ~Reader(void)
destructor
const DataSetInfo & DataInfo() const
static Types & Instance()
the the single instance of "Types" if existing already, or create it (Singleton)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TString & ReplaceAll(const TString &s1, const TString &s2)
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Ssiz_t Last(char c) const
Find last occurrence of a character c.
TString & Append(const char *cs)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
RooCmdArg Verbose(Bool_t flag=kTRUE)
void GetMethodName(TString &name, TKey *mkey)
MsgLogger & Endl(MsgLogger &ml)