/********************************************************************************** * Project : TMVA - a Root-integrated toolkit for multivariate data analysis * * Package : TMVA * * Exectuable: ClassApplication * * * * Test suit for comparison of Reader and standalone class outputs * **********************************************************************************/ #include void ClassApplication( TString myMethodList = "Fisher" ) { cout << endl; cout << "==> start ClassApplication" << endl; const int Nmvas = 17; const char* bulkname[Nmvas] = { "Likelihood", "LikelihoodD", "LikelihoodPCA", "LikelihoodMIX", "HMatrix", "FisherD", "Fisher", "MLP", "BDT", "BDTD", "RuleFit", "SVM_Gauss", "SVM_Poly", "SVM_Lin", "FDA_MT", "FDA_MC", "FDA_GA" }; bool iuse[Nmvas] = { Nmvas*kFALSE }; // interpret input list if (myMethodList != "") { TList* mlist = TMVA::Tools::ParseFormatLine( myMethodList, " :," ); for (int imva=0; imvaFindObject( bulkname[imva] )) iuse[imva] = kTRUE; delete mlist; } // create a set of variables and declare them to the reader // - the variable names must corresponds in name and type to // those given in the weight file(s) that you use std::vector inputVars; inputVars.push_back( "var1+var2" ); inputVars.push_back( "var1-var2" ); inputVars.push_back( "var3" ); inputVars.push_back( "var4" ); // preload standalone class(es) string dir = "weights/"; string prefix = "TMVAnalysis"; for (int imva=0; imvaLoadMacro( cfile ); } } cout << "=== Macro : Classifier class loading successfully terminated" << endl; // define classes IClassifierReader* classReader[Nmvas] = { Nmvas*0 }; // ... and create them (and some histograms for the output) int nbin = 100; TH1* hist[Nmvas]; for (int imva=0; imvaAccessPathName("./tmva_example.root")) { // first we try to find tmva_example.root in the local directory cout << "=== Macro : Accessing ./tmva_example.root" << endl; input = TFile::Open("tmva_example.root"); } else { // second we try accessing the file via the web from // http://root.cern.ch/files/tmva_example.root cout << "=== Macro : Accessing tmva_example.root file from http://root.cern.ch/files" << endl; cout << "=== Macro : For faster startup you may consider downloading it into you local directory" << endl; input = TFile::Open("http://root.cern.ch/files/tmva_example.root"); } if (!input) { cout << "ERROR: could not open data file" << endl; exit(1); } // // prepare the tree // - here the variable names have to corresponds to your tree // - you can use the same variables as above which is slightly faster, // but of course you can use different ones and copy the values inside the event loop // TTree* theTree = (TTree*)input->Get("TreeS"); cout << "=== Macro : Loop over signal sample" << endl; // the references to the variables float var1, var2, var3, var4; float userVar1, userVar2; theTree->SetBranchAddress( "var1", &userVar1 ); theTree->SetBranchAddress( "var2", &userVar2 ); theTree->SetBranchAddress( "var3", &var3 ); theTree->SetBranchAddress( "var4", &var4 ); cout << "=== Macro : Processing total of " << theTree->GetEntries() << " events ... " << endl; std::vector* inputVec = new std::vector( 4 ); for (Long64_t ievt=0; ievtGetEntries();ievt++) { if (ievt%1000 == 0) cout << "=== Macro : ... processing event: " << ievt << endl; theTree->GetEntry(ievt); var1 = userVar1 + userVar2; var2 = userVar1 - userVar2; (*inputVec)[0] = var1; (*inputVec)[1] = var2; (*inputVec)[2] = var3; (*inputVec)[3] = var4; // loop over all booked classifiers for (int imva=0; imvaGetMvaValue( *inputVec ); hist[imva]->Fill( retval, 1.0 ); } } } cout << "=== Macro : Event loop done! " << endl; TFile *target = new TFile( "ClassApp.root","RECREATE" ); for (int imva=0; imvaWrite(); } } cout << "=== Macro : Created target file: " << target->GetName() << endl; target->Close(); delete target; delete inputVec; cout << "==> ClassApplication is done!" << endl << endl; }