#include "TMVA/Factory.h"
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TRegexp.h"
#include "TEventList.h"
#include "TLeaf.h"
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
Go to the source code of this file.
Definition at line 47 of file TMVATraining.C.
References i, n, res, SplitString(), TString, and v.
Referenced by TMVATraining().
51 TRegexp rvar(
"[_a-zA-Z][_a-zA-Z0-9]*");
60 if (v==
"tag" || res.Contains(
" "+v+
" "))
continue;
65 res = res.Strip(TString::kBoth);
int SplitString(TString s, TString delim, TString *toks, int maxtoks)
int gettype |
( |
TTree * |
t, |
|
|
TString |
varname |
|
) |
| |
Definition at line 16 of file TMVATraining.C.
References TString.
Referenced by TMVATraining().
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;
Definition at line 31 of file TMVATraining.C.
References i.
Referenced by getFromCut(), and TMVATraining().
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);
Definition at line 72 of file TMVATraining.C.
References f, getFromCut(), gettype(), i, nsig, SplitString(), t, and TString.
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();
int SplitString(TString s, TString delim, TString *toks, int maxtoks)
TString getFromCut(TString vars)
int gettype(TTree *t, TString varname)