34 void TMVAMulticlassApplication( TString myMethodList =
"" )
41 std::map<std::string,int> Use;
49 std::cout << std::endl;
50 std::cout <<
"==> Start TMVAMulticlassApp" << std::endl;
51 if (myMethodList !=
"") {
52 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
55 for (
UInt_t i=0; i<mlist.size(); i++) {
56 std::string regMethod(mlist[i]);
58 if (Use.find(regMethod) == Use.end()) {
59 std::cout <<
"Method \"" << regMethod <<
"\" not known in TMVA under this name. Choose among the following:" << std::endl;
60 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first <<
" " << std::endl;
61 std::cout << std::endl;
82 TString dir =
"dataset/weights/";
83 TString prefix =
"TMVAMulticlass";
85 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
87 TString methodName = TString(it->first) + TString(
" method");
88 TString weightfile = dir + prefix + TString(
"_") + TString(it->first) + TString(
".weights.xml");
89 reader->
BookMVA( methodName, weightfile );
95 TH1F *histMLP_signal(0), *histBDTG_signal(0), *histFDAGA_signal(0), *histPDEFoam_signal(0), *histDNNCPU_signal(0);
97 histMLP_signal =
new TH1F(
"MVA_MLP_signal",
"MVA_MLP_signal", nbin, 0., 1.1 );
99 histBDTG_signal =
new TH1F(
"MVA_BDTG_signal",
"MVA_BDTG_signal", nbin, 0., 1.1 );
100 if (Use[
"DNN_CPU"]) histDNNCPU_signal =
new TH1F(
"MVA_DNNCPU_signal",
"MVA_DNNCPU_signal", nbin, 0., 1.1);
102 histFDAGA_signal =
new TH1F(
"MVA_FDA_GA_signal",
"MVA_FDA_GA_signal", nbin, 0., 1.1 );
104 histPDEFoam_signal =
new TH1F(
"MVA_PDEFoam_signal",
"MVA_PDEFoam_signal", nbin, 0., 1.1 );
108 TString fname =
"./tmva_example_multiple_background.root";
113 std::cout <<
"ERROR: could not open data file, please generate example data first!" << std::endl;
116 std::cout <<
"--- TMVAMulticlassApp : Using input file: " << input->GetName() << std::endl;
123 TTree* theTree = (TTree*)input->Get(
"TreeS");
124 std::cout <<
"--- Select signal sample" << std::endl;
125 theTree->SetBranchAddress(
"var1", &var1 );
126 theTree->SetBranchAddress(
"var2", &var2 );
127 theTree->SetBranchAddress(
"var3", &var3 );
128 theTree->SetBranchAddress(
"var4", &var4 );
130 std::cout <<
"--- Processing: " << theTree->GetEntries() <<
" events" << std::endl;
134 for (
Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
136 std::cout <<
"--- ... Processing event: " << ievt << std::endl;
138 theTree->GetEntry(ievt);
144 if (Use[
"DNN_CPU"]) histDNNCPU_signal->Fill((reader->
EvaluateMulticlass(
"DNN_CPU method"))[0]);
154 std::cout <<
"--- End of event loop: "; sw.
Print();
156 TFile *target =
new TFile(
"TMVAMulticlassApp.root",
"RECREATE" );
158 histMLP_signal->Write();
160 histBDTG_signal->Write();
161 if (Use[
"DNN_CPU"]) histDNNCPU_signal->Write();
163 histFDAGA_signal->Write();
165 histPDEFoam_signal->Write();
168 std::cout <<
"--- Created root file: \"TMVMulticlassApp.root\" containing the MVA output histograms" << std::endl;
172 std::cout <<
"==> TMVAMulticlassApp is done!" << std::endl << std::endl;
175 int main(
int argc,
char** argv )
179 for (
int i=1; i<argc; i++) {
180 TString regMethod(argv[i]);
181 if(regMethod==
"-b" || regMethod==
"--batch")
continue;
182 if (!methodList.IsNull()) methodList += TString(
",");
183 methodList += regMethod;
185 TMVAMulticlassApplication(methodList);
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
1-D histogram with a float per channel (see TH1 documentation)}
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
void Stop()
Stop the stopwatch.
int main(int argc, char **argv)
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
R__EXTERN TSystem * gSystem
The Reader class serves to use the MVAs in a specific analysis context.
Abstract ClassifierFactory template that handles arbitrary types.
const std::vector< Float_t > & EvaluateMulticlass(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables