82 TMVA::MethodCategory::MethodCategory( const
TString& jobName,
87 : TMVA::MethodCompositeBase( jobName, Types::kCategory, methodTitle, theData, theOption, theTargetDir ),
101 fDataSetManager(
NULL)
110 std::vector<TTreeFormula*>::iterator formIt = fCatFormulas.begin();
111 std::vector<TTreeFormula*>::iterator lastF = fCatFormulas.end();
112 for(;formIt!=lastF; ++formIt)
delete *formIt;
122 std::vector<IMethod*>::iterator itrMethod = fMethods.begin();
125 for(; itrMethod != fMethods.end(); ++itrMethod ) {
126 if ( !(*itrMethod)->HasAnalysisType(type, numberClasses, numberTargets) )
150 Log() <<
kINFO <<
"Adding sub-classifier: " << addedMethodName <<
"::" << theTitle <<
Endl;
152 DataSetInfo& dsi = CreateCategoryDSI(theCut, theVariables, theTitle);
157 if(method==0)
return 0;
180 fMethods.push_back(method);
181 fCategoryCuts.push_back(theCut);
182 fVars.push_back(theVariables);
187 fCategorySpecIdx.push_back(newSpectatorIndex);
204 TString dsiName=theTitle+
"_dsi";
210 fDataSetManager->AddDataSetInfo(*dsi);
213 std::vector<VariableInfo>::iterator itrVarInfo;
225 std::vector<UInt_t> varMap;
229 std::vector<TString>::iterator itrVariables;
233 for (itrVariables = variables.begin(); itrVariables != variables.end(); itrVariables++) {
238 if((*itrVariables==itrVarInfo->GetLabel()) ) {
242 varMap.push_back(counter);
250 if((*itrVariables==itrVarInfo->GetLabel()) ) {
254 varMap.push_back(counter);
262 Log() <<
kFATAL <<
"The variable " << itrVariables->Data() <<
" was not found and could not be added " <<
Endl;
268 if (theVariables==
"") {
276 fVarMaps.push_back(varMap);
282 for (
UInt_t i=0; i<nClasses; i++) {
286 dsi->
AddCut(theCut,className);
315 std::vector<VariableInfo>::const_iterator viIt;
320 for (viIt = vars.begin(); viIt != vars.end(); ++viIt)
321 if( viIt->GetExternalLink() == 0 ) {
322 hasAllExternalLinks =
kFALSE;
325 for (viIt = specs.begin(); viIt != specs.end(); ++viIt)
326 if( viIt->GetExternalLink() == 0 ) {
327 hasAllExternalLinks =
kFALSE;
331 if(!hasAllExternalLinks)
return;
340 fCatTree->SetCircular(1);
343 for (viIt = vars.begin(); viIt != vars.end(); ++viIt) {
347 for (viIt = specs.begin(); viIt != specs.end(); ++viIt) {
353 for(
UInt_t cat=0; cat!=fCategoryCuts.size(); ++cat) {
354 fCatFormulas.push_back(
new TTreeFormula(
Form(
"Category_%i",cat), fCategoryCuts[cat].GetTitle(), fCatTree));
369 Log() <<
kINFO <<
"Train all sub-classifiers for "
373 if (fMethods.empty()) {
378 std::vector<IMethod*>::iterator itrMethod;
381 for (itrMethod = fMethods.begin(); itrMethod != fMethods.end(); ++itrMethod ) {
394 itrMethod = fMethods.erase( itrMethod );
407 <<
" not trained (training tree has less entries ["
409 <<
"] than required [" << MinNoTrainingEvents <<
"]" <<
Endl;
411 Log() <<
kERROR <<
" w/o training/test events for that category, I better stop here and let you fix " <<
Endl;
412 Log() <<
kFATAL <<
"that one first, otherwise things get too messy later ... " <<
Endl;
420 Log() <<
kINFO <<
"Begin ranking of input variables..." <<
Endl;
421 for (itrMethod = fMethods.begin(); itrMethod != fMethods.end(); itrMethod++) {
424 const Ranking* ranking = (*itrMethod)->CreateRanking();
428 Log() <<
kINFO <<
"No variable ranking supplied by classifier: "
444 std::vector<IMethod*>::iterator itrMethod;
447 for (
UInt_t i=0; i<fMethods.size(); i++) {
473 Log() <<
kINFO <<
"Recreating sub-classifiers from XML-file " <<
Endl;
476 for (
UInt_t i=0; i<nSubMethods; i++) {
482 methodType = fullMethodName(0,fullMethodName.
Index(
"::"));
483 if (methodType.
Contains(
" ")) methodType = methodType(methodType.
Last(
' ')+1,methodType.
Length());
486 titleLength = fullMethodName.
Length()-fullMethodName.
Index(
"::")-2;
487 methodTitle = fullMethodName(fullMethodName.
Index(
"::")+2,titleLength);
490 DataSetInfo& dsi = CreateCategoryDSI(
TCut(theCutString), theVariables, methodTitle);
496 Log() <<
kFATAL <<
"Could not create sub-method " << method <<
" from XML." <<
Endl;
501 fMethods.push_back(method);
502 fCategoryCuts.push_back(
TCut(theCutString));
503 fVars.push_back(theVariables);
507 UInt_t spectatorIdx = 10000;
512 std::vector<VariableInfo>::iterator itrVarInfo;
513 TString specName=
Form(
"%s_cat%i", GetName(),(
int)fCategorySpecIdx.size()+1);
515 for (itrVarInfo = spectators.begin(); itrVarInfo != spectators.end(); ++itrVarInfo, ++counter) {
516 if((specName==itrVarInfo->GetLabel()) || (specName==itrVarInfo->GetExpression())) {
517 spectatorIdx=counter;
518 fCategorySpecIdx.push_back(spectatorIdx);
526 InitCircularTree(DataInfo());
548 Log() <<
"This method allows to define different categories of events. The" <<
Endl;
549 Log() <<
"categories are defined via cuts on the variables. For each" <<
Endl;
550 Log() <<
"category, a different classifier and set of variables can be" <<
Endl;
551 Log() <<
"specified. The categories which are defined for this method must" <<
Endl;
552 Log() <<
"be disjoint." <<
Endl;
571 if (methodIdx>=fCatFormulas.size()) {
572 Log() <<
kFATAL <<
"Large method index " << methodIdx <<
", number of category formulas = "
573 << fCatFormulas.size() <<
Endl;
582 if (methodIdx>=fCategorySpecIdx.size()) {
583 Log() <<
kFATAL <<
"Unknown method index " << methodIdx <<
" maximum allowed index="
584 << fCategorySpecIdx.size() <<
Endl;
586 UInt_t spectatorIdx = fCategorySpecIdx[methodIdx];
588 Bool_t pass = (specVal>0.5);
598 if (fMethods.empty())
return 0;
601 const Event* ev = GetEvent();
604 Int_t suitableCutsN = 0;
606 for (
UInt_t i=0; i<fMethods.size(); ++i) {
607 if (PassesCut(ev, i)) {
613 if (suitableCutsN == 0) {
614 Log() <<
kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
618 if (suitableCutsN > 1) {
619 Log() <<
kFATAL <<
"The defined categories are not disjoint." <<
Endl;
625 Double_t mvaValue =
dynamic_cast<MethodBase*
>(fMethods[methodToUse])->GetMvaValue(ev,err,errUpper);
641 const Event* ev = GetEvent();
644 Int_t suitableCutsN = 0;
646 for (
UInt_t i=0; i<fMethods.size(); ++i) {
647 if (PassesCut(ev, i)) {
653 if (suitableCutsN == 0) {
654 Log() <<
kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
658 if (suitableCutsN > 1) {
659 Log() <<
kFATAL <<
"The defined categories are not disjoint." <<
Endl;
664 Log() <<
kFATAL <<
"method not found in Category Regression method" <<
Endl;
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
virtual const char * GetTitle() const
Returns title of object.
void Init()
initialize the method
Ssiz_t Last(char c) const
Find last occurrence of a character c.
TMVA::IMethod * AddMethod(const TCut &, const TString &theVariables, Types::EMVA theMethod, const TString &theTitle, const TString &theOptions)
adds sub-classifier for a category
MsgLogger & Endl(MsgLogger &ml)
VariableInfo & AddTarget(const TString &expression, const TString &title, const TString &unit, Double_t min, Double_t max, 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 ...
void AddWeightsXMLTo(void *parent) const
create XML description of Category classifier
const TString GetWeightExpression(Int_t i) const
void ReadStateFromXML(void *parent)
std::vector< VariableInfo > & GetSpectatorInfos()
void variables(TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
void SetVariableArrangement(std::vector< UInt_t > *const m) const
set the variable arrangement
void SetCut(const TCut &cut, const TString &className)
set the cut for the classes
void InitCircularTree(const DataSetInfo &dsi)
initialize the circular tree
const TString & GetExpression() const
const char * GetName() const
Returns name of object.
UInt_t GetNClasses() const
void SetMethodBaseDir(TDirectory *methodDir)
UInt_t GetNTargets() const
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
virtual const std::vector< Float_t > & GetRegressionValues()
virtual ~MethodCategory(void)
destructor
ClassImp(TMVA::MethodCategory) TMVA
standard constructor
Float_t GetSpectator(UInt_t ivar) const
return spectator content
void AddCut(const TCut &cut, const TString &className)
set the cut for the classes
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)=0
void GetHelpMessage() const
Get help message text.
const TString & GetMethodName() const
const char * Data() const
static Types & Instance()
the the single instance of "Types" if existin already, or create it (Signleton)
void DeclareOptions()
options for this method
TDirectory * GetRootDir() const
const TString & GetNormalization() const
std::vector< std::vector< double > > Data
virtual void ParseOptions()
options parser
void SetupMethod()
setup of methods
std::vector< VariableInfo > & GetTargetInfos()
MethodCategory(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="", TDirectory *theTargetDir=NULL)
A specialized string object used for TTree selections.
const Int_t MinNoTrainingEvents
void SetSplitOptions(const TString &so)
const Ranking * CreateRanking()
no ranking
std::string GetMethodName(TCppMethod_t)
TMVA::DataSetInfo & CreateCategoryDSI(const TCut &, const TString &, const TString &)
create a DataSetInfo object for a sub-classifier
ClassInfo * GetClassInfo(Int_t clNum) const
void SetWeightExpression(const TString &exp, const TString &className="")
set the weight expressions for the classes if class name is specified, set only for this class if cla...
char * Form(const char *fmt,...)
void Train(void)
train all sub-classifiers
const TString & GetName() const
const TCut & GetCut(Int_t i) const
const TString & GetSplitOptions() const
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
Describe directory structure in memory.
DataSetInfo & DataInfo() const
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t)
check whether method category has analysis type the method type has to be the same for all sub-method...
ClassInfo * AddClass(const TString &className)
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns the mva value of the right sub-classifier
void * GetExternalLink() const
#define REGISTER_METHOD(CLASS)
for example
VariableInfo & AddSpectator(const TString &expression, const TString &title, const TString &unit, Double_t min, Double_t max, char type= 'F', Bool_t normalized=kTRUE, void *external=0)
add a spectator (can be a complex expression) to the set of spectator variables used in the MV analys...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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 ...
void DisableWriting(Bool_t setter)
Long64_t GetNTrainingEvents() const
A TTree object has a header with a name and a title.
void ReadWeightsFromXML(void *wghtnode)
read weights of sub-classifiers of MethodCategory from xml weight file
Bool_t PassesCut(const Event *ev, UInt_t methodIdx)
virtual void Print() const
get maximum length of variable names
TString GetMethodTypeName() const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
double norm(double *x, double *p)
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables, variable transformation type etc.
void SetNormalization(const TString &norm)
void SetRootDir(TDirectory *d)
virtual const std::vector< Float_t > & GetRegressionValues()
returns the mva value of the right sub-classifier
std::vector< VariableInfo > & GetVariableInfos()
virtual void SetAnalysisType(Types::EAnalysisType type)
void ProcessOptions()
process user options