本文整理汇总了C++中tmva::Reader::AddSpectator方法的典型用法代码示例。如果您正苦于以下问题:C++ Reader::AddSpectator方法的具体用法?C++ Reader::AddSpectator怎么用?C++ Reader::AddSpectator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmva::Reader
的用法示例。
在下文中一共展示了Reader::AddSpectator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bookReader
int reader_wrapper::bookReader( TString xml_file_name) {
m_reader = new TMVA::Reader("!Color:Silent");
for (auto var : m_spectators) {
m_reader->AddSpectator(var.formula, &var.value);
}
for (auto& var : m_variables) {
m_reader->AddVariable(var.formula, &var.value);
}
m_reader->BookMVA( m_methodName, xml_file_name );
return 0;
}
示例2: TMVAReader
//.........这里部分代码省略.........
TMVA::Reader *reader = new TMVA::Reader( "!Color" );
reader->AddVariable("TagVarCSV_vertexCategory",&TagVarCSV_vertexCategory);
reader->AddVariable("TagVarCSV_jetNTracks",&TagVarCSV_jetNTracks);
//reader->AddVariable("TagVarCSV_trackSip2dSig_0",&TagVarCSV_trackSip2dSig_0);
//reader->AddVariable("TagVarCSV_trackSip2dSig_1",&TagVarCSV_trackSip2dSig_1);
//reader->AddVariable("TagVarCSV_trackSip2dSig_2",&TagVarCSV_trackSip2dSig_2);
//reader->AddVariable("TagVarCSV_trackSip2dSig_3",&TagVarCSV_trackSip2dSig_3);
reader->AddVariable("TagVarCSV_trackSip3dSig_0",&TagVarCSV_trackSip3dSig_0);
reader->AddVariable("TagVarCSV_trackSip3dSig_1",&TagVarCSV_trackSip3dSig_1);
reader->AddVariable("TagVarCSV_trackSip3dSig_2",&TagVarCSV_trackSip3dSig_2);
reader->AddVariable("TagVarCSV_trackSip3dSig_3",&TagVarCSV_trackSip3dSig_3);
//reader->AddVariable("TagVarCSV_trackPtRel_0",&TagVarCSV_trackPtRel_0);
//reader->AddVariable("TagVarCSV_trackPtRel_1",&TagVarCSV_trackPtRel_1);
//reader->AddVariable("TagVarCSV_trackPtRel_2",&TagVarCSV_trackPtRel_2);
//reader->AddVariable("TagVarCSV_trackPtRel_3",&TagVarCSV_trackPtRel_3);
reader->AddVariable("TagVarCSV_trackSip2dSigAboveCharm",&TagVarCSV_trackSip2dSigAboveCharm);
//reader->AddVariable("TagVarCSV_trackSip3dSigAboveCharm",&TagVarCSV_trackSip3dSigAboveCharm);
//reader->AddVariable("TagVarCSV_trackSumJetEtRatio",&TagVarCSV_trackSumJetEtRatio);
//reader->AddVariable("TagVarCSV_trackSumJetDeltaR",&TagVarCSV_trackSumJetDeltaR);
reader->AddVariable("TagVarCSV_jetNTracksEtaRel",&TagVarCSV_jetNTracksEtaRel);
reader->AddVariable("TagVarCSV_trackEtaRel_0",&TagVarCSV_trackEtaRel_0);
reader->AddVariable("TagVarCSV_trackEtaRel_1",&TagVarCSV_trackEtaRel_1);
reader->AddVariable("TagVarCSV_trackEtaRel_2",&TagVarCSV_trackEtaRel_2);
reader->AddVariable("TagVarCSV_jetNSecondaryVertices",&TagVarCSV_jetNSecondaryVertices);
reader->AddVariable("TagVarCSV_vertexMass",&TagVarCSV_vertexMass);
reader->AddVariable("TagVarCSV_vertexNTracks",&TagVarCSV_vertexNTracks);
reader->AddVariable("TagVarCSV_vertexEnergyRatio",&TagVarCSV_vertexEnergyRatio);
reader->AddVariable("TagVarCSV_vertexJetDeltaR",&TagVarCSV_vertexJetDeltaR);
reader->AddVariable("TagVarCSV_flightDistance2dSig",&TagVarCSV_flightDistance2dSig);
//reader->AddVariable("TagVarCSV_flightDistance3dSig",&TagVarCSV_flightDistance3dSig);
reader->AddSpectator("Jet_pt", &Jet_pt);
reader->AddSpectator("Jet_eta", &Jet_eta);
reader->AddSpectator("Jet_phi", &Jet_phi);
reader->AddSpectator("Jet_mass", &Jet_mass);
reader->AddSpectator("Jet_massGroomed", &Jet_massGroomed);
reader->AddSpectator("Jet_flavour", &Jet_flavour);
reader->AddSpectator("Jet_nbHadrons", &Jet_nbHadrons);
reader->AddSpectator("Jet_JP", &Jet_JP);
reader->AddSpectator("Jet_JBP", &Jet_JBP);
reader->AddSpectator("Jet_CSV", &Jet_CSV);
reader->AddSpectator("Jet_CSVIVF", &Jet_CSVIVF);
reader->AddSpectator("Jet_tau1", &Jet_tau1);
reader->AddSpectator("Jet_tau2", &Jet_tau2);
reader->AddSpectator("SubJet1_CSVIVF", &SubJet1_CSVIVF);
reader->AddSpectator("SubJet2_CSVIVF", &SubJet2_CSVIVF);
reader->BookMVA( "BDTG_T1000D3_fat_BBvsQCD method", "weights/TMVATrainer_BDTG_T1000D3_fat_BBvsQCD.weights.xml" );
// histograms
TH1F* hBDTGDiscSig = new TH1F("hBDTGDiscSig","",1000,-5,5);
TH1F* hBDTGDiscBkg = new TH1F("hBDTGDiscBkg","",1000,-5,5);
TH1F* hFatCSVIVFDiscSig = new TH1F("hFatCSVIVFDiscSig","",1000,-5,5);
TH1F* hFatCSVIVFDiscBkg = new TH1F("hFatCSVIVFDiscBkg","",1000,-5,5);
TH1F* hSubCSVIVFDiscSig = new TH1F("hSubCSVIVFDiscSig","",1000,-5,5);
TH1F* hSubCSVIVFDiscBkg = new TH1F("hSubCSVIVFDiscBkg","",1000,-5,5);
hBDTGDiscSig->GetXaxis()->SetTitle("BDTG Discriminant");
hBDTGDiscBkg->GetXaxis()->SetTitle("BDTG Discriminant");
hFatCSVIVFDiscSig->GetXaxis()->SetTitle("CSV Discriminant");
示例3: TMVARegressionApplication
void TMVARegressionApplication( int wMs,int wM, string st,string st2,string option="",TString myMethodList = "" )
{
//---------------------------------------------------------------
// This loads the library
TMVA::Tools::Instance();
// Default MVA methods to be trained + tested
std::map<std::string,int> Use;
// --- Mutidimensional likelihood and Nearest-Neighbour methods
Use["PDERS"] = 0;
Use["PDEFoam"] = 0;
Use["KNN"] = 0;
//
// --- Linear Discriminant Analysis
Use["LD"] = 0;
//
// --- Function Discriminant analysis
Use["FDA_GA"] = 0;
Use["FDA_MC"] = 0;
Use["FDA_MT"] = 0;
Use["FDA_GAMT"] = 0;
//
// --- Neural Network
Use["MLP"] = 0;
//
// --- Support Vector Machine
Use["SVM"] = 0;
//
// --- Boosted Decision Trees
Use["BDT"] = 0;
Use["BDTG"] = 1;
// ---------------------------------------------------------------
std::cout << std::endl;
std::cout << "==> Start TMVARegressionApplication" << std::endl;
// Select methods (don't look at this code - not of interest)
if (myMethodList != "") {
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' );
for (UInt_t i=0; i<mlist.size(); i++) {
std::string regMethod(mlist[i]);
if (Use.find(regMethod) == Use.end()) {
std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl;
for (std::map<std::string,int>::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 var1, var2;
//reader->AddVariable( "var1", &var1 );
//reader->AddVariable( "var2", &var2 );
Float_t pt_AK8MatchedToHbb,eta_AK8MatchedToHbb,nsv_AK8MatchedToHbb,sv0mass_AK8MatchedToHbb,sv1mass_AK8MatchedToHbb,
nch_AK8MatchedToHbb,nmu_AK8MatchedToHbb,nel_AK8MatchedToHbb,muenfr_AK8MatchedToHbb,emenfr_AK8MatchedToHbb;
reader->AddVariable( "pt_AK8MatchedToHbb", &pt_AK8MatchedToHbb );
reader->AddVariable( "eta_AK8MatchedToHbb", &eta_AK8MatchedToHbb );
reader->AddVariable( "nsv_AK8MatchedToHbb", &nsv_AK8MatchedToHbb );
reader->AddVariable( "sv0mass_AK8MatchedToHbb", &sv0mass_AK8MatchedToHbb );
reader->AddVariable( "sv1mass_AK8MatchedToHbb", &sv1mass_AK8MatchedToHbb );
reader->AddVariable( "nch_AK8MatchedToHbb", &nch_AK8MatchedToHbb );
reader->AddVariable( "nmu_AK8MatchedToHbb", &nmu_AK8MatchedToHbb );
reader->AddVariable( "nel_AK8MatchedToHbb", &nel_AK8MatchedToHbb );
reader->AddVariable( "muenfr_AK8MatchedToHbb", &muenfr_AK8MatchedToHbb );
reader->AddVariable( "emenfr_AK8MatchedToHbb", &emenfr_AK8MatchedToHbb );
// Spectator variables declared in the training have to be added to the reader, too
Float_t spec1,spec2;
reader->AddSpectator( "spec1:=n_pv", &spec1 );
reader->AddSpectator( "spec2:=msoftdrop_AK8MatchedToHbb", &spec2 );
// --- Book the MVA methods
TString dir = "weights/";
TString prefix = "TMVARegression";
// Book method(s)
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (it->second) {
TString methodName = it->first + " method";
TString weightfile = dir + prefix + "_" + TString(it->first) + ".weights.xml";
reader->BookMVA( methodName, weightfile );
}
}
TH1* hists[100];
//.........这里部分代码省略.........
示例4: TMVAClassificationApplication
void TMVAClassificationApplication( TString myMethodList = "" )
{
#ifdef __CINT__
gROOT->ProcessLine( ".O0" ); // turn off optimization in CINT
#endif
//---------------------------------------------------------------
// This loads the library
TMVA::Tools::Instance();
// Default MVA methods to be trained + tested
std::map<std::string,int> Use;
Use["MLP"] = 0; // Recommended ANN
Use["BDT"] = 1; // uses Adaptive Boost
std::cout << std::endl;
std::cout << "==> Start TMVAClassificationApplication" << std::endl;
// --- 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 var1, var2;
Float_t var3, var4;
reader->AddVariable( "myvar1 := var1+var2", &var1 );
reader->AddVariable( "myvar2 := var1-var2", &var2 );
reader->AddVariable( "var3", &var3 );
reader->AddVariable( "var4", &var4 );
// Spectator variables declared in the training have to be added to the reader, too
Float_t spec1,spec2;
reader->AddSpectator( "spec1 := var1*2", &spec1 );
reader->AddSpectator( "spec2 := var1*3", &spec2 );
Float_t Category_cat1, Category_cat2, Category_cat3;
if (Use["Category"]){
// Add artificial spectators for distinguishing categories
reader->AddSpectator( "Category_cat1 := var3<=0", &Category_cat1 );
reader->AddSpectator( "Category_cat2 := (var3>0)&&(var4<0)", &Category_cat2 );
reader->AddSpectator( "Category_cat3 := (var3>0)&&(var4>=0)", &Category_cat3 );
}
// --- Book the MVA methods
TString dir = "weights/";
TString prefix = "TMVAClassification";
// Book method(s)
for (std::map<std::string,int>::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 );
}
}
// 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
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
// TMVAreader->AddVariable("dphill", &dphill);
// TMVAreader->AddVariable("mth", &mth);
// TMVAreader->AddVariable("dphillmet", &dphillmet);
// TMVAreader->AddVariable("mpmet", &mpmet);
Float_t input_variables[1000];
// float input_variables[1000];
// TMVAreader->AddVariable("jetpt1", &(input_variables[0]));
// TMVAreader->AddVariable("jetpt2", &(input_variables[1]));
// TMVAreader->AddVariable("mjj", &(input_variables[2]));
// TMVAreader->AddVariable("detajj", &(input_variables[3]));
// TMVAreader->AddVariable("dphilljetjet", &(input_variables[4]));
// TMVAreader->AddVariable("pt1", &(input_variables[5]));
// TMVAreader->AddVariable("pt2", &(input_variables[6]));
// TMVAreader->AddVariable("mll", &(input_variables[7]));
// TMVAreader->AddVariable("dphill", &(input_variables[8]));
// TMVAreader->AddVariable("mth", &(input_variables[9]));
// TMVAreader->AddVariable("dphillmet", &(input_variables[10]));
// TMVAreader->AddVariable("mpmet", &(input_variables[11]));
TMVAreader->AddVariable("jetpt1", &input_variables[0]);
TMVAreader->AddVariable("jetpt2", &input_variables[1]);
TMVAreader->AddVariable("mjj", &input_variables[2]);
TMVAreader->AddVariable("detajj", &input_variables[3]);
TMVAreader->AddVariable("dphilljetjet", &input_variables[4]);
TMVAreader->AddVariable("pt1", &input_variables[5]);
TMVAreader->AddVariable("pt2", &input_variables[6]);
TMVAreader->AddVariable("mll", &input_variables[7]);
TMVAreader->AddVariable("dphill", &input_variables[8]);
TMVAreader->AddVariable("mth", &input_variables[9]);
TMVAreader->AddVariable("dphillmet", &input_variables[10]);
TMVAreader->AddVariable("mpmet", &input_variables[11]);
TMVAreader->AddSpectator("channel", &input_variables[12]);
TString myMethodMassList = Form ("%s",vectorMyMethodMassList.at(iMVAMass).c_str());
TString weightfile = Form ("%s/weights_%s_testVariables/TMVAMulticlass_%s.weights.xml",MVADirectory.c_str(),myMethodMassList.Data(),myMethodList.Data());
std::cout << " myMethodList = " << myMethodList.Data() << std::endl;
std::cout << " weightfile = " << weightfile.Data() << std::endl;
// TString myMethodListBook = Form ("%s",vectorMyMethodList.at(iMVA).c_str());
// TMVAreader->BookMVA( myMethodListBook, weightfile );
TMVAreader->BookMVA( myMethodList, weightfile );
for (int iSample=0; iSample<numberOfSamples; iSample++){
std::cout << " iSample = " << iSample << " :: " << numberOfSamples << std::endl;
file[iSample] -> cd();
Double_t MVA_Value;
TBranch *newBranch;
TString methodName4Tree = Form ("%s_%s_MVAHiggs",myMethodList.Data(),myMethodMassList.Data());
TString methodName4Tree2 = Form ("%s_%s_MVAHiggs/D",myMethodList.Data(),myMethodMassList.Data());
newBranch = cloneTreeJetLepVect[iSample]->Branch(methodName4Tree,&MVA_Value,methodName4Tree2);
// newBranch = treeJetLepVect[iSample]->Branch(methodName4Tree,&MVA_Value,methodName4Tree2);
///==== loop ====
Long64_t nentries = treeJetLepVect[iSample]->GetEntries();
for (Long64_t iEntry = 0; iEntry < nentries; iEntry++){
if((iEntry%1000) == 0) std::cout << ">>>>> analysis::GetEntry " << iEntry << " : " << nentries << std::endl;
示例6: TMVARegressionApplication
void TMVARegressionApplication( TString myMethodList = "" )
{
//---------------------------------------------------------------
// This loads the library
TMVA::Tools::Instance();
// Default MVA methods to be trained + tested
std::map<std::string,int> Use;
// --- Mutidimensional likelihood and Nearest-Neighbour methods
Use["PDERS"] = 0;
Use["PDEFoam"] = 1;
Use["KNN"] = 1;
//
// --- Linear Discriminant Analysis
Use["LD"] = 1;
//
// --- Function Discriminant analysis
Use["FDA_GA"] = 1;
Use["FDA_MC"] = 0;
Use["FDA_MT"] = 0;
Use["FDA_GAMT"] = 0;
//
// --- Neural Network
Use["MLP"] = 1;
Use["DNN_CPU"] = 0;
//
// --- Support Vector Machine
Use["SVM"] = 0;
//
// --- Boosted Decision Trees
Use["BDT"] = 0;
Use["BDTG"] = 1;
// ---------------------------------------------------------------
std::cout << std::endl;
std::cout << "==> Start TMVARegressionApplication" << std::endl;
// Select methods (don't look at this code - not of interest)
if (myMethodList != "") {
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' );
for (UInt_t i=0; i<mlist.size(); i++) {
std::string regMethod(mlist[i]);
if (Use.find(regMethod) == Use.end()) {
std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl;
for (std::map<std::string,int>::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 var1, var2;
reader->AddVariable( "var1", &var1 );
reader->AddVariable( "var2", &var2 );
// Spectator variables declared in the training have to be added to the reader, too
Float_t spec1,spec2;
reader->AddSpectator( "spec1:=var1*2", &spec1 );
reader->AddSpectator( "spec2:=var1*3", &spec2 );
// --- Book the MVA methods
TString dir = "dataset/weights/";
TString prefix = "TMVARegression";
// Book method(s)
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (it->second) {
TString methodName = it->first + " method";
TString weightfile = dir + prefix + "_" + TString(it->first) + ".weights.xml";
reader->BookMVA( methodName, weightfile );
}
}
// Book output histograms
TH1* hists[100];
Int_t nhists = -1;
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
TH1* h = new TH1F( it->first.c_str(), TString(it->first) + " method", 100, -100, 600 );
if (it->second) hists[++nhists] = h;
}
nhists++;
// 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.
//
//.........这里部分代码省略.........
示例7: TMVAClassificationApplication_cc1pcoh_bdt_ver3noveractFFFSI
void TMVAClassificationApplication_cc1pcoh_bdt_ver3noveractFFFSI( TString myMethodList = "", TString fname)
{
#ifdef __CINT__
gROOT->ProcessLine( ".O0" ); // turn off optimization in CINT
#endif
//---------------------------------------------------------------
// This loads the library
TMVA::Tools::Instance();
// Default MVA methods to be trained + tested
std::map<std::string,int> Use;
//
// --- Boosted Decision Trees
Use["BDT"] = 1; // uses Adaptive Boost
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<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' );
for (UInt_t i=0; i<mlist.size(); i++) {
std::string regMethod(mlist[i]);
if (Use.find(regMethod) == Use.end()) {
std::cout << "Method \"" << regMethod
<< "\" not known in TMVA under this name. Choose among the following:" << std::endl;
for (std::map<std::string,int>::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 mumucl, pmucl;
Float_t pang_t, muang_t;
Float_t veract;
Float_t ppe, mupe;
Float_t range, coplanarity;
Float_t opening;//newadd
reader->AddVariable( "mumucl", &mumucl );
reader->AddVariable( "pmucl", &pmucl );
reader->AddVariable( "pang_t", &pang_t );
reader->AddVariable( "muang_t", &muang_t );
//reader->AddVariable( "veract", &veract );
reader->AddVariable( "ppe", &ppe);
reader->AddVariable( "mupe", &mupe);
reader->AddVariable( "range", &range);
reader->AddVariable( "coplanarity", &coplanarity);
reader->AddVariable( "opening", &opening);//newadd
// Spectator variables declared in the training have to be added to the reader, too
Int_t fileIndex, inttype;
Float_t nuE, norm, totcrsne;
reader->AddSpectator( "fileIndex", &fileIndex );
reader->AddSpectator( "nuE", &nuE );
reader->AddSpectator( "inttype", &inttype );
reader->AddSpectator( "norm", &norm );
reader->AddSpectator( "totcrsne", &totcrsne );
reader->AddSpectator( "veract", &veract );
// --- Book the MVA methods
TString dir = "weights/";
TString prefix = "TMVAClassification_ver3noveractFFFSI";//newchange
// Book method(s)
for (std::map<std::string,int>::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 );
}
}
// 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.
//
//.........这里部分代码省略.........
开发者ID:cvson,项目名称:tmvaccohPM,代码行数:101,代码来源:TMVAClassificationApplication_cc1pcoh_bdt_ver3noveractFFFSI.C
示例8: TMVAClassificationApplication
void TMVAClassificationApplication( TString weightFile = "TMVAClassificationPtOrd_qqH115vsWZttQCD_Cuts.weights.xml",
Double_t effS_ = 0.5 )
{
TMVA::Tools::Instance();
TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );
Float_t pt1, pt2;
Float_t Deta, Mjj;
Float_t eta1,eta2;
reader->AddVariable( "pt1", &pt1);
reader->AddVariable( "pt2", &pt2);
reader->AddVariable( "Deta",&Deta);
reader->AddVariable( "Mjj", &Mjj);
reader->AddSpectator("eta1",&eta1);
reader->AddSpectator("eta2",&eta2);
reader->BookMVA( "Cuts", TString("weights/")+weightFile );
// mu+tau iso, OS, Mt<40
TString fSignalName = "/data_CMS/cms/lbianchini/VbfJetsStudy/looseSelection/nTupleVBFH115-PU-L.root";
//TString fSignalName = "/data_CMS/cms/lbianchini/VbfJetsStudy/nTupleVbf.root";
// mu+tau iso, OS, Mt<40
//TString fBackgroundNameDYJets = "/data_CMS/cms/lbianchini/VbfJetsStudy/looseSelection/nTupleDYJets-madgraph-50-PU-L.root";
TString fBackgroundNameDYJets = "/data_CMS/cms/lbianchini/VbfJetsStudy/nTupleZJets.root";
// Mt<40
TString fBackgroundNameWJets = "/data_CMS/cms/lbianchini/VbfJetsStudy/looseSelection/nTupleWJets-madgraph-PU-L.root";
// Mt<40
TString fBackgroundNameQCD = "/data_CMS/cms/lbianchini/VbfJetsStudy/looseSelection/nTupleQCD-pythia-PU-L.root";
// Mt<40
TString fBackgroundNameTTbar = "/data_CMS/cms/lbianchini/VbfJetsStudy/looseSelection/nTupleTT-madgraph-PU-L.root";
TFile *fSignal(0);
TFile *fBackgroundDYJets(0);
TFile *fBackgroundWJets(0);
TFile *fBackgroundQCD(0);
TFile *fBackgroundTTbar(0);
fSignal = TFile::Open( fSignalName );
fBackgroundDYJets = TFile::Open( fBackgroundNameDYJets );
fBackgroundWJets = TFile::Open( fBackgroundNameWJets );
fBackgroundQCD = TFile::Open( fBackgroundNameQCD );
fBackgroundTTbar = TFile::Open( fBackgroundNameTTbar );
if(!fSignal || !fBackgroundDYJets || !fBackgroundWJets || !fBackgroundQCD || !fBackgroundTTbar) {
std::cout << "ERROR: could not open files" << std::endl;
exit(1);
}
TString tree = "outTreePtOrd";
TTree *signal = (TTree*)fSignal->Get(tree);
TTree *backgroundDYJets = (TTree*)fBackgroundDYJets->Get(tree);
TTree *backgroundWJets = (TTree*)fBackgroundWJets->Get(tree);
TTree *backgroundQCD = (TTree*)fBackgroundQCD->Get(tree);
TTree *backgroundTTbar = (TTree*)fBackgroundTTbar->Get(tree);
TCut mycuts = "pt1>0 && abs(eta1*eta2)/eta1/eta2<0";
TCut mycutb = "pt1>0 && abs(eta1*eta2)/eta1/eta2<0";
std::map<std::string,TTree*> tMap;
tMap["qqH115"]=signal;
tMap["Zjets"]=backgroundDYJets;
tMap["Wjets"]=backgroundWJets;
tMap["QCD"]=backgroundQCD;
tMap["TTbar"]=backgroundTTbar;
Double_t pt1_, pt2_;
Double_t Deta_, Mjj_;
for(std::map<std::string,TTree*>::iterator it = tMap.begin(); it != tMap.end(); it++) {
TFile* dummy = new TFile("dummy.root","RECREATE");
TTree* currentTree = (TTree*)(it->second)->CopyTree(mycuts);
Int_t counter = 0;
currentTree->SetBranchAddress( "pt1", &pt1_ );
currentTree->SetBranchAddress( "pt2", &pt2_ );
currentTree->SetBranchAddress( "Deta",&Deta_ );
currentTree->SetBranchAddress( "Mjj", &Mjj_ );
for (Long64_t ievt=0; ievt<currentTree->GetEntries(); ievt++) {
currentTree->GetEntry(ievt);
pt1 = pt1_;
pt2 = pt2_;
Deta = Deta_;
Mjj = Mjj_;
if (ievt%1000000 == 0) {
std::cout << "--- ... Processing event: " << ievt << std::endl;
//cout << pt1 << ", " << pt2 << ", " << Deta << ", " << Mjj << endl;
}
if(reader->EvaluateMVA( "Cuts", effS_ )) counter++;
//.........这里部分代码省略.........
示例9: ZTMVAClassificationApplication
//.........这里部分代码省略.........
for (UInt_t i=0; i<mlist.size(); i++) {
std::string regMethod(mlist[i]);
if (Use.find(regMethod) == Use.end()) {
std::cout << "Method \"" << regMethod
<< "\" not known in TMVA under this name. Choose among the following:" << std::endl;
for (std::map<std::string,int>::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" );
Float_t B_s0_ln_FDCHI2; reader->AddVariable("B_s0_ln_FDCHI2", &B_s0_ln_FDCHI2 );
Float_t B_s0_ln_IPCHI2; reader->AddVariable("B_s0_ln_IPCHI2", &B_s0_ln_IPCHI2 );
Float_t B_s0_ln_EVCHI2; reader->AddVariable("B_s0_ln_EVCHI2", &B_s0_ln_EVCHI2 );
Float_t B_s0_PT_fiveGeV;reader->AddVariable("B_s0_PT_fiveGeV",&B_s0_PT_fiveGeV);
Float_t B_s0_Eta; reader->AddVariable("B_s0_Eta", &B_s0_Eta );
Float_t minK_PT_GeV; reader->AddVariable("minK_PT_GeV", &minK_PT_GeV );
Float_t minK_ln_IPCHI2; reader->AddVariable("minK_ln_IPCHI2", &minK_ln_IPCHI2 );
Float_t Category_cat1, Category_cat2, Category_cat3;
if (Use["Category"]){
// Add artificial spectators for distinguishing categories
reader->AddSpectator( "Category_cat1 := var3<=0", &Category_cat1 );
reader->AddSpectator( "Category_cat2 := (var3>0)&&(var4<0)", &Category_cat2 );
reader->AddSpectator( "Category_cat3 := (var3>0)&&(var4>=0)", &Category_cat3 );
}
// --- Book the MVA methods
TString dir = "weights/";
TString prefix = "TMVAClassification";
// Book method(s)
for (std::map<std::string,int>::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 );
}
}
// 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 );
示例10: TMVAClassificationApplicationLambda
//.........这里部分代码省略.........
}
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 var1, var2;
//Float_t var3, var4;
Float_t la_agl, la_dlos, la_dau1_dzos, la_dau1_dxyos, la_dau2_dzos, la_dau2_dxyos;
Float_t la_vtxChi2, la_dau1_nhit, la_dau2_nhit;
reader->AddVariable( "la_agl", &la_agl );
reader->AddVariable( "la_dlos", &la_dlos );
reader->AddVariable( "la_dau1_dzos", &la_dau1_dzos );
reader->AddVariable( "la_dau2_dzos",&la_dau2_dzos);
reader->AddVariable( "la_dau1_dxyos", &la_dau1_dxyos );
reader->AddVariable( "la_dau2_dxyos",&la_dau2_dxyos);
reader->AddVariable( "la_vtxChi2",&la_vtxChi2);
reader->AddVariable( "la_dau1_nhit",&la_dau1_nhit);
reader->AddVariable( "la_dau2_nhit",&la_dau2_nhit);
// Spectator variables declared in the training have to be added to the reader, too
Float_t la_mass;
reader->AddSpectator( "la_mass", &la_mass );
//reader->AddSpectator( "spec2 := var1*3", &spec2 );
/*
Float_t Category_cat1, Category_cat2, Category_cat3;
if (Use["Category"]){
// Add artificial spectators for distinguishing categories
reader->AddSpectator( "Category_cat1 := var3<=0", &Category_cat1 );
reader->AddSpectator( "Category_cat2 := (var3>0)&&(var4<0)", &Category_cat2 );
reader->AddSpectator( "Category_cat3 := (var3>0)&&(var4>=0)", &Category_cat3 );
}
*/
// --- Book the MVA methods
TString dir = "weights/";
TString prefix = "TMVAClassification";
// Book method(s)
for (std::map<std::string,int>::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 );
}
}
// 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);
示例11: cutFlowStudyMu
void cutFlowStudyMu( TString weightFile = "TMVAClassificationPtOrd_qqH115vsWZttQCD_Cuts.weights.xml",
Double_t effS_ = 0.3)
{
ofstream out("cutFlow-MuTauStream.txt");
out.precision(4);
TMVA::Tools::Instance();
TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );
Float_t pt1, pt2;
Float_t Deta, Mjj;
Float_t eta1,eta2;
reader->AddVariable( "pt1", &pt1);
reader->AddVariable( "pt2", &pt2);
reader->AddVariable( "Deta",&Deta);
reader->AddVariable( "Mjj", &Mjj);
reader->AddSpectator("eta1",&eta1);
reader->AddSpectator("eta2",&eta2);
reader->BookMVA( "Cuts", TString("/home/llr/cms/lbianchini/CMSSW_3_9_9/src/Bianchi/TauTauStudies/test/Macro/weights/")+weightFile );
TFile *fFullSignalVBF = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_VBFH115-Mu-powheg-PUS1.root","READ");
TFile *fFullSignalGGH = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_GGFH115-Mu-powheg-PUS1.root","READ");
TFile *fFullBackgroundDYTauTau = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_DYToTauTau-Mu-20-PUS1.root","READ");
TFile *fFullBackgroundDYMuMu = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_DYToMuMu-20-PUS1.root","READ");
TFile *fFullBackgroundWJets = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_WJets-Mu-madgraph-PUS1.root","READ");
TFile *fFullBackgroundQCD = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_QCDmu.root","READ");
TFile *fFullBackgroundTTbar = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_TTJets-Mu-madgraph-PUS1.root","READ");
TFile *fFullBackgroundDiBoson = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011/treeMuTauStream_DiBoson-Mu.root","READ");
// OpenNTuples
TString fSignalNameVBF = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleVBFH115-Mu-powheg-PUS1_Open_MuTauStream.root";
TString fSignalNameGGH = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleGGFH115-Mu-powheg-PUS1_Open_MuTauStream.root";
TString fBackgroundNameDYTauTau = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleDYToTauTau-Mu-20-PUS1_Open_MuTauStream.root";
TString fBackgroundNameDYMuMu = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleDYToMuMu-20-PUS1_Open_MuTauStream.root";
TString fBackgroundNameWJets = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleWJets-Mu-madgraph-PUS1_Open_MuTauStream.root";
TString fBackgroundNameQCD = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleQCDmu_Open_MuTauStream.root";
TString fBackgroundNameTTbar = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleTTJets-Mu-madgraph-PUS1_Open_MuTauStream.root";
TString fBackgroundNameDiBoson = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011/v2/nTupleDiBoson-Mu_Open_MuTauStream.root";
TFile *fSignalVBF(0);
TFile *fSignalGGH(0);
TFile *fBackgroundDYTauTau(0);
TFile *fBackgroundDYMuMu(0);
TFile *fBackgroundWJets(0);
TFile *fBackgroundQCD(0);
TFile *fBackgroundTTbar(0);
TFile *fBackgroundDiBoson(0);
fSignalVBF = TFile::Open( fSignalNameVBF );
fSignalGGH = TFile::Open( fSignalNameGGH );
fBackgroundDYTauTau = TFile::Open( fBackgroundNameDYTauTau );
fBackgroundDYMuMu = TFile::Open( fBackgroundNameDYMuMu );
fBackgroundWJets = TFile::Open( fBackgroundNameWJets );
fBackgroundQCD = TFile::Open( fBackgroundNameQCD );
fBackgroundTTbar = TFile::Open( fBackgroundNameTTbar );
fBackgroundDiBoson = TFile::Open( fBackgroundNameDiBoson );
if(!fSignalVBF || !fBackgroundDYTauTau || !fBackgroundWJets || !fBackgroundQCD || !fBackgroundTTbar ||
!fSignalGGH || !fBackgroundDYMuMu || !fBackgroundDiBoson ){
std::cout << "ERROR: could not open files" << std::endl;
exit(1);
}
TString tree = "outTreePtOrd";
TTree *signalVBF = (TTree*)fSignalVBF->Get(tree);
TTree *signalGGH = (TTree*)fSignalGGH->Get(tree);
TTree *backgroundDYTauTau = (TTree*)fBackgroundDYTauTau->Get(tree);
TTree *backgroundDYMuMu = (TTree*)fBackgroundDYMuMu->Get(tree);
TTree *backgroundWJets = (TTree*)fBackgroundWJets->Get(tree);
TTree *backgroundQCD = (TTree*)fBackgroundQCD->Get(tree);
TTree *backgroundTTbar = (TTree*)fBackgroundTTbar->Get(tree);
TTree *backgroundDiBoson = (TTree*)fBackgroundDiBoson->Get(tree);
// here I define the map between a sample name and its tree
std::map<std::string,TTree*> tMap;
tMap["ggH115"]=signalGGH;
tMap["qqH115"]=signalVBF;
tMap["Ztautau"]=backgroundDYTauTau;
tMap["Zmumu"]=backgroundDYMuMu;
tMap["Wjets"]=backgroundWJets;
tMap["QCD"]=backgroundQCD;
tMap["TTbar"]=backgroundTTbar;
tMap["DiBoson"]=backgroundDiBoson;
std::map<std::string,TTree*>::iterator jt;
Float_t pt1_, pt2_;
Float_t Deta_, Mjj_;
Float_t Dphi,diTauSVFitPt,diTauSVFitEta,diTauVisMass,diTauSVFitMass,ptL1,ptL2,etaL1,etaL2,diTauCharge,MtLeg1,numPV,combRelIsoLeg1,sampleWeight,ptVeto,HLT;
Int_t tightestHPSWP;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// here I choose the order in the stack
std::vector<string> samples;
//.........这里部分代码省略.........
示例12: TMVAClassificationApplication
void TMVAClassificationApplication( TString myMethodList = "" )
{
#ifdef __CINT__
gROOT->ProcessLine( ".O0" ); // turn off optimization in CINT
#endif
//---------------------------------------------------------------
// This loads the library
TMVA::Tools::Instance();
// set verbosity
//TMVA::Tools::Instance().Log().SetMinType(kINFO);
// Default MVA methods to be trained + tested
std::map<std::string,int> Use;
Use["BDT"] = 1; // uses Adaptive Boost
Use["Category"] = 1;
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<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' );
for (UInt_t i=0; i<mlist.size(); i++) {
std::string regMethod(mlist[i]);
if (Use.find(regMethod) == Use.end()) {
std::cout << "Method \"" << regMethod
<< "\" not known in TMVA under this name. Choose among the following:" << std::endl;
for (std::map<std::string,int>::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" );
reader->SetMsgType(kINFO);
// CMS STATS:
//
// 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 met;
Float_t HT;
Float_t minMLB;
Float_t leptonJetsMETSum;
reader->AddVariable( "met", &met );
reader->AddVariable( "HT", &HT );
reader->AddVariable( "minMLB", &minMLB );
reader->AddVariable( "leptonJetsMETSum", &leptonJetsMETSum );
// CMS STATS:
// *** VERY IMPORTANT! ***
// TMVA notoriously has problems with integer and other non-float branches.
// Better not to use them at all and convert them to Float_t. If you happen
// to have integer branches that you need, as in this example, you should create
// corresponding float spectator variables and assign them in the event loop.
//
// Spectator variables declared in the training have to be added to the reader, too
//
// Note that the corresponding branches are integer, so we create floats too!
Int_t nBTag;
Int_t nJets;
Int_t nLeptons;
Int_t isMuon1;
Int_t isMuon2;
Int_t isMuon3;
Int_t isMuon4;
Float_t nBTagFloat;
Float_t nJetsFloat;
Float_t nLeptonsFloat;
Float_t isMuon1Float;
Float_t isMuon2Float;
Float_t isMuon3Float;
Float_t isMuon4Float;
Float_t leptonSumMass;
reader->AddSpectator( "nBTag", &nBTagFloat );
reader->AddSpectator( "nJets", &nJetsFloat );
reader->AddSpectator( "nLeptons", &nLeptonsFloat );
reader->AddSpectator( "isMuon1", &isMuon1Float );
reader->AddSpectator( "isMuon2", &isMuon2Float );
reader->AddSpectator( "isMuon3", &isMuon3Float );
reader->AddSpectator( "isMuon4", &isMuon4Float );
reader->AddSpectator( "leptonSumMass", &leptonSumMass );
//.........这里部分代码省略.........
示例13: TMVAClassificationCategoryApplication
void TMVAClassificationCategoryApplication()
{
// ---------------------------------------------------------------
// default MVA methods to be trained + tested
std::map<std::string,int> Use;
// ---
Use["LikelihoodCat"] = 1;
Use["FisherCat"] = 1;
// ---------------------------------------------------------------
std::cout << std::endl
<< "==> Start TMVAClassificationCategoryApplication" << std::endl;
// --- Create the Reader object
TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );
// Create a set of variables and spectators 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 var1, var2, var3, var4, eta;
reader->AddVariable( "var1", &var1 );
reader->AddVariable( "var2", &var2 );
reader->AddVariable( "var3", &var3 );
reader->AddVariable( "var4", &var4 );
reader->AddSpectator( "eta", &eta );
// --- Book the MVA methods
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (it->second) {
TString methodName = it->first + " method";
TString weightfile = "dataset/weights/TMVAClassificationCategory_" + TString(it->first) + ".weights.xml";
reader->BookMVA( methodName, weightfile );
}
}
// Book output histograms
UInt_t nbin = 100;
std::map<std::string,TH1*> hist;
hist["LikelihoodCat"] = new TH1F( "MVA_LikelihoodCat", "MVA_LikelihoodCat", nbin, -1, 0.9999 );
hist["FisherCat"] = new TH1F( "MVA_FisherCat", "MVA_FisherCat", nbin, -4, 4 );
// 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.
//
TString fname = TString(gSystem->DirName(__FILE__) ) + "/data/";
// if directory data not found try using tutorials dir
if (gSystem->AccessPathName( fname )) {
fname = TString(gROOT->GetTutorialsDir()) + "/tmva/data/";
}
if (UseOffsetMethod) fname += "toy_sigbkg_categ_offset.root";
else fname += "toy_sigbkg_categ_varoff.root";
std::cout << "--- TMVAClassificationApp : Accessing " << fname << "!" << std::endl;
TFile *input = TFile::Open(fname);
if (!input) {
std::cout << "ERROR: could not open data file: " << fname << std::endl;
exit(1);
}
// --- Event loop
// 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");
std::cout << "--- Use signal sample for evalution" << std::endl;
theTree->SetBranchAddress( "var1", &var1 );
theTree->SetBranchAddress( "var2", &var2 );
theTree->SetBranchAddress( "var3", &var3 );
theTree->SetBranchAddress( "var4", &var4 );
theTree->SetBranchAddress( "eta", &eta ); // spectator
std::cout << "--- Processing: " << theTree->GetEntries() << " events" << std::endl;
TStopwatch sw;
sw.Start();
for (Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl;
theTree->GetEntry(ievt);
// --- Return the MVA outputs and fill into histograms
for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
if (!it->second) continue;
TString methodName = it->first + " method";
hist[it->first]->Fill( reader->EvaluateMVA( methodName ) );
}
}
sw.Stop();
std::cout << "--- End of event loop: "; sw.Print();
// --- Write histograms
//.........这里部分代码省略.........
示例14: TMVAPredict
TString TMVAPredict(TString method_name, EnumPredictMode predictMode = EnumPredictMode::FINAL)
{
std::cout << "------------ predict with : " << method_name << " ------ " << std::endl;
std::vector<std::string> inputNames = {"training","test","check_correlation","check_agreement"};
std::map<std::string,std::vector<std::string>> varsForInput;
std::vector<std::string> variableOrder = {"id", "signal", "mass", "min_ANNmuon", "prediction"};
varsForInput["training"].emplace_back ("prediction");
if (predictMode != EnumPredictMode::INTERMEDIATE)
{
varsForInput["training"].emplace_back ("id");
varsForInput["training"].emplace_back ("signal");
varsForInput["training"].emplace_back ("mass");
varsForInput["training"].emplace_back ("min_ANNmuon");
varsForInput["test"].emplace_back ("prediction");
varsForInput["test"].emplace_back ("id");
varsForInput["check_agreement"].emplace_back ("signal");
varsForInput["check_agreement"].emplace_back ("weight");
varsForInput["check_agreement"].emplace_back ("prediction");
varsForInput["check_correlation"].emplace_back ("mass");
varsForInput["check_correlation"].emplace_back ("prediction");
}
std::map<std::string,std::vector<std::string>> createForInput;
createForInput["training"].emplace_back ("root");
if (predictMode != EnumPredictMode::INTERMEDIATE)
{
createForInput["training"].emplace_back ("csv");
createForInput["test"].emplace_back ("csv");
createForInput["check_agreement"].emplace_back ("csv");
createForInput["check_correlation"].emplace_back ("csv");
}
// -------- prepare the Reader ------
TMVA::Tools::Instance();
std::cout << "==> Start TMVAPredict" << std::endl;
TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );
std::vector<Float_t> variables (variableNames.size ());
auto itVar = begin (variables);
for (auto varName : variableNames)
{
Float_t* pVar = &(*itVar);
auto localVarName = varName;
localVarName.substr(0,localVarName.find(":="));
reader->AddVariable(varName.c_str(), pVar);
(*itVar) = 0.0;
++itVar;
}
// spectators not known for the reader (in test.csv)
for (auto varName : spectatorNames)
{
Float_t spectator (0.0);
reader->AddSpectator (varName.c_str(), &spectator);
++itVar;
}
TString dir = "weights/";
TString prefix = "TMVAClassification";
TString weightfile = dir + prefix + TString("_") + method_name + TString(".weights.xml");
std::cout << "weightfile name : " << weightfile.Data () << std::endl;
reader->BookMVA( method_name, weightfile );
// --------- for each of the input files
for (auto inputName : inputNames)
{
// --- define variables
Int_t id;
Float_t prediction;
Float_t weight;
Float_t min_ANNmuon;
Float_t mass;
Float_t signal;
// --- open input file
TFile *input(0);
std::stringstream infilename;
infilename << pathToData.Data () << inputName << ".root";
std::cout << "infilename = " << infilename.str ().c_str () << std::endl;
input = TFile::Open (infilename.str ().c_str ());
TTree* tree = (TTree*)input->Get("data");
// --- prepare branches on input file
// id field if needed
if (contains (varsForInput, inputName, "id"))
//.........这里部分代码省略.........
示例15: PlotDecisionBoundary
void PlotDecisionBoundary( TString weightFile = "weights/Zprime_vs_QCD_TMVAClassification_BDT.weights.xml",TString v0="lep_pt_ljet", TString v1="met_pt", TString dataFileNameS = "/nfs/dust/cms/user/karavdia/ttbar_semilep_13TeV/RunII_25ns_v1/test_03/uhh2.AnalysisModuleRunner.MC.Zp01w3000.root", TString dataFileNameB = "/nfs/dust/cms/user/karavdia/ttbar_semilep_13TeV/RunII_25ns_v1/test_03/uhh2.AnalysisModuleRunner.MC.QCD_EMEnriched.root")
{
//---------------------------------------------------------------
// default MVA methods to be trained + tested
// this loads the library
TMVA::Tools::Instance();
std::cout << std::endl;
std::cout << "==> Start TMVAClassificationApplication" << std::endl;
//
// 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) that you use
// Float_t var0, var1;
// reader->AddVariable( v0, &var0 );
// reader->AddVariable( v1, &var1 );
Float_t lep_pt, lep_fbrem, MwT;
Float_t log_ljet_pt, log_met_pt, log_lep_pt_ljet;
Float_t log_dR_lep_cljet, log_dR_cljet_ljet;
Float_t dPhi_lep_cljet;
reader->AddVariable("lep_pt", &lep_pt);
reader->AddVariable("lep_fbrem", & lep_fbrem);
reader->AddVariable("MwT", &MwT);
reader->AddVariable("log(ljet_pt)", &log_ljet_pt);
reader->AddVariable("log(met_pt)",&log_met_pt);
reader->AddVariable("log(lep_pt_ljet)",&log_lep_pt_ljet);
reader->AddVariable("log(dR_lep_cljet)",&log_dR_lep_cljet_trans);
reader->AddVariable("log(fabs((dR_cljet_ljet-3.14)/3.14))", &log_dR_cljet_ljet);
reader->AddSpectator("dPhi_lep_cljet", &dPhi_lep_cljet);
//
// book the MVA method
//
reader->BookMVA( "BDT", weightFile );
TFile *fS = new TFile(dataFileNameS);
TTree *signal = (TTree*)fS->Get("AnalysisTree");
TFile *fB = new TFile(dataFileNameS);
TTree *background = (TTree*)fB->Get("AnalysisTree");
//Declaration of leaves types
Float_t svar0;
Float_t svar1;
Float_t bvar0;
Float_t bvar1;
Float_t sWeight=1.0; // just in case you have weight defined, also set these branchaddresses
Float_t bWeight=1.0*signal->GetEntries()/background->GetEntries(); // just in case you have weight defined, also set these branchaddresses
// Set branch addresses.
signal->SetBranchAddress(v0,&svar0);
signal->SetBranchAddress(v1,&svar1);
background->SetBranchAddress(v0,&bvar0);
background->SetBranchAddress(v1,&bvar1);
UInt_t nbin = 50;
Float_t xmax = signal->GetMaximum(v0.Data());
Float_t xmin = signal->GetMinimum(v0.Data());
Float_t ymax = signal->GetMaximum(v1.Data());
Float_t ymin = signal->GetMinimum(v1.Data());
xmax = TMath::Max(xmax,(Float_t)background->GetMaximum(v0.Data()));
xmin = TMath::Min(xmin,(Float_t)background->GetMinimum(v0.Data()));
ymax = TMath::Max(ymax,(Float_t)background->GetMaximum(v1.Data()));
ymin = TMath::Min(ymin,(Float_t)background->GetMinimum(v1.Data()));
TH2D *hs=new TH2D("hs","",nbin,xmin,xmax,nbin,ymin,ymax);
TH2D *hb=new TH2D("hb","",nbin,xmin,xmax,nbin,ymin,ymax);
hs->SetXTitle(v0);
hs->SetYTitle(v1);
hb->SetXTitle(v0);
hb->SetYTitle(v1);
hs->SetMarkerColor(4);
hb->SetMarkerColor(2);
TH2F * hist = new TH2F( "MVA", "MVA", nbin,xmin,xmax,nbin,ymin,ymax);
// 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.
Float_t MinMVA=10000, MaxMVA=-100000;
for (UInt_t ibin=1; ibin<nbin+1; ibin++){
for (UInt_t jbin=1; jbin<nbin+1; jbin++){
var0 = hs->GetXaxis()->GetBinCenter(ibin);
var1 = hs->GetYaxis()->GetBinCenter(jbin);
Float_t mvaVal=reader->EvaluateMVA( "BDT" ) ;
//.........这里部分代码省略.........