//Apply classifier with TMVA //using namespace TMVA::Experimental; void apply() { TFile* inputFile = new TFile("/home/shubhangi/work/mc14/CS_transform/sig_bdt.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_sigoutput.root","RECREATE" ); TTree *tree = new TTree("tree","calibrated tree"); //TMVA::Reader *reader = new TMVA::Reader("!Color:!Silent"); std::vector predictWithFloat(std::string method); TMVA::Reader *reader = new TMVA::Reader("!Color:!Silent"); double useCMSFrame, 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, fbdt; float cosTheta, cosTBTO_t, cosTBz_t, et, hso00, hso02, hso04, hso10, hso12, hso14, hso20, hso22, hso24, hoo0, hoo1, hoo2, hoo3, hoo4; data->SetBranchAddress( "extraInfo__boFastBDT__bc", &fbdt); data->SetBranchAddress( "useCMSFrame__bocosTheta__bc", &useCMSFrame); data->SetBranchAddress( "cosTBTO", &cosTBTO); data->SetBranchAddress( "cosTBz", &cosTBz ); data->SetBranchAddress( "KSFWVariables__boet__bc", &KSFWVariables__boet__bc); data->SetBranchAddress( "KSFWVariables__bohso00__bc", &KSFWVariables__bohso00__bc); data->SetBranchAddress( "KSFWVariables__bohso02__bc", &KSFWVariables__bohso02__bc); data->SetBranchAddress( "KSFWVariables__bohso04__bc", &KSFWVariables__bohso04__bc); data->SetBranchAddress( "KSFWVariables__bohso10__bc", &KSFWVariables__bohso10__bc); data->SetBranchAddress( "KSFWVariables__bohso12__bc", &KSFWVariables__bohso12__bc); data->SetBranchAddress( "KSFWVariables__bohso14__bc", &KSFWVariables__bohso14__bc); data->SetBranchAddress( "KSFWVariables__bohso20__bc", &KSFWVariables__bohso20__bc); data->SetBranchAddress( "KSFWVariables__bohso22__bc", &KSFWVariables__bohso22__bc); data->SetBranchAddress( "KSFWVariables__bohso24__bc", &KSFWVariables__bohso24__bc); data->SetBranchAddress( "KSFWVariables__bohoo0__bc", &KSFWVariables__bohoo0__bc); data->SetBranchAddress( "KSFWVariables__bohoo1__bc", &KSFWVariables__bohoo1__bc); data->SetBranchAddress( "KSFWVariables__bohoo2__bc", &KSFWVariables__bohoo2__bc); data->SetBranchAddress( "KSFWVariables__bohoo3__bc", &KSFWVariables__bohoo3__bc); data->SetBranchAddress( "KSFWVariables__bohoo4__bc", &KSFWVariables__bohoo4__bc); reader->AddVariable( "useCMSFrame__bocosTheta__bc", &cosTheta ); reader->AddVariable( "cosTBTO", &cosTBTO_t ); reader->AddVariable( "cosTBz", &cosTBz_t ); reader->AddVariable( "KSFWVariables__boet__bc", &et ); reader->AddVariable( "KSFWVariables__bohso00__bc", &hso00); reader->AddVariable( "KSFWVariables__bohso02__bc", &hso02); reader->AddVariable( "KSFWVariables__bohso04__bc", &hso04); reader->AddVariable( "KSFWVariables__bohso10__bc", &hso10); reader->AddVariable( "KSFWVariables__bohso12__bc", &hso12); reader->AddVariable( "KSFWVariables__bohso14__bc", &hso14); reader->AddVariable( "KSFWVariables__bohso20__bc", &hso20); reader->AddVariable( "KSFWVariables__bohso22__bc", &hso22); reader->AddVariable( "KSFWVariables__bohso24__bc", &hso24); reader->AddVariable( "KSFWVariables__bohoo0__bc", &hoo0); reader->AddVariable( "KSFWVariables__bohoo1__bc", &hoo1); reader->AddVariable( "KSFWVariables__bohoo2__bc", &hoo2); reader->AddVariable( "KSFWVariables__bohoo3__bc", &hoo3); reader->AddVariable( "KSFWVariables__bohoo4__bc", &hoo4); //reader->BookMVA( "My BDT", "dataset/weights/TMVAClassification_BDT.weights.xml"); reader->BookMVA( "My BDT", "TMVA/weights/TMVA_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 BDT_response; tree->Branch("BDT_response",&BDT_response); // ------- start your event loop for (Long64_t ievt=0; ievtGetEntries(); ++ievt) { data->GetEntry(ievt); cosTheta = useCMSFrame; cosTBTO_t = cosTBTO; cosTBz_t = cosTBz; et = KSFWVariables__boet__bc; hso00 = KSFWVariables__bohso00__bc; hso02 = KSFWVariables__bohso02__bc; hso04 = KSFWVariables__bohso04__bc; hso10 = KSFWVariables__bohso10__bc; hso12 = KSFWVariables__bohso12__bc; hso14 = KSFWVariables__bohso14__bc; hso20 = KSFWVariables__bohso20__bc; hso22 = KSFWVariables__bohso22__bc; hso24 = KSFWVariables__bohso24__bc; hoo0 = KSFWVariables__bohoo0__bc; hoo1 = KSFWVariables__bohoo1__bc; hoo2 = KSFWVariables__bohoo2__bc; hoo3 = KSFWVariables__bohoo3__bc; hoo4 = KSFWVariables__bohoo4__bc; 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 ) ); //float rarity; //tree->Branch("rarityHistFi",&rarity); tree->Fill(); } tree->Write(); if (probHistFi != 0) probHistFi->Write(); if (rarityHistFi != 0) rarityHistFi->Write(); //target->Close(); delete reader; inputFile->Close(); }