#include #include #include #include #include "TMath.h" #include "TChain.h" #include "TFile.h" #include "TTree.h" #include "TString.h" #include "TObjString.h" #include "TSystem.h" #include "TROOT.h" //#include "Functions.h" #include "TMath.h" #include "TMVA/Factory.h" //#include "TMVA/DataLoader.h" #include "TMVA/Tools.h" #include "TMVA/TMVAGui.h" //#include void Application() { // -------------------------------------------------------------------------------------------------- // This loads the library TMVA::Tools::Instance(); std::map Use; // // Boosted Decision Trees Use["BDT"] = 0; // uses Adaptive Boost Use["BDTG"] = 0; // uses Gradient Boost Use["BDTB"] = 0; // uses Bagging Use["BDTD"] = 0; // decorrelation + Adaptive Boost Use["BDTF"] = 1; // allow usage of fisher discriminant for node splitting TMVA::Reader *reader = new TMVA::Reader("!Color"); Float_t zlepPt, zETAlep, zPHIlep, zlepM, zdPHI, zdRll, zaxialMET, zfracPT, zMissingET, zETAmiss, zPHImiss; //reader->AddVariable( "lepPt", &zlepPt); //Reconstructed Z PT //reader->AddVariable( "ETAlep", &zETAlep); //reader->AddVariable( "PHIlep", &zPHIlep); reader->AddVariable( "lepM", &zlepM); reader->AddVariable( "dPHI", &zdPHI); reader->AddVariable( "dRll", &zdRll); reader->AddVariable( "axialMET", &zaxialMET); reader->AddVariable( "fracPT", &zfracPT); reader->AddVariable( "MissingET", &zMissingET); //reader->AddVariable( "ETAmiss", &zETAmiss); //reader->AddVariable( "PHImiss", &zPHImiss); reader->BookMVA( "BDTF method", "/home/saumyen/HEP_Packages/MyRoot/tutorials/tmva/dataset/weights/MVAnalysis_BDTF.weights.xml" ); TFile *input = TFile::Open("/home/saumyen/Dropbox/Untitled_Folder/Signal.root"); TTree* theTree = (TTree*)input->Get("event_tree"); // Book output histograms UInt_t nbin = 100; TH1F *histBdtF(0); if (Use["BDTF"]) histBdtF = new TH1F( "MVA_BDTF", "MVA_BDTF", nbin, -1.0, 1.0 ); Float_t lepPt, ETAlep, PHIlep, lepM, dPHI, dRll, axialMET, fracPT, MissingET, ETAmiss, PHImiss; theTree->SetBranchAddress( "lepPt", &lepPt); //Reconstructed Z PT theTree->SetBranchAddress( "ETAlep", &ETAlep); theTree->SetBranchAddress( "PHIlep", &PHIlep); theTree->SetBranchAddress( "lepM", &lepM); theTree->SetBranchAddress( "dPHI", &dPHI); theTree->SetBranchAddress( "dRll", &dRll); theTree->SetBranchAddress( "axialMET", &axialMET); theTree->SetBranchAddress( "fracPT", &fracPT); theTree->SetBranchAddress( "MissingET", &MissingET); theTree->SetBranchAddress( "ETAmiss", &ETAmiss); theTree->SetBranchAddress( "PHImiss", &PHImiss); std::vector vecVar(4); // vector for EvaluateMVA tests std::cout << "--- Processing: " << theTree->GetEntries() << " events" << std::endl; //TStopwatch sw; //sw.Start(); for (Long64_t ievt=0; ievtGetEntries();ievt++) { if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl; theTree->GetEntry(ievt); zlepPt = lepPt; zETAlep = ETAlep; zPHIlep = PHIlep; zlepM = lepM; zdPHI = dPHI; zdRll = dRll; zaxialMET = axialMET; zfracPT =fracPT; zMissingET = MissingET; zETAmiss = ETAmiss; zPHImiss = PHImiss; if (Use["BDTF" ]) histBdtF ->Fill( reader->EvaluateMVA( "BDTF method" ) ); } // Get elapsed time //sw.Stop(); //std::cout << "--- End of event loop: "; sw.Print(); // Write histograms TFile *target = new TFile( "AppOut.root","RECREATE" ); if (Use["BDTF" ]) histBdtF ->Write(); std::cout << "--- Created root file: \"AppOut.root\" containing the MVA output histograms" << std::endl; delete reader; std::cout << "==> TMVAClassificationApplication is done!" << std::endl << std::endl; }