00001
00002 #include <cstdlib>
00003 #include <iostream>
00004 #include <map>
00005 #include <string>
00006
00007 #include "TChain.h"
00008 #include "TFile.h"
00009 #include "TTree.h"
00010 #include "TString.h"
00011 #include "TObjString.h"
00012 #include "TSystem.h"
00013 #include "TROOT.h"
00014
00015 #include "TMVAGui.C"
00016
00017 #ifndef __CINT__
00018 #include "TMVA/Tools.h"
00019 #include "TMVA/Factory.h"
00020 #endif
00021
00022 using namespace TMVA;
00023
00024 void Boost2(){
00025 TString outfileName = "boost.root";
00026 TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
00027 TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
00028 "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D" );
00029 factory->AddVariable( "var0", 'F' );
00030 factory->AddVariable( "var1", 'F' );
00031 TFile *input(0);
00032 TString fname = "./circledata.root";
00033 if (!gSystem->AccessPathName( fname )) {
00034
00035 std::cout << "--- BOOST : Accessing " << fname << std::endl;
00036 input = TFile::Open( fname );
00037 }
00038 else {
00039 gROOT->LoadMacro( "./createData.C");
00040 create_fullcirc(20000);
00041 cout << " created circledata.root with data and circle arranged in circles"<<endl;
00042 input = TFile::Open( fname );
00043 }
00044 if (!input) {
00045 std::cout << "ERROR: could not open data file" << std::endl;
00046 exit(1);
00047 }
00048 TTree *signal = (TTree*)input->Get("TreeS");
00049 TTree *background = (TTree*)input->Get("TreeB");
00050 Double_t signalWeight = 1.0;
00051 Double_t backgroundWeight = 1.0;
00052
00053 gROOT->cd( outfileName+TString(":/") );
00054 factory->AddSignalTree ( signal, signalWeight );
00055 factory->AddBackgroundTree( background, backgroundWeight );
00056 factory->PrepareTrainingAndTestTree( "", "",
00057 "nTrain_Signal=10000:nTrain_Background=10000:SplitMode=Random:NormMode=NumEvents:!V" );
00058
00059 TString fisher="H:!V";
00060 factory->BookMethod( TMVA::Types::kFisher, "Fisher", fisher );
00061 factory->BookMethod( TMVA::Types::kFisher, "FisherBS", fisher+":Boost_Num=100:Boost_Type=Bagging:Boost_Transform=step" );
00062 factory->BookMethod( TMVA::Types::kFisher, "FisherS", fisher+":Boost_Num=100:Boost_Type=AdaBoost:Boost_Transform=step" );
00063
00064
00065
00066 factory->TrainAllMethods();
00067
00068
00069 factory->TestAllMethods();
00070
00071
00072 factory->EvaluateAllMethods();
00073
00074
00075
00076
00077 outputFile->Close();
00078
00079 std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
00080 std::cout << "==> TMVAClassification is done!" << std::endl;
00081
00082 delete factory;
00083
00084
00085 if (!gROOT->IsBatch()) TMVAGui( outfileName );
00086
00087
00088 }