103 fDataSetManager(NULL)
112 std::vector<TTreeFormula*>::iterator formIt = fCatFormulas.begin();
113 std::vector<TTreeFormula*>::iterator lastF = fCatFormulas.end();
114 for(;formIt!=lastF; ++formIt)
delete *formIt;
124 std::vector<IMethod*>::iterator itrMethod = fMethods.begin();
127 for(; itrMethod != fMethods.end(); ++itrMethod ) {
128 if ( !(*itrMethod)->HasAnalysisType(
type, numberClasses, numberTargets) )
152 Log() << kINFO <<
"Adding sub-classifier: " << addedMethodName <<
"::" << theTitle <<
Endl;
154 DataSetInfo& dsi = CreateCategoryDSI(theCut, theVariables, theTitle);
159 if(method==0)
return 0;
187 fMethods.push_back(method);
188 fCategoryCuts.push_back(theCut);
189 fVars.push_back(theVariables);
194 fCategorySpecIdx.push_back(newSpectatorIndex);
211 TString dsiName=theTitle+
"_dsi";
217 fDataSetManager->AddDataSetInfo(*dsi);
220 std::vector<VariableInfo>::iterator itrVarInfo;
232 std::vector<UInt_t> varMap;
236 std::vector<TString>::iterator itrVariables;
240 for (itrVariables =
variables.begin(); itrVariables !=
variables.end(); ++itrVariables) {
245 if((*itrVariables==itrVarInfo->GetLabel()) ) {
249 varMap.push_back(counter);
257 if((*itrVariables==itrVarInfo->GetLabel()) ) {
261 varMap.push_back(counter);
269 Log() << kFATAL <<
"The variable " << itrVariables->Data() <<
" was not found and could not be added " <<
Endl;
275 if (theVariables==
"") {
283 fVarMaps.push_back(varMap);
289 for (
UInt_t i=0; i<nClasses; i++) {
293 dsi->
AddCut(theCut,className);
322 std::vector<VariableInfo>::const_iterator viIt;
327 for (viIt = vars.begin(); viIt != vars.end(); ++viIt)
328 if( viIt->GetExternalLink() == 0 ) {
329 hasAllExternalLinks =
kFALSE;
332 for (viIt = specs.begin(); viIt != specs.end(); ++viIt)
333 if( viIt->GetExternalLink() == 0 ) {
334 hasAllExternalLinks =
kFALSE;
338 if(!hasAllExternalLinks)
return;
347 fCatTree->SetCircular(1);
350 for (viIt = vars.begin(); viIt != vars.end(); ++viIt) {
354 for (viIt = specs.begin(); viIt != specs.end(); ++viIt) {
360 for(
UInt_t cat=0; cat!=fCategoryCuts.size(); ++cat) {
361 fCatFormulas.push_back(
new TTreeFormula(
Form(
"Category_%i",cat), fCategoryCuts[cat].GetTitle(), fCatTree));
376 Log() << kINFO <<
"Train all sub-classifiers for "
380 if (fMethods.empty()) {
381 Log() << kINFO <<
"...nothing found to train" <<
Endl;
385 std::vector<IMethod*>::iterator itrMethod;
388 for (itrMethod = fMethods.begin(); itrMethod != fMethods.end(); ++itrMethod ) {
401 itrMethod = fMethods.erase( itrMethod );
409 Log() << kINFO <<
"Training finished" <<
Endl;
414 <<
" not trained (training tree has less entries ["
418 Log() << kERROR <<
" w/o training/test events for that category, I better stop here and let you fix " <<
Endl;
419 Log() << kFATAL <<
"that one first, otherwise things get too messy later ... " <<
Endl;
427 Log() << kINFO <<
"Begin ranking of input variables..." <<
Endl;
428 for (itrMethod = fMethods.begin(); itrMethod != fMethods.end(); ++itrMethod) {
431 const Ranking* ranking = (*itrMethod)->CreateRanking();
435 Log() << kINFO <<
"No variable ranking supplied by classifier: "
452 for (
UInt_t i=0; i<fMethods.size(); i++) {
478 Log() << kINFO <<
"Recreating sub-classifiers from XML-file " <<
Endl;
481 for (
UInt_t i=0; i<nSubMethods; i++) {
487 methodType = fullMethodName(0,fullMethodName.
Index(
"::"));
488 if (methodType.
Contains(
" ")) methodType = methodType(methodType.
Last(
' ')+1,methodType.
Length());
491 titleLength = fullMethodName.
Length()-fullMethodName.
Index(
"::")-2;
492 methodTitle = fullMethodName(fullMethodName.
Index(
"::")+2,titleLength);
495 DataSetInfo& dsi = CreateCategoryDSI(
TCut(theCutString), theVariables, methodTitle);
501 Log() << kFATAL <<
"Could not create sub-method " << method <<
" from XML." <<
Endl;
506 fMethods.push_back(method);
507 fCategoryCuts.push_back(
TCut(theCutString));
508 fVars.push_back(theVariables);
512 UInt_t spectatorIdx = 10000;
517 std::vector<VariableInfo>::iterator itrVarInfo;
520 for (itrVarInfo = spectators.begin(); itrVarInfo != spectators.end(); ++itrVarInfo, ++counter) {
521 if((specName==itrVarInfo->GetLabel()) || (specName==itrVarInfo->GetExpression())) {
522 spectatorIdx=counter;
523 fCategorySpecIdx.push_back(spectatorIdx);
531 InitCircularTree(DataInfo());
553 Log() <<
"This method allows to define different categories of events. The" <<
Endl;
554 Log() <<
"categories are defined via cuts on the variables. For each" <<
Endl;
555 Log() <<
"category, a different classifier and set of variables can be" <<
Endl;
556 Log() <<
"specified. The categories which are defined for this method must" <<
Endl;
557 Log() <<
"be disjoint." <<
Endl;
576 if (methodIdx>=fCatFormulas.size()) {
577 Log() << kFATAL <<
"Large method index " << methodIdx <<
", number of category formulas = "
578 << fCatFormulas.size() <<
Endl;
581 return f->EvalInstance(0) > 0.5;
587 if (methodIdx>=fCategorySpecIdx.size()) {
588 Log() << kFATAL <<
"Unknown method index " << methodIdx <<
" maximum allowed index="
589 << fCategorySpecIdx.size() <<
Endl;
591 UInt_t spectatorIdx = fCategorySpecIdx[methodIdx];
593 Bool_t pass = (specVal>0.5);
603 if (fMethods.empty())
return 0;
606 const Event* ev = GetEvent();
609 Int_t suitableCutsN = 0;
611 for (
UInt_t i=0; i<fMethods.size(); ++i) {
612 if (PassesCut(ev, i)) {
618 if (suitableCutsN == 0) {
619 Log() << kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
623 if (suitableCutsN > 1) {
624 Log() << kFATAL <<
"The defined categories are not disjoint." <<
Endl;
630 Double_t mvaValue =
dynamic_cast<MethodBase*
>(fMethods[methodToUse])->GetMvaValue(ev,err,errUpper);
646 const Event* ev = GetEvent();
649 Int_t suitableCutsN = 0;
651 for (
UInt_t i=0; i<fMethods.size(); ++i) {
652 if (PassesCut(ev, i)) {
658 if (suitableCutsN == 0) {
659 Log() << kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
663 if (suitableCutsN > 1) {
664 Log() << kFATAL <<
"The defined categories are not disjoint." <<
Endl;
669 Log() << kFATAL <<
"method not found in Category Regression method" <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
char * Form(const char *fmt,...)
A specialized string object used for TTree selections.
Small helper to keep current directory context.
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
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 void ParseOptions()
options parser
Class that contains all the data information.
const TString GetWeightExpression(Int_t i) const
std::vector< VariableInfo > & GetVariableInfos()
void SetSplitOptions(const TString &so)
ClassInfo * AddClass(const TString &className)
const TString & GetNormalization() const
std::vector< VariableInfo > & GetSpectatorInfos()
TDirectory * GetRootDir() const
void SetNormalization(const TString &norm)
UInt_t GetNClasses() const
const TString & GetSplitOptions() const
UInt_t GetNTargets() const
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
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...
ClassInfo * GetClassInfo(Int_t clNum) const
const TCut & GetCut(Int_t i) const
void SetCut(const TCut &cut, const TString &className)
set the cut for the classes
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
std::vector< VariableInfo > & GetTargetInfos()
void SetRootDir(TDirectory *d)
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...
void AddCut(const TCut &cut, const TString &className)
set the cut for the classes
Long64_t GetNTrainingEvents() const
void SetVariableArrangement(std::vector< UInt_t > *const m) const
set the variable arrangement
Float_t GetSpectator(UInt_t ivar) const
return spectator content
Interface for all concrete MVA method implementations.
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)=0
Virtual base Class for all MVA method.
virtual const std::vector< Float_t > & GetRegressionValues()
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
void SetSilentFile(Bool_t status)
void SetWeightFileDir(TString fileDir)
set directory of weight file
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables,...
TString GetMethodTypeName() const
void DisableWriting(Bool_t setter)
const char * GetName() const
void SetupMethod()
setup of methods
virtual void SetAnalysisType(Types::EAnalysisType type)
const TString & GetMethodName() const
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
DataSetInfo & DataInfo() const
void SetFile(TFile *file)
void ReadStateFromXML(void *parent)
friend class MethodCategory
void SetMethodBaseDir(TDirectory *methodDir)
void SetModelPersistence(Bool_t status)
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.
void InitCircularTree(const DataSetInfo &dsi)
initialize the circular tree
void GetHelpMessage() const
Get help message text.
void Init()
initialize the method
Bool_t PassesCut(const Event *ev, UInt_t methodIdx)
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...
void ProcessOptions()
process user options
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns the mva value of the right sub-classifier
TMVA::DataSetInfo & CreateCategoryDSI(const TCut &, const TString &, const TString &)
create a DataSetInfo object for a sub-classifier
void DeclareOptions()
options for this method
void AddWeightsXMLTo(void *parent) const
create XML description of Category classifier
const Ranking * CreateRanking()
no ranking
virtual ~MethodCategory(void)
destructor
virtual const std::vector< Float_t > & GetRegressionValues()
returns the mva value of the right sub-classifier
TMVA::IMethod * AddMethod(const TCut &, const TString &theVariables, Types::EMVA theMethod, const TString &theTitle, const TString &theOptions)
adds sub-classifier for a category
void ReadWeightsFromXML(void *wghtnode)
read weights of sub-classifiers of MethodCategory from xml weight file
void Train(void)
train all sub-classifiers
Virtual base class for combining several TMVA method.
Ranking for variables in method (implementation)
virtual void Print() const
get maximum length of variable names
Singleton class for Global types used by TMVA.
static Types & Instance()
the the single instance of "Types" if existing already, or create it (Singleton)
Class for type info of MVA input variable.
const TString & GetExpression() const
void * GetExternalLink() const
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
const char * Data() const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A TTree represents a columnar dataset.
std::string GetMethodName(TCppMethod_t)
std::string GetName(const std::string &scope_name)
create variable transformations
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
MsgLogger & Endl(MsgLogger &ml)
const Int_t MinNoTrainingEvents