1 #include "TMVA/Factory.h" 
    6 #include "TEventList.h" 
   18         if (t->GetBranch(varname)==0) 
return -1;
 
   20         TString leaftype = t->GetLeaf(varname)->GetTypeName();
 
   22         if (leaftype==
"Float_t")         
return 0; 
 
   23         else if (leaftype==
"Int_t")      
return 1;  
 
   24         else if (leaftype==
"Bool_t") 
return 2;
 
   33         TObjArray *tok = s.Tokenize(delim);
 
   34         int N = tok->GetEntries();      
 
   38                         toks[
i] = ((TObjString*)tok->At(
i))->String();
 
   39                         toks[
i].ReplaceAll(
"\t",
"");
 
   40                         toks[
i] = toks[
i].Strip(TString::kBoth);
 
   51         TRegexp rvar(
"[_a-zA-Z][_a-zA-Z0-9]*");
 
   60                         if (v==
"tag" || res.Contains(
" "+v+
" ")) 
continue;
 
   65         res = res.Strip(TString::kBoth);
 
   74         if (vars.Contains(
"&&")) vars = 
getFromCut(vars);
 
   75         cout <<
"Vars : "<<vars<<endl;
 
   77         TString sigcut = 
"tag&&mode%1000!=900";
 
   78         TString bkgcut = 
"tag&&mode%1000==900";
 
   82                 cout <<
"Precut : "<<precut<<endl;
 
   83                 sigcut += 
"&&" + precut;
 
   84                 bkgcut += 
"&&" + precut;
 
   87         TRegexp rntp(
"n[0-9][0-9][0-9]");
 
   88         TRegexp rmod(
"M[0-9][0-9][0-9]");
 
   89         if (treename==
"") treename = fname(rntp);
 
   92         TString code = smode+treename(1,3);
 
   94         TFile *
f = TFile::Open(fname);
 
   95         TTree *
t =(TTree*) f->Get(treename);
 
   97         TFile* outputFile = TFile::Open( 
"TMVA_"+code+
".root", 
"RECREATE" );
 
   99         TMVA::Factory *factory = 
new TMVA::Factory( code, outputFile, 
"Silent:!V:Transformations=I;N;D");
 
  104         for (
int i=0;
i<N;++
i)
 
  107                 if (btype==0 || btype==1)
 
  108                         factory->AddVariable(toks[i], btype==0?
'F':
'I');
 
  111         factory->AddTree( t, 
"Signal",     1.0, sigcut.Data());
 
  112         factory->AddTree( t, 
"Background", 1.0, bkgcut.Data());
 
  114         int nsig = t->GetEntries(sigcut);
 
  115         int nbkg = t->GetEntries(bkgcut);
 
  117         factory->PrepareTrainingAndTestTree( 
"", 
int(nsig*0.8), 
int(nbkg*0.8), 
int(nsig*0.19), 
int(nbkg*0.19)); 
 
  125         factory->BookMethod( TMVA::Types::kBDT, 
"BDT", 
"!V:nTrees=400:BoostType=AdaBoost:nCuts=10:NNodesMax=10" );
 
  127         factory->TrainAllMethods();  
 
TString getFromCut(TString vars)
int gettype(TTree *t, TString varname)
int SplitString(TString s, TString delim, StrVec &toks)
int TMVATraining(TString fname, TString vars, TString precut="", TString treename="")