/********************************************************************************** * Project : TMVA - a Root-integrated toolkit for multivariate data analysis * * Package : TMVA * * Exectuable: TMVAClassificationApplication * * * * This macro provides a simple example on how to use the trained classifiers * * within an analysis module * **********************************************************************************/ #include #include #include #include #include #include "TFile.h" #include "TTree.h" #include "TString.h" #include "TSystem.h" #include "TROOT.h" #include "TStopwatch.h" #include "TMVA/Tools.h" #include "TMVA/Reader.h" #include "TMVA/MethodCuts.h" using namespace TMVA; void TMVAClassificationApplication( TString myMethodList = "" ) { //--------------------------------------------------------------- // This loads the library TMVA::Tools::Instance(); // Default MVA methods to be trained + tested std::map Use; // --- Cut optimisation Use["Cuts"] = 0; Use["CutsD"] = 0; Use["CutsPCA"] = 0; Use["CutsGA"] = 0; Use["CutsSA"] = 0; // // --- 1-dimensional likelihood ("naive Bayes estimator") Use["Likelihood"] = 0; Use["LikelihoodD"] = 0; // the "D" extension indicates decorrelated input variables (see option strings) Use["LikelihoodPCA"] = 0; // the "PCA" extension indicates PCA-transformed input variables (see option strings) Use["LikelihoodKDE"] = 0; Use["LikelihoodMIX"] = 0; // // --- Mutidimensional likelihood and Nearest-Neighbour methods Use["PDERS"] = 0; Use["PDERSD"] = 0; Use["PDERSPCA"] = 0; Use["PDEFoam"] = 0; Use["PDEFoamBoost"] = 0; // uses generalised MVA method boosting Use["KNN"] = 0; // k-nearest neighbour method // // --- Linear Discriminant Analysis Use["LD"] = 0; // Linear Discriminant identical to Fisher Use["Fisher"] = 0; Use["FisherG"] = 0; Use["BoostedFisher"] = 0; // uses generalised MVA method boosting Use["HMatrix"] = 0; // // --- Function Discriminant analysis Use["FDA_GA"] = 0; // minimisation of user-defined function using Genetics Algorithm Use["FDA_SA"] = 0; Use["FDA_MC"] = 0; Use["FDA_MT"] = 0; Use["FDA_GAMT"] = 0; Use["FDA_MCMT"] = 0; // // --- Neural Networks (all are feed-forward Multilayer Perceptrons) Use["MLP"] = 0; // Recommended ANN Use["MLPBFGS"] = 0; // Recommended ANN with optional training method Use["MLPBNN"] = 0; // Recommended ANN with BFGS training method and bayesian regulator Use["CFMlpANN"] = 0; // Depreciated ANN from ALEPH Use["TMlpANN"] = 0; // ROOT's own ANN // // --- Support Vector Machine Use["SVM"] = 0; // // --- Boosted Decision Trees Use["BDT"] = 1; // uses Adaptive Boost Use["BDTG"] = 0; // uses Gradient Boost Use["BDTB"] = 0; // uses Bagging Use["BDTD"] = 0; // decorrelation + Adaptive Boost // // --- Friedman's RuleFit method, ie, an optimised series of cuts ("rules") Use["RuleFit"] = 0; // --------------------------------------------------------------- Use["Plugin"] = 0; Use["Category"] = 0; Use["SVM_Gauss"] = 0; Use["SVM_Poly"] = 0; Use["SVM_Lin"] = 0; std::cout << std::endl; std::cout << "==> Start TMVAClassificationApplication" << std::endl; // Select methods (don't look at this code - not of interest) if (myMethodList != "") { for (std::map::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0; std::vector mlist = gTools().SplitString( myMethodList, ',' ); for (UInt_t i=0; i::iterator it = Use.begin(); it != Use.end(); it++) { std::cout << it->first << " "; } std::cout << std::endl; return; } Use[regMethod] = 1; } } // -------------------------------------------------------------------------------------------------- // --- Create the Reader object TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" ); // 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) used /*Float_t Rratio_Higgs_pt; Float_t Rhiggs_pt_asym; Float_t Rratio , Rw1 , Rw2 , Rx1 , Rx2; Float_t Rdetalb , Rdphilb , Rdrlb; Float_t Rdetal_b , Rdphil_b , Rdrl_b; Float_t Rm_H; Float_t RE_tt; reader->AddVariable("ratio",&Rratio); reader->AddVariable("w1",&Rw1); reader->AddVariable("w2",&Rw2); reader->AddVariable("x1",&Rx1); reader->AddVariable("x2",&Rx2); reader->AddVariable("E_tt",&RE_tt); reader->AddVariable("higgs_pt_ratio", &Rratio_Higgs_pt); reader->AddVariable("higgs_pt_asym",&Rhiggs_pt_asym); reader->AddVariable("detalb", &Rdetalb); reader->AddVariable("dphilb", &Rdphilb); reader->AddVariable("drlb", &Rdrlb); reader->AddVariable("detal_b", &Rdetal_b); reader->AddVariable("dphil_b", &Rdphil_b); reader->AddVariable("drl_b", &Rdrl_b); reader->AddSpectator("m_H",&Rm_H); */ Float_t Rratio,Rw1,Rw2,Rx1,Rx2; Float_t RE_tt,Rhiggs_pt_ratio,Rhiggs_pt_asym; Float_t Rdeta1 ,Rdphi1, Rdr1; Float_t Rdeta2 ,Rdphi2, Rdr2; Float_t Rdeta3 ,Rdphi3, Rdr3; Float_t Rdeta4 ,Rdphi4, Rdr4; Float_t Rdeta5 ,Rdphi5, Rdr5; Float_t Rdeta6 ,Rdphi6, Rdr6; Float_t Rdeta7 ,Rdphi7, Rdr7; Float_t Rdeta8 ,Rdphi8, Rdr8; Float_t Rdeta9 ,Rdphi9, Rdr9; Float_t Rdeta10 ,Rdphi10, Rdr10; Float_t Rdeta11 ,Rdphi11, Rdr11; Float_t Rdeta12 ,Rdphi12, Rdr12; Float_t Rdeta13 ,Rdphi13, Rdr13; Float_t Rm_H; Int_t Revent_number ,Rlep_comb ,Rjet_comb; Float_t HIGGS1; Float_t HIGGS2; Int_t EV1; Int_t EV2; Float_t prob; TTree *postTMVA_inpeak = new TTree("mytreein","mytreein"); postTMVA_inpeak->Branch("higgsmass" ,&HIGGS1 ,"HIGGS1/F"); postTMVA_inpeak->Branch("eventnumber" ,&EV1 ,"EV1/I"); TTree *postTMVA_outpeak = new TTree("mytreeout","mytreeout"); postTMVA_outpeak->Branch("higgsmass" ,&HIGGS2 ,"HIGGS2/F"); postTMVA_outpeak->Branch("eventnumber" ,&EV2 ,"EV2/I"); TTree *TMVA_prob_inpeak = new TTree("tree1","tree1"); TMVA_prob_inpeak->Branch("prob_in" ,&prob ,"prob/F"); TTree *TMVA_prob_outpeak = new TTree("tree2","tree2"); TMVA_prob_outpeak->Branch("prob_out" ,&prob ,"prob/F"); reader->AddVariable("ratio" , &Rratio); reader->AddVariable("w1" , &Rw1); reader->AddVariable("w2" , &Rw2); reader->AddVariable("x1" , &Rx1); reader->AddVariable("x2" , &Rx2); reader->AddVariable("E_tt" , &RE_tt); reader->AddVariable("higgs_pt_ratio" , &Rhiggs_pt_ratio); reader->AddVariable("higgs_pt_asym" , &Rhiggs_pt_asym); reader->AddVariable("deta1" , &Rdeta1); reader->AddVariable("dphi1" , &Rdphi1); reader->AddVariable("dr1" , &Rdr1); reader->AddSpectator("deta2" , &Rdeta2); reader->AddSpectator("dphi2" , &Rdphi2); reader->AddSpectator("dr2" , &Rdr2); reader->AddSpectator("deta3" , &Rdeta3); reader->AddSpectator("dphi3" , &Rdphi3); reader->AddSpectator("dr3" , &Rdr3); reader->AddSpectator("deta4" , &Rdeta4); reader->AddSpectator("dphi4" , &Rdphi4); reader->AddSpectator("dr4" , &Rdr4); reader->AddSpectator("deta5" , &Rdeta5); reader->AddSpectator("dphi5" , &Rdphi5); reader->AddSpectator("dr5" , &Rdr5); reader->AddVariable("deta6" , &Rdeta6); reader->AddVariable("dphi6" , &Rdphi6); reader->AddVariable("dr6" , &Rdr6); reader->AddSpectator("deta7" , &Rdeta7); reader->AddSpectator("dphi7" , &Rdphi7); reader->AddSpectator("dr7" , &Rdr7); reader->AddSpectator("deta8" , &Rdeta8); reader->AddSpectator("dphi8" , &Rdphi8); reader->AddSpectator("dr8" , &Rdr8); reader->AddVariable("deta9" , &Rdeta9); reader->AddVariable("dphi9" , &Rdphi9); reader->AddVariable("dr9" , &Rdr9); reader->AddSpectator("deta10" , &Rdeta10); reader->AddSpectator("dphi10" , &Rdphi10); reader->AddSpectator("dr10" , &Rdr10); reader->AddSpectator("deta11" , &Rdeta11); reader->AddSpectator("dphi11" , &Rdphi11); reader->AddSpectator("dr11" , &Rdr11); reader->AddSpectator("deta12" , &Rdeta12); reader->AddSpectator("dphi12" , &Rdphi12); reader->AddSpectator("dr12" , &Rdr12); reader->AddSpectator("deta13" , &Rdeta13); reader->AddSpectator("dphi13" , &Rdphi13); reader->AddSpectator("dr13" , &Rdr13); reader->AddSpectator("m_H" , &Rm_H); reader->AddSpectator("event_number" , &Revent_number); reader->AddSpectator("lep_comb" , &Rlep_comb); reader->AddSpectator("jet_comb" , &Rjet_comb); // Spectator variables declared in the training have to be added to the reader, too // --- Book the MVA methods TString dir = "weights/"; TString prefix = "TMVAClassification"; // Book method(s) for (std::map::iterator it = Use.begin(); it != Use.end(); it++) { if (it->second) { TString methodName = TString(it->first) + TString(" method"); TString weightfile = dir + prefix + TString("_") + TString(it->first) + TString(".weights.xml"); reader->BookMVA( methodName, weightfile ); } } //***/// MY HISTOGRAMS ////****// TH1D *higgsmass_in(0); higgsmass_in = new TH1D("higgs_mass_inpeak","Higgs mass1",125,0,250); TH1D *higgsmass_out(0); higgsmass_out = new TH1D("higgs_mass_outpeak","Higgs mass2",125,0,250); /* TH1D *event_numb_in(0); event_numb_in = new TH1D("event_number_inpeak","en1",1500,0,1500); TH1D *event_numb_out(0); event_numb_out = new TH1D("event_number_outpeak","en2",1500,0,1500); */ // Book output histograms UInt_t nbin = 100; TH1F *histLk(0), *histLkD(0), *histLkPCA(0), *histLkKDE(0), *histLkMIX(0), *histPD(0), *histPDD(0); TH1F *histPDPCA(0), *histPDEFoam(0), *histPDEFoamErr(0), *histPDEFoamSig(0), *histKNN(0), *histHm(0); TH1F *histFi(0), *histFiG(0), *histFiB(0), *histLD(0), *histNn(0),*histNnbfgs(0),*histNnbnn(0); TH1F *histNnC(0), *histNnT(0), *histBdt(0), *histBdtG(0), *histBdtD(0), *histRf(0), *histSVMG(0); TH1F *histSVMP(0), *histSVML(0), *histFDAMT(0), *histFDAGA(0), *histCat(0), *histPBdt(0); if (Use["Likelihood"]) histLk = new TH1F( "MVA_Likelihood", "MVA_Likelihood", nbin, -1, 1 ); if (Use["LikelihoodD"]) histLkD = new TH1F( "MVA_LikelihoodD", "MVA_LikelihoodD", nbin, -1, 0.9999 ); if (Use["LikelihoodPCA"]) histLkPCA = new TH1F( "MVA_LikelihoodPCA", "MVA_LikelihoodPCA", nbin, -1, 1 ); if (Use["LikelihoodKDE"]) histLkKDE = new TH1F( "MVA_LikelihoodKDE", "MVA_LikelihoodKDE", nbin, -0.00001, 0.99999 ); if (Use["LikelihoodMIX"]) histLkMIX = new TH1F( "MVA_LikelihoodMIX", "MVA_LikelihoodMIX", nbin, 0, 1 ); if (Use["PDERS"]) histPD = new TH1F( "MVA_PDERS", "MVA_PDERS", nbin, 0, 1 ); if (Use["PDERSD"]) histPDD = new TH1F( "MVA_PDERSD", "MVA_PDERSD", nbin, 0, 1 ); if (Use["PDERSPCA"]) histPDPCA = new TH1F( "MVA_PDERSPCA", "MVA_PDERSPCA", nbin, 0, 1 ); if (Use["KNN"]) histKNN = new TH1F( "MVA_KNN", "MVA_KNN", nbin, 0, 1 ); if (Use["HMatrix"]) histHm = new TH1F( "MVA_HMatrix", "MVA_HMatrix", nbin, -0.95, 1.55 ); if (Use["Fisher"]) histFi = new TH1F( "MVA_Fisher", "MVA_Fisher", nbin, -4, 4 ); if (Use["FisherG"]) histFiG = new TH1F( "MVA_FisherG", "MVA_FisherG", nbin, -1, 1 ); if (Use["BoostedFisher"]) histFiB = new TH1F( "MVA_BoostedFisher", "MVA_BoostedFisher", nbin, -2, 2 ); if (Use["LD"]) histLD = new TH1F( "MVA_LD", "MVA_LD", nbin, -2, 2 ); if (Use["MLP"]) histNn = new TH1F( "MVA_MLP", "MVA_MLP", nbin, -1.25, 1.5 ); if (Use["MLPBFGS"]) histNnbfgs = new TH1F( "MVA_MLPBFGS", "MVA_MLPBFGS", nbin, -1.25, 1.5 ); if (Use["MLPBNN"]) histNnbnn = new TH1F( "MVA_MLPBNN", "MVA_MLPBNN", nbin, -1.25, 1.5 ); if (Use["CFMlpANN"]) histNnC = new TH1F( "MVA_CFMlpANN", "MVA_CFMlpANN", nbin, 0, 1 ); if (Use["TMlpANN"]) histNnT = new TH1F( "MVA_TMlpANN", "MVA_TMlpANN", nbin, -1.3, 1.3 ); if (Use["BDT"]) histBdt = new TH1F( "MVA_BDT", "MVA_BDT", nbin, -0.8, 0.8 ); if (Use["BDTD"]) histBdtD = new TH1F( "MVA_BDTD", "MVA_BDTD", nbin, -0.8, 0.8 ); if (Use["BDTG"]) histBdtG = new TH1F( "MVA_BDTG", "MVA_BDTG", nbin, -1.0, 1.0 ); if (Use["RuleFit"]) histRf = new TH1F( "MVA_RuleFit", "MVA_RuleFit", nbin, -2.0, 2.0 ); if (Use["SVM_Gauss"]) histSVMG = new TH1F( "MVA_SVM_Gauss", "MVA_SVM_Gauss", nbin, 0.0, 1.0 ); if (Use["SVM_Poly"]) histSVMP = new TH1F( "MVA_SVM_Poly", "MVA_SVM_Poly", nbin, 0.0, 1.0 ); if (Use["SVM_Lin"]) histSVML = new TH1F( "MVA_SVM_Lin", "MVA_SVM_Lin", nbin, 0.0, 1.0 ); if (Use["FDA_MT"]) histFDAMT = new TH1F( "MVA_FDA_MT", "MVA_FDA_MT", nbin, -2.0, 3.0 ); if (Use["FDA_GA"]) histFDAGA = new TH1F( "MVA_FDA_GA", "MVA_FDA_GA", nbin, -2.0, 3.0 ); if (Use["Category"]) histCat = new TH1F( "MVA_Category", "MVA_Category", nbin, -2., 2. ); if (Use["Plugin"]) histPBdt = new TH1F( "MVA_PBDT", "MVA_BDT", nbin, -0.8, 0.8 ); // PDEFoam also returns per-event error, fill in histogram, and also fill significance if (Use["PDEFoam"]) { histPDEFoam = new TH1F( "MVA_PDEFoam", "MVA_PDEFoam", nbin, 0, 1 ); histPDEFoamErr = new TH1F( "MVA_PDEFoamErr", "MVA_PDEFoam error", nbin, 0, 1 ); histPDEFoamSig = new TH1F( "MVA_PDEFoamSig", "MVA_PDEFoam significance", nbin, 0, 10 ); } // Book example histogram for probability (the other methods are done similarly) TH1F *probHistFi(0), *rarityHistFi(0); if (Use["Fisher"]) { probHistFi = new TH1F( "MVA_Fisher_Proba", "MVA_Fisher_Proba", nbin, 0, 1 ); rarityHistFi = new TH1F( "MVA_Fisher_Rarity", "MVA_Fisher_Rarity", nbin, 0, 1 ); } // Prepare input tree (this must be replaced by your data source) // in this example, there is a toy tree with signal and one with background events // we'll later on use only the "signal" events for the test in this example. // TFile input("/afs/cern.ch/work/g/gbillis/tmva3/wrng_sol_half2total_witheventN.root","update"); /* if (!input) { std::cout << "ERROR: could not open data file" << std::endl; exit(1); } std::cout << "--- TMVAClassificationApp : Using input file: " << input.GetName() << std::endl; */ // --- Event loop // Prepare the event 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 // std::cout << "--- Select signal sample" << std::endl; TTree* theTree = (TTree*)input.Get("mytreewrng2"); /* Double_t tratio_Higgs_pt; Double_t thiggs_pt_asym; Double_t tratio , tw1 , tw2 , tx1 , tx2; Double_t tdetalb , tdphilb , tdrlb; Double_t tdetal_b , tdphil_b , tdrl_b; Double_t tm_H , tE_tt; Double_t tdetaH1 , tdphiH1 , tdrH1; Double_t tdetaH2 , tdphiH2 , tdrH2; theTree->SetBranchAddress("ratio", &tratio); theTree->SetBranchAddress("w1", &tw1); theTree->SetBranchAddress("w2", &tw2); theTree->SetBranchAddress("x1", &tx1); theTree->SetBranchAddress("x2", &tx2); theTree->SetBranchAddress("E_tt", &tE_tt); theTree->SetBranchAddress("higgs_pt_ratio", &tratio_Higgs_pt); theTree->SetBranchAddress("higgs_pt_asym", &thiggs_pt_asym); theTree->SetBranchAddress("detalb", &tdetalb); theTree->SetBranchAddress("dphilb", &tdphilb); theTree->SetBranchAddress("drlb", &tdrlb); theTree->SetBranchAddress("detal_b", &tdetal_b); theTree->SetBranchAddress("dphil_b", &tdphil_b); theTree->SetBranchAddress("drl_b", &tdrl_b); theTree->SetBranchAddress("detaH1", &tdetaH1); theTree->SetBranchAddress("dphiH1", &tdphiH1); theTree->SetBranchAddress("drH1", &tdrH1); theTree->SetBranchAddress("detaH2", &tdetaH2 ); theTree->SetBranchAddress("dphiH2", &tdphiH2); theTree->SetBranchAddress("drH2", &tdrH2); theTree->SetBranchAddress("m_H", &tm_H); */ Double_t tratio ,tw1 , tw2,tx1,tx2; Double_t tE_tt ,thiggs_pt_ratio,thiggs_pt_asym; Double_t tdeta1 ,tdphi1 , tdr1; Double_t tdeta2 ,tdphi2 , tdr2; Double_t tdeta3 ,tdphi3 , tdr3; Double_t tdeta4 ,tdphi4 , tdr4; Double_t tdeta5 ,tdphi5 , tdr5; Double_t tdeta6 ,tdphi6 , tdr6; Double_t tdeta7 ,tdphi7 , tdr7; Double_t tdeta8 ,tdphi8 , tdr8; Double_t tdeta9 ,tdphi9 , tdr9; Double_t tdeta10 ,tdphi10, tdr10; Double_t tdeta11 ,tdphi11, tdr11; Double_t tdeta12 ,tdphi12, tdr12; Double_t tdeta13 ,tdphi13, tdr13; Double_t tm_H; Int_t tevent_number ,tlep_comb ,tjet_comb; theTree->SetBranchAddress("ratio", &tratio); theTree->SetBranchAddress("w1", &tw1); theTree->SetBranchAddress("w2", &tw2); theTree->SetBranchAddress("x1", &tx1); theTree->SetBranchAddress("x2", &tx2); theTree->SetBranchAddress("E_tt", &tE_tt); theTree->SetBranchAddress("higgs_pt_ratio", &thiggs_pt_ratio); theTree->SetBranchAddress("higgs_pt_asym", &thiggs_pt_asym); theTree->SetBranchAddress("deta1", &tdeta1); theTree->SetBranchAddress("dphi1", &tdphi1); theTree->SetBranchAddress("dr1", &tdr1); theTree->SetBranchAddress("deta2", &tdeta2); theTree->SetBranchAddress("dphi2", &tdphi2); theTree->SetBranchAddress("dr2", &tdr2); theTree->SetBranchAddress("deta3", &tdeta3); theTree->SetBranchAddress("dphi3", &tdphi3); theTree->SetBranchAddress("dr3", &tdr3); theTree->SetBranchAddress("deta4", &tdeta4); theTree->SetBranchAddress("dphi4", &tdphi4); theTree->SetBranchAddress("dr4", &tdr4); theTree->SetBranchAddress("deta5", &tdeta5); theTree->SetBranchAddress("dphi5", &tdphi5); theTree->SetBranchAddress("dr5", &tdr5); theTree->SetBranchAddress("deta6", &tdeta6); theTree->SetBranchAddress("dphi6", &tdphi6); theTree->SetBranchAddress("dr6", &tdr6); theTree->SetBranchAddress("deta7", &tdeta7); theTree->SetBranchAddress("dphi7", &tdphi7); theTree->SetBranchAddress("dr7", &tdr7); theTree->SetBranchAddress("deta8", &tdeta8); theTree->SetBranchAddress("dphi8", &tdphi8); theTree->SetBranchAddress("dr8", &tdr8); theTree->SetBranchAddress("deta9", &tdeta9); theTree->SetBranchAddress("dphi9", &tdphi9); theTree->SetBranchAddress("dr9", &tdr9); theTree->SetBranchAddress("deta10", &tdeta10); theTree->SetBranchAddress("dphi10", &tdphi10); theTree->SetBranchAddress("dr10", &tdr10); theTree->SetBranchAddress("deta11", &tdeta11); theTree->SetBranchAddress("dphi11", &tdphi11); theTree->SetBranchAddress("dr11", &tdr11); theTree->SetBranchAddress("deta12", &tdeta12); theTree->SetBranchAddress("dphi12", &tdphi12); theTree->SetBranchAddress("dr12", &tdr12); theTree->SetBranchAddress("deta13", &tdeta13); theTree->SetBranchAddress("dphi13", &tdphi13); theTree->SetBranchAddress("dr13", &tdr13); theTree->SetBranchAddress("m_H", &tm_H); theTree->SetBranchAddress("event_number", &tevent_number); theTree->SetBranchAddress("lep_comb", &tlep_comb); theTree->SetBranchAddress("jet_comb", &tjet_comb); // Efficiency calculator for cut method Int_t nSelCutsGA = 0; Double_t effS = 0.7; 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%10000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl; theTree->GetEntry(ievt); Rratio = tratio; Rw1 = tw1; Rw2 = tw2; Rx1 = tx1; Rx2 = tx2; RE_tt = tE_tt; Rhiggs_pt_ratio = thiggs_pt_ratio; Rhiggs_pt_asym = thiggs_pt_asym; Rdeta1 = tdeta1; Rdphi1 = tdphi1; Rdr1 = tdr1; Rdeta2 = tdeta2; Rdphi2 = tdphi2; Rdr2 = tdr2; Rdeta3 = tdeta3; Rdphi3 = tdphi3; Rdr3 = tdr3; Rdeta4 = tdeta4; Rdphi4 = tdphi4; Rdr4 = tdr4; Rdeta5 = tdeta5; Rdphi5 = tdphi5; Rdr5 = tdr5; Rdeta6 = tdeta6; Rdphi6 = tdphi6; Rdr6 = tdr6; Rdeta7 = tdeta7; Rdphi7 = tdphi7; Rdr7 = tdr7; Rdeta8 = tdeta8; Rdphi8 = tdphi8; Rdr8 = tdr8; Rdeta9 = tdeta9; Rdphi9 = tdphi9; Rdr9 = tdr9; Rdeta10 = tdeta10; Rdphi10 = tdphi10; Rdr10 = tdr10; Rdeta11 = tdeta11; Rdphi11 = tdphi11; Rdr11 = tdr11; Rdeta12 = tdeta12; Rdphi12 = tdphi12; Rdr12 = tdr12; Rdeta13 = tdeta13; Rdphi13 = tdphi13; Rdr13 = tdr13; Rm_H = tm_H; Revent_number = tevent_number; Rlep_comb = tlep_comb; Rjet_comb = tjet_comb; //prob = reader->EvaluateMVA("BDT method"); if(reader->EvaluateMVA("BDT method")> 0.2){ if(Rratio>0.1){ if(Rm_H>124 && Rm_H<126){ //higgsmass_in->Fill(Rm_H); HIGGS1=Rm_H; EV1=Revent_number; // cout<<"in ="<Fill(); // TMVA_prob_inpeak->Fill(); } else{ //higgsmass_out->Fill(Rm_H); HIGGS2=Rm_H; EV2=Revent_number; // cout<<"out = "<Fill(); // TMVA_prob_outpeak->Fill(); } } } // --- Return the MVA outputs and fill into histograms if (Use["CutsGA"]) { // Cuts is a special case: give the desired signal efficienciy Bool_t passed = reader->EvaluateMVA( "CutsGA method", effS ); if (passed) nSelCutsGA++; } if (Use["Likelihood" ]) histLk ->Fill( reader->EvaluateMVA( "Likelihood method" ) ); if (Use["LikelihoodD" ]) histLkD ->Fill( reader->EvaluateMVA( "LikelihoodD method" ) ); if (Use["LikelihoodPCA"]) histLkPCA ->Fill( reader->EvaluateMVA( "LikelihoodPCA method" ) ); if (Use["LikelihoodKDE"]) histLkKDE ->Fill( reader->EvaluateMVA( "LikelihoodKDE method" ) ); if (Use["LikelihoodMIX"]) histLkMIX ->Fill( reader->EvaluateMVA( "LikelihoodMIX method" ) ); if (Use["PDERS" ]) histPD ->Fill( reader->EvaluateMVA( "PDERS method" ) ); if (Use["PDERSD" ]) histPDD ->Fill( reader->EvaluateMVA( "PDERSD method" ) ); if (Use["PDERSPCA" ]) histPDPCA ->Fill( reader->EvaluateMVA( "PDERSPCA method" ) ); if (Use["KNN" ]) histKNN ->Fill( reader->EvaluateMVA( "KNN method" ) ); if (Use["HMatrix" ]) histHm ->Fill( reader->EvaluateMVA( "HMatrix method" ) ); if (Use["Fisher" ]) histFi ->Fill( reader->EvaluateMVA( "Fisher method" ) ); if (Use["FisherG" ]) histFiG ->Fill( reader->EvaluateMVA( "FisherG method" ) ); if (Use["BoostedFisher"]) histFiB ->Fill( reader->EvaluateMVA( "BoostedFisher method" ) ); if (Use["LD" ]) histLD ->Fill( reader->EvaluateMVA( "LD method" ) ); if (Use["MLP" ]) histNn ->Fill( reader->EvaluateMVA( "MLP method" ) ); if (Use["MLPBFGS" ]) histNnbfgs ->Fill( reader->EvaluateMVA( "MLPBFGS method" ) ); if (Use["MLPBNN" ]) histNnbnn ->Fill( reader->EvaluateMVA( "MLPBNN method" ) ); if (Use["CFMlpANN" ]) histNnC ->Fill( reader->EvaluateMVA( "CFMlpANN method" ) ); if (Use["TMlpANN" ]) histNnT ->Fill( reader->EvaluateMVA( "TMlpANN method" ) ); if (Use["BDT" ]) histBdt ->Fill( reader->EvaluateMVA( "BDT method" ) ); if (Use["BDTD" ]) histBdtD ->Fill( reader->EvaluateMVA( "BDTD method" ) ); if (Use["BDTG" ]) histBdtG ->Fill( reader->EvaluateMVA( "BDTG method" ) ); if (Use["RuleFit" ]) histRf ->Fill( reader->EvaluateMVA( "RuleFit method" ) ); if (Use["SVM_Gauss" ]) histSVMG ->Fill( reader->EvaluateMVA( "SVM_Gauss method" ) ); if (Use["SVM_Poly" ]) histSVMP ->Fill( reader->EvaluateMVA( "SVM_Poly method" ) ); if (Use["SVM_Lin" ]) histSVML ->Fill( reader->EvaluateMVA( "SVM_Lin method" ) ); if (Use["FDA_MT" ]) histFDAMT ->Fill( reader->EvaluateMVA( "FDA_MT method" ) ); if (Use["FDA_GA" ]) histFDAGA ->Fill( reader->EvaluateMVA( "FDA_GA method" ) ); if (Use["Category" ]) histCat ->Fill( reader->EvaluateMVA( "Category method" ) ); if (Use["Plugin" ]) histPBdt ->Fill( reader->EvaluateMVA( "P_BDT method" ) ); // Retrieve also per-event error if (Use["PDEFoam"]) { Double_t val = reader->EvaluateMVA( "PDEFoam method" ); Double_t err = reader->GetMVAError(); histPDEFoam ->Fill( val ); histPDEFoamErr->Fill( err ); if (err>1.e-50) histPDEFoamSig->Fill( val/err ); } // Retrieve probability instead of MVA output if (Use["Fisher"]) { probHistFi ->Fill( reader->GetProba ( "Fisher method" ) ); rarityHistFi->Fill( reader->GetRarity( "Fisher method" ) ); } } // Get elapsed time sw.Stop(); std::cout << "--- End of event loop: "; sw.Print(); // Get efficiency for cuts classifier if (Use["CutsGA"]) std::cout << "--- Efficiency for CutsGA method: " << double(nSelCutsGA)/theTree->GetEntries() << " (for a required signal efficiency of " << effS << ")" << std::endl; if (Use["CutsGA"]) { // test: retrieve cuts for particular signal efficiency // CINT ignores dynamic_casts so we have to use a cuts-secific Reader function to acces the pointer TMVA::MethodCuts* mcuts = reader->FindCutsMVA( "CutsGA method" ) ; if (mcuts) { std::vector cutsMin; std::vector cutsMax; mcuts->GetCuts( 0.7, cutsMin, cutsMax ); std::cout << "--- -------------------------------------------------------------" << std::endl; std::cout << "--- Retrieve cut values for signal efficiency of 0.7 from Reader" << std::endl; for (UInt_t ivar=0; ivarGetInputVar(ivar) << "\" <= " << cutsMax[ivar] << std::endl; } std::cout << "--- -------------------------------------------------------------" << std::endl; } } // --- Write histograms TFile *target = new TFile( "TMVApp_sig_and_BG_BDTgreaterP0.2_evaluation_eN.root","RECREATE" ); if (Use["Likelihood" ]) histLk ->Write(); if (Use["LikelihoodD" ]) histLkD ->Write(); if (Use["LikelihoodPCA"]) histLkPCA ->Write(); if (Use["LikelihoodKDE"]) histLkKDE ->Write(); if (Use["LikelihoodMIX"]) histLkMIX ->Write(); if (Use["PDERS" ]) histPD ->Write(); if (Use["PDERSD" ]) histPDD ->Write(); if (Use["PDERSPCA" ]) histPDPCA ->Write(); if (Use["KNN" ]) histKNN ->Write(); if (Use["HMatrix" ]) histHm ->Write(); if (Use["Fisher" ]) histFi ->Write(); if (Use["FisherG" ]) histFiG ->Write(); if (Use["BoostedFisher"]) histFiB ->Write(); if (Use["LD" ]) histLD ->Write(); if (Use["MLP" ]) histNn ->Write(); if (Use["MLPBFGS" ]) histNnbfgs ->Write(); if (Use["MLPBNN" ]) histNnbnn ->Write(); if (Use["CFMlpANN" ]) histNnC ->Write(); if (Use["TMlpANN" ]) histNnT ->Write(); if (Use["BDT" ]) histBdt ->Write(); if (Use["BDTD" ]) histBdtD ->Write(); if (Use["BDTG" ]) histBdtG ->Write(); if (Use["RuleFit" ]) histRf ->Write(); if (Use["SVM_Gauss" ]) histSVMG ->Write(); if (Use["SVM_Poly" ]) histSVMP ->Write(); if (Use["SVM_Lin" ]) histSVML ->Write(); if (Use["FDA_MT" ]) histFDAMT ->Write(); if (Use["FDA_GA" ]) histFDAGA ->Write(); if (Use["Category" ]) histCat ->Write(); if (Use["Plugin" ]) histPBdt ->Write(); higgsmass_in->Write(); higgsmass_out->Write(); // Write also error and significance histos if (Use["PDEFoam"]) { histPDEFoam->Write(); histPDEFoamErr->Write(); histPDEFoamSig->Write(); } // Write also probability hists if (Use["Fisher"]) { if (probHistFi != 0) probHistFi->Write(); if (rarityHistFi != 0) rarityHistFi->Write(); } target->Close(); std::cout << "--- Created root file: \"TMVApp_Sig.root\" containing the MVA output histograms" << std::endl; delete reader; TFile *file_in = new TFile("/tmp/gbillis/post_TMVA_wrong_inpeak.root","RECREATE"); file_in->cd(); postTMVA_inpeak->Write(); file_in->Close(); TFile *file_out = new TFile("/tmp/gbillis/post_TMVA_wrong_outpeak.root","RECREATE"); file_out->cd(); postTMVA_outpeak->Write(); file_out->Close(); TFile *file1 = new TFile("/tmp/gbillis/TMVA_prob_wrong_inpeak.root","RECREATE"); file1->cd(); TMVA_prob_inpeak->Write(); file1->Close(); TFile *file2 = new TFile("/tmp/gbillis/TMVA_prob_wrong_outpeak.root","RECREATE"); file2->cd(); TMVA_prob_outpeak->Write(); file2->Close(); std::cout << "==> TMVAClassificationApplication is done!" << std::endl << std::endl; } int main( int argc, char** argv ) { TString methodList; for (int i=1; i