29 #if not defined(__CINT__) || defined(__MAKECINT__)
36 Bool_t UseOffsetMethod = kTRUE;
38 void TMVAClassificationCategoryApplication()
42 std::map<std::string,int> Use;
44 Use[
"LikelihoodCat"] = 1;
48 std::cout << std::endl
49 <<
"==> Start TMVAClassificationCategoryApplication" << std::endl;
53 TMVA::Reader *reader =
new TMVA::Reader(
"!Color:!Silent" );
57 Float_t var1, var2, var3, var4, eta;
58 reader->AddVariable(
"var1", &var1 );
59 reader->AddVariable(
"var2", &var2 );
60 reader->AddVariable(
"var3", &var3 );
61 reader->AddVariable(
"var4", &var4 );
63 reader->AddSpectator(
"eta", &eta );
67 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
69 TString methodName = it->first +
" method";
70 TString weightfile =
"dataset/weights/TMVAClassificationCategory_" + TString(it->first) +
".weights.xml";
71 reader->BookMVA( methodName, weightfile );
77 std::map<std::string,TH1*> hist;
78 hist[
"LikelihoodCat"] =
new TH1F(
"MVA_LikelihoodCat",
"MVA_LikelihoodCat", nbin, -1, 0.9999 );
79 hist[
"FisherCat"] =
new TH1F(
"MVA_FisherCat",
"MVA_FisherCat", nbin, -4, 4 );
85 TString fname = TString(gSystem->DirName(__FILE__) ) +
"/data/";
87 if (gSystem->AccessPathName( fname +
"toy_sigbkg_categ_offset.root" )) {
88 fname = gROOT->GetTutorialDir() +
"/tmva/data/";
90 if (UseOffsetMethod) fname +=
"toy_sigbkg_categ_offset.root";
91 else fname +=
"toy_sigbkg_categ_varoff.root";
92 std::cout <<
"--- TMVAClassificationApp : Accessing " << fname <<
"!" << std::endl;
93 TFile *input = TFile::Open(fname);
95 std::cout <<
"ERROR: could not open data file: " << fname << std::endl;
106 TTree* theTree = (TTree*)input->Get(
"TreeS");
107 std::cout <<
"--- Use signal sample for evalution" << std::endl;
108 theTree->SetBranchAddress(
"var1", &var1 );
109 theTree->SetBranchAddress(
"var2", &var2 );
110 theTree->SetBranchAddress(
"var3", &var3 );
111 theTree->SetBranchAddress(
"var4", &var4 );
113 theTree->SetBranchAddress(
"eta", &eta );
115 std::cout <<
"--- Processing: " << theTree->GetEntries() <<
" events" << std::endl;
118 for (Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
120 if (ievt%1000 == 0) std::cout <<
"--- ... Processing event: " << ievt << std::endl;
122 theTree->GetEntry(ievt);
126 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
127 if (!it->second)
continue;
128 TString methodName = it->first +
" method";
129 hist[it->first]->Fill( reader->EvaluateMVA( methodName ) );
134 std::cout <<
"--- End of event loop: "; sw.Print();
138 TFile *target =
new TFile(
"TMVApp.root",
"RECREATE" );
139 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++)
140 if (it->second) hist[it->first]->Write();
143 std::cout <<
"--- Created root file: \"TMVApp.root\" containing the MVA output histograms" << std::endl;
146 std::cout <<
"==> TMVAClassificationApplication is done!" << std::endl << std::endl;
149 int main(
int argc,
char** argv )
151 TMVAClassificationCategoryApplication();