This macro provides a simple example on how to use the trained classifiers (with categories) within an analysis module
- Project : TMVA - a Root-integrated toolkit for multivariate data analysis
- Package : TMVA
- Exectuable: TMVAClassificationCategoryApplication
0.0251798629761
4.76597976685
Processing /mnt/build/workspace/root-makedoc-v612/rootspi/rdoc/src/v6-12-00-patches/tutorials/tmva/TMVAClassificationCategoryApplication.C...
==> Start TMVAClassificationCategoryApplication
: Booking "FisherCat method" of type "Category" from dataset/weights/TMVAClassificationCategory_FisherCat.weights.xml.
<HEADER> DataSetInfo : [Default] : Added class "Signal"
<HEADER> DataSetInfo : [Default] : Added class "Background"
: Recreating sub-classifiers from XML-file
<HEADER> DataSetInfo : [Category_Fisher_1_dsi] : Added class "Signal"
<HEADER> DataSetInfo : [Category_Fisher_1_dsi] : Added class "Background"
<HEADER> DataSetInfo : [Category_Fisher_2_dsi] : Added class "Signal"
<HEADER> DataSetInfo : [Category_Fisher_2_dsi] : Added class "Background"
: Booked classifier "FisherCat" of type: "Category"
: Booking "LikelihoodCat method" of type "Category" from dataset/weights/TMVAClassificationCategory_LikelihoodCat.weights.xml.
: Recreating sub-classifiers from XML-file
<HEADER> DataSetInfo : [Category_Likelihood_1_dsi] : Added class "Signal"
<HEADER> DataSetInfo : [Category_Likelihood_1_dsi] : Added class "Background"
<HEADER> DataSetInfo : [Category_Likelihood_2_dsi] : Added class "Signal"
<HEADER> DataSetInfo : [Category_Likelihood_2_dsi] : Added class "Background"
: Booked classifier "LikelihoodCat" of type: "Category"
--- TMVAClassificationApp : Accessing /mnt/build/workspace/root-makedoc-v612/rootspi/rdoc/src/v6-12-00-patches/tutorials/tmva/data/toy_sigbkg_categ_offset.root!
--- Use signal sample for evalution
--- Processing: 10000 events
--- ... Processing event: 0
--- ... Processing event: 1000
--- ... Processing event: 2000
--- ... Processing event: 3000
--- ... Processing event: 4000
--- ... Processing event: 5000
--- ... Processing event: 6000
--- ... Processing event: 7000
--- ... Processing event: 8000
--- ... Processing event: 9000
--- End of event loop: Real time 0:00:00, CP time 0.080
--- Created root file: "TMVApp.root" containing the MVA output histograms
==> TMVAClassificationApplication is done!
#include <cstdlib>
#include <vector>
#include <iostream>
#include <map>
#include <string>
#if not defined(__CINT__) || defined(__MAKECINT__)
#endif
void TMVAClassificationCategoryApplication()
{
std::map<std::string,int> Use;
Use["LikelihoodCat"] = 1;
Use["FisherCat"] = 1;
std::cout << std::endl
<< "==> Start TMVAClassificationCategoryApplication" << std::endl;
Float_t var1, var2, var3, var4, eta;
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (it->second) {
TString methodName = it->first +
" method";
TString weightfile =
"dataset/weights/TMVAClassificationCategory_" +
TString(it->first) +
".weights.xml";
reader->
BookMVA( methodName, weightfile );
}
}
std::map<std::string,TH1*> hist;
hist[
"LikelihoodCat"] =
new TH1F(
"MVA_LikelihoodCat",
"MVA_LikelihoodCat", nbin, -1, 0.9999 );
hist[
"FisherCat"] =
new TH1F(
"MVA_FisherCat",
"MVA_FisherCat", nbin, -4, 4 );
fname =
gROOT->GetTutorialDir() +
"/tmva/data/";
}
if (UseOffsetMethod) fname += "toy_sigbkg_categ_offset.root";
else fname += "toy_sigbkg_categ_varoff.root";
std::cout << "--- TMVAClassificationApp : Accessing " << fname << "!" << std::endl;
if (!input) {
std::cout << "ERROR: could not open data file: " << fname << std::endl;
exit(1);
}
std::cout << "--- Use signal sample for evalution" << std::endl;
std::cout <<
"--- Processing: " << theTree->
GetEntries() <<
" events" << std::endl;
if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl;
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (!it->second) continue;
TString methodName = it->first +
" method";
hist[it->first]->Fill( reader->
EvaluateMVA( methodName ) );
}
}
std::cout <<
"--- End of event loop: "; sw.
Print();
TFile *target =
new TFile(
"TMVApp.root",
"RECREATE" );
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++)
if (it->second) hist[it->first]->Write();
std::cout << "--- Created root file: \"TMVApp.root\" containing the MVA output histograms" << std::endl;
std::cout << "==> TMVAClassificationApplication is done!" << std::endl << std::endl;
}
int main(
int argc,
char** argv )
{
TMVAClassificationCategoryApplication();
return 0;
}
- Author
- Andreas Hoecker
Definition in file TMVAClassificationCategoryApplication.C.