//Apply classifier with TMVA //using namespace TMVA::Experimental; void apply() { TFile* inputFile = new TFile("sig_train.root"); TTree* data = (TTree*)inputFile->Get("b0"); //the name of the output file which will contain the BDT response of each event: TFile *target = new TFile("mva_output.root","RECREATE" ); TTree *tree = new TTree("tree","calibrated tree"); TMVA::Reader *reader = new TMVA::Reader("!Color:!Silent"); Float_t useCMSFrame__bocosTheta__bc, cosTBTO, cosTBz, KSFWVariables__boet__bc, KSFWVariables__bohso00__bc, KSFWVariables__bohso02__bc, KSFWVariables__bohso04__bc, KSFWVariables__bohso10__bc, KSFWVariables__bohso12__bc, KSFWVariables__bohso14__bc, KSFWVariables__bohso20__bc, KSFWVariables__bohso22__bc, KSFWVariables__bohso24__bc, KSFWVariables__bohoo0__bc, KSFWVariables__bohoo1__bc, KSFWVariables__bohoo2__bc, KSFWVariables__bohoo3__bc, KSFWVariables__bohoo4__bc; reader->AddVariable( "useCMSFrame__bocosTheta__bc", &useCMSFrame__bocosTheta__bc ); reader->AddVariable( "cosTBTO", &cosTBTO ); reader->AddVariable( "cosTBz", &cosTBz ); reader->AddVariable( "KSFWVariables__boet__bc", &KSFWVariables__boet__bc ); //reader->AddVariable( "KSFWVariables__bohso00__bc", &KSFWVariables__bohso00__bc); reader->AddVariable( "KSFWVariables__bohso02__bc", &KSFWVariables__bohso02__bc); reader->AddVariable( "KSFWVariables__bohso04__bc", &KSFWVariables__bohso04__bc); reader->AddVariable( "KSFWVariables__bohso10__bc", &KSFWVariables__bohso10__bc); reader->AddVariable( "KSFWVariables__bohso12__bc", &KSFWVariables__bohso12__bc); reader->AddVariable( "KSFWVariables__bohso14__bc", &KSFWVariables__bohso14__bc); reader->AddVariable( "KSFWVariables__bohso20__bc", &KSFWVariables__bohso20__bc); reader->AddVariable( "KSFWVariables__bohso22__bc", &KSFWVariables__bohso22__bc); reader->AddVariable( "KSFWVariables__bohso24__bc", &KSFWVariables__bohso24__bc); //reader->AddVariable( "KSFWVariables__bohoo0__bc", &KSFWVariables__bohoo0__bc); //reader->AddVariable( "KSFWVariables__bohoo1__bc", &KSFWVariables__bohoo1__bc); //reader->AddVariable( "KSFWVariables__bohoo2__bc", &KSFWVariables__bohoo2__bc); //reader->AddVariable( "KSFWVariables__bohoo3__bc", &KSFWVariables__bohoo3__bc); //reader->AddVariable( "KSFWVariables__bohoo4__bc", &KSFWVariables__bohoo4__bc); reader->BookMVA( "My BDT", "dataset/weights/TMVAClassification_BDT.weights.xml"); reader->BookMVA( "Fisher discriminant","dataset/weights/TMVAClassification_Fisher.weights.xml"); //RReader *reader; //RReader reader( "My BDT", "dataset/weights/TMVAClassification_BDT.weights.xml"); //auto variables = reader.GetVariableNames(); Double_t fbdt; data->SetBranchAddress( "extraInfo__boFastBDT__bc", &fbdt); tree->Branch("extraInfo__boFastBDT__bc", &fbdt); // Book example histogram for probability (the other methods are done similarly) TH1F *probHistFi(0), *rarityHistFi(0); probHistFi = new TH1F( "MVA_BDT_Proba", "MVA_BDT_Proba", 100, 0, 1 ); rarityHistFi = new TH1F( "MVA_BDT_Rarity", "MVA_BDT_Rarity", 100, 0, 1 ); // Add a branch to store the BDT response of events: Float_t BDT_response; tree->Branch("BDT_response",&BDT_response); // ------- start your event loop for (Long64_t ievt=0; ievtGetEntries(); ++ievt) { data->GetEntry(ievt); BDT_response=reader->EvaluateMVA("My BDT"); //double fisher = reader->EvaluateMVA("Fisher discriminant"); probHistFi->Fill( reader->GetProba ( "My BDT" ) ); TMVA::MethodBDT * methodbase = dynamic_cast(reader->FindMVA("My BDT")); Double_t pdf = reader->EvaluateMVA( "My BDT" ); rarityHistFi->Fill( methodbase->GetRarity( pdf, TMVA::Types::kSignal ) ); tree->Fill(); } tree->Write(); if (probHistFi != 0) probHistFi->Write(); if (rarityHistFi != 0) rarityHistFi->Write(); //target->Close(); delete reader; inputFile->Close(); }