==> Start TMVAMulticlassApp
: Booking "BDTG method" of type "BDT" from dataset/weights/TMVAMulticlass_BDTG.weights.xml.
: Reading weight file: dataset/weights/TMVAMulticlass_BDTG.weights.xml
<HEADER> DataSetInfo : [Default] : Added class "Signal"
<HEADER> DataSetInfo : [Default] : Added class "bg0"
<HEADER> DataSetInfo : [Default] : Added class "bg1"
<HEADER> DataSetInfo : [Default] : Added class "bg2"
: Booked classifier "BDTG" of type: "BDT"
: Booking "MLP method" of type "MLP" from dataset/weights/TMVAMulticlass_MLP.weights.xml.
: Reading weight file: dataset/weights/TMVAMulticlass_MLP.weights.xml
<HEADER> MLP : Building Network.
: Initializing weights
: Booked classifier "MLP" of type: "MLP"
--- TMVAMulticlassApp : Using input file: ./tmva_example_multiple_background.root
--- Select signal sample
--- End of event loop: Real time 0:00:00, CP time 2.670
--- Created root file: "TMVMulticlassApp.root" containing the MVA output histograms
==> TMVAMulticlassApp is done!
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
void TMVAMulticlassApplication(
TString myMethodList =
"" )
{
std::map<std::string,int> Use;
Use["MLP"] = 1;
Use["BDTG"] = 1;
Use["DNN_CPU"] = 0;
Use["FDA_GA"] = 0;
Use["PDEFoam"] = 0;
std::cout << std::endl;
std::cout << "==> Start TMVAMulticlassApp" << std::endl;
if (myMethodList != "") {
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
for (
UInt_t i=0; i<mlist.size(); i++) {
std::string regMethod(mlist[i]);
if (Use.find(regMethod) == Use.end()) {
std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl;
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first << " " << std::endl;
std::cout << std::endl;
return;
}
Use[regMethod] = 1;
}
}
reader->AddVariable(
"var1", &var1 );
reader->AddVariable(
"var2", &var2 );
reader->AddVariable(
"var3", &var3 );
reader->AddVariable(
"var4", &var4 );
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (it->second) {
reader->BookMVA( methodName, weightfile );
}
}
TH1F *histMLP_signal(0), *histBDTG_signal(0), *histFDAGA_signal(0), *histPDEFoam_signal(0), *histDNNCPU_signal(0);
if (Use["MLP"])
histMLP_signal =
new TH1F(
"MVA_MLP_signal",
"MVA_MLP_signal", nbin, 0., 1.1 );
if (Use["BDTG"])
histBDTG_signal =
new TH1F(
"MVA_BDTG_signal",
"MVA_BDTG_signal", nbin, 0., 1.1 );
if (Use[
"DNN_CPU"]) histDNNCPU_signal =
new TH1F(
"MVA_DNNCPU_signal",
"MVA_DNNCPU_signal", nbin, 0., 1.1);
if (Use["FDA_GA"])
histFDAGA_signal =
new TH1F(
"MVA_FDA_GA_signal",
"MVA_FDA_GA_signal", nbin, 0., 1.1 );
if (Use["PDEFoam"])
histPDEFoam_signal =
new TH1F(
"MVA_PDEFoam_signal",
"MVA_PDEFoam_signal", nbin, 0., 1.1 );
TString fname =
"./tmva_example_multiple_background.root";
}
if (!input) {
std::cout << "ERROR: could not open data file, please generate example data first!" << std::endl;
exit(1);
}
std::cout << "--- TMVAMulticlassApp : Using input file: " << input->GetName() << std::endl;
std::cout << "--- Select signal sample" << std::endl;
std::cout <<
"--- Processing: " << theTree->
GetEntries() <<
" events" << std::endl;
if (ievt%1000 == 0){
std::cout << "--- ... Processing event: " << ievt << std::endl;
}
if (Use["MLP"])
histMLP_signal->Fill((
reader->EvaluateMulticlass(
"MLP method" ))[0]);
if (Use["BDTG"])
histBDTG_signal->Fill((
reader->EvaluateMulticlass(
"BDTG method" ))[0]);
if (Use[
"DNN_CPU"]) histDNNCPU_signal->Fill((
reader->EvaluateMulticlass(
"DNN_CPU method"))[0]);
if (Use["FDA_GA"])
histFDAGA_signal->Fill((
reader->EvaluateMulticlass(
"FDA_GA method" ))[0]);
if (Use["PDEFoam"])
histPDEFoam_signal->Fill((
reader->EvaluateMulticlass(
"PDEFoam method" ))[0]);
}
std::cout <<
"--- End of event loop: "; sw.
Print();
TFile *target =
new TFile(
"TMVAMulticlassApp.root",
"RECREATE" );
if (Use["MLP"])
histMLP_signal->Write();
if (Use["BDTG"])
histBDTG_signal->Write();
if (Use["DNN_CPU"]) histDNNCPU_signal->Write();
if (Use["FDA_GA"])
histFDAGA_signal->Write();
if (Use["PDEFoam"])
histPDEFoam_signal->Write();
std::cout << "--- Created root file: \"TMVMulticlassApp.root\" containing the MVA output histograms" << std::endl;
std::cout << "==> TMVAMulticlassApp is done!" << std::endl << std::endl;
}
int main(
int argc,
char** argv )
{
for (int i=1; i<argc; i++) {
if(regMethod=="-b" || regMethod=="--batch") continue;
methodList += regMethod;
}
TMVAMulticlassApplication(methodList);
return 0;
}
R__EXTERN TSystem * gSystem
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
virtual void Close(Option_t *option="")
Close a file.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)}
The Reader class serves to use the MVAs in a specific analysis context.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
A TTree object has a header with a name and a title.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
virtual Long64_t GetEntries() const
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
int main(int argc, char **argv)
Abstract ClassifierFactory template that handles arbitrary types.