当前位置: 首页>>代码示例>>C++>>正文


C++ Factory::AddVariable方法代码示例

本文整理汇总了C++中tmva::Factory::AddVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ Factory::AddVariable方法的具体用法?C++ Factory::AddVariable怎么用?C++ Factory::AddVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tmva::Factory的用法示例。


在下文中一共展示了Factory::AddVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TMVAClassification

void TMVAClassification()
{
   TMVA::Tools::Instance();

   std::cout << "==> Start TMVAClassification" << std::endl;
   TString outfileName( "TMVA.root" );

   TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
   TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
                                               "AnalysisType=Classification" );
   factory->AddVariable("LifeTime", 'F');
   factory->AddVariable("FlightDistance", 'F');
   factory->AddVariable("pt", 'F');
   
   TString fname = "../tau_data/training.root";
   TFile *input = TFile::Open( fname );
   
   TTree *tree     = (TTree*)input->Get("data");
   
   factory->AddTree(tree, "Signal", 1., "signal == 1", "Training");
   factory->AddTree(tree, "Signal", 1., "signal == 1", "Test");
   factory->AddTree(tree, "Background", 1., "signal == 0", "Training");
   factory->AddTree(tree, "Background", 1., "signal == 0", "Test");
   
   // gradient boosting training
   factory->BookMethod(TMVA::Types::kBDT, "GBDT",
                       "NTrees=40:BoostType=Grad:Shrinkage=0.01:MaxDepth=7:UseNvars=6:nCuts=20:MinNodeSize=10");
   factory->TrainAllMethods();
   input->Close();
   outputFile->Close();

   delete factory;
}
开发者ID:dbarge,项目名称:tauTo3mu,代码行数:33,代码来源:tmva.c

示例2: process

void process(const std::vector<std::string>& inputFiles, const std::string& name, const std::string& outputFile) {
  TChain* signal = loadChain(inputFiles, "signal");
  TChain* background = loadChain(inputFiles, "background");

  TFile* output = TFile::Open(outputFile.c_str(), "recreate");

  TMVA::Factory* factory = new TMVA::Factory(name.c_str(), output, "V");
  factory->AddSignalTree(signal, 1.);
  factory->AddBackgroundTree(background, 1.);

  //{
    //factory->AddVariable("lightJet1p2_Pt");
    //factory->AddVariable("leptonic_B_Pt");
    //factory->AddVariable("leptonic_Top_Pt");
    //factory->AddVariable("leptonic_Top_M");
    //factory->AddVariable("hadronic_B_Pt");
    //factory->AddVariable("hadronic_W_M");
    //factory->AddVariable("hadronic_Top_Pt");
    //factory->AddVariable("hadronic_Top_M");
    //factory->AddVariable("delta_R_tops");
    //factory->AddVariable("delta_R_lightjets");
    //factory->AddVariable("leptonic_B_CSV");
    //factory->AddVariable("hadronic_B_CSV");
  //}


  // chi^2 style
  {
    factory->AddVariable("leptonic_Top_M");
    factory->AddVariable("hadronic_W_M");
    factory->AddVariable("hadronic_Top_M");
    factory->AddVariable("ht_fraction");
  }

  factory->SetWeightExpression("weight");

  factory->PrepareTrainingAndTestTree("", "", "V:VerboseLevel=Info:nTrain_Signal=100000:nTrain_Background=100000:nTest_Signal=100000:nTest_Background=100000");

  factory->BookMethod(TMVA::Types::kBDT, "BDT", "V:BoostType=AdaBoost:nCuts=20:VarTransform=D");
  factory->BookMethod(TMVA::Types::kMLP, "NN", "V:VarTransform=D");
  //factory->BookMethod(TMVA::Types::kPDERS, "PDERS", "V");

  factory->TrainAllMethods();
  factory->TestAllMethods();
  factory->EvaluateAllMethods();

  output->Close();
  delete output;

  delete signal;
  delete background;
}
开发者ID:IPNL-CMS,项目名称:MttTools,代码行数:52,代码来源:trainBDT.cpp

示例3: test_train

void test_train(TString signalName = "WW",
		TString bkgName = "DY")
{
  TFile *outFile = new TFile("myAnalysisFile.root","RECREATE");
  
  TMVA::Factory *factory = new TMVA::Factory(signalName, outFile,"");
  
  TString directory = "../rootFiles/SF/MediumIDTighterIP/";
  //signalName = directory + signalName;
  
  //defining WW signal
  TFile *MySignalFile = new TFile("../rootFiles/SF/MediumIDTighterIP/WW.root","READ");
  TTree* sigTree = (TTree*)MySignalFile->Get("nt");
  factory->AddSignalTree(sigTree,1);
  
  //defining DY background
  TFile *MyBkgFile = new TFile("../rootFiles/SF/MediumIDTighterIP/DY.root","READ");
  TTree* bkgTree = (TTree*)MyBkgFile->Get("nt");
  factory->AddBackgroundTree(bkgTree,1);

  factory->SetWeightExpression("baseW");

  //************************************ FACTORY  
  
  factory->AddVariable("fullpmet");
  factory->AddVariable("trkpmet");
  factory->AddVariable("ratioMet");
  factory->AddVariable("ptll");
  factory->AddVariable("mth");
  factory->AddVariable("jetpt1");
  factory->AddVariable("ptWW");
  factory->AddVariable("dphilljet");
  factory->AddVariable("dphillmet");
  factory->AddVariable("dphijet1met");
  factory->AddVariable("nvtx");

  factory->PrepareTrainingAndTestTree("",500,500,500,500);
  cout<<"I've prepared trees"<<endl;
  //factory->BookMethod(TMVA::Types::kFisher, "Fisher","");
  factory->BookMethod(TMVA::Types::kBDT, "BDT","");
  
  cout<<"I've booked method"<<endl;
  factory->TrainAllMethods();
  factory->TestAllMethods();
  cout<<"I've tested all methods"<<endl;
  factory->EvaluateAllMethods();
  cout<<"I've evaluated all methods"<<endl;
  
}
开发者ID:NTrevisani,项目名称:WW13TeV,代码行数:49,代码来源:mva2.C

示例4: Loop

void REG::Loop() {

  if (fChain == 0) return;


  Long64_t nentries = fChain->GetEntriesFast();
  
  Long64_t nbytes = 0, nb = 0;
  TMVA::Tools::Instance();
  std::cout << std::endl;
  std::cout << "==> Start TMVARegression" << std::endl;
  TString outfileName( "TMVAReg.root" );
  TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

  TMVA::Factory *factory = new TMVA::Factory( "TMVARegression", outputFile, 
					      "!V:!Silent:Color:DrawProgressBar" );

  factory->AddVariable( "l1Pt", "Variable 1", "units", 'F' );
  factory->AddVariable( "l1Eta", "Variable 2", "units", 'F' );
  factory->AddVariable( "l1Phi", "Variable 1", "units", 'F' );
//  factory->AddVariable( "RhoL1", "Variable 2", "units", 'F' );

  
  factory->AddTarget( "ratio" ); 
  factory->AddRegressionTree(fChain, 1.0 );
  TCut mycut = "";
  factory->PrepareTrainingAndTestTree( mycut, 
				       "nTrain_Regression=10000:nTest_Regression=0:SplitMode=Block:NormMode=NumEvents:!V" );

  factory->BookMethod( TMVA::Types::kBDT, "BDT",
		       "!H:!V:NTrees=100:nEventsMin=5:BoostType=AdaBoostR2:SeparationType=RegressionVariance:nCuts=20:PruneMethod=CostComplexity:PruneStrength=30" );
  factory->TrainAllMethods();
 // ---- Evaluate all MVAs using the set of test events
  //   factory->TestAllMethods();

   // ----- Evaluate and compare performance of all configured MVAs
  //  factory->EvaluateAllMethods();    

   // --------------------------------------------------------------
   
   // Save the output
   outputFile->Close();

   std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
   std::cout << "==> TMVARegression is done!" << std::endl;      

   delete factory;
}
开发者ID:mguilbau,项目名称:usercode,代码行数:48,代码来源:NonLinReg.C

示例5: TMVAClassification

void TMVAClassification(char* trainFile, char* tree, 
                        char* mycuts, char*  mycutb, char* inputVars[], int size) 
{
   // this loads the library
   TMVA::Tools::Instance();

   // Create a new root output file.
   TFile* outputFile = TFile::Open( "TMVA.root", "RECREATE" );

   // Create the factory object.
   TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile, 
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D" );
   // ---------- input variables 
   for (int ivar = 0; ivar < size; ++ivar) {
     factory->AddVariable(inputVars[ivar], 'F');
   }

   // read training and test data
   TFile *input = TFile::Open( trainFile);
   TTree *signal     = (TTree*)input->Get(tree);
   TTree *background = (TTree*)input->Get(tree);
   

   // global event weights per tree 
   Double_t signalWeight     = 1.0;
   Double_t backgroundWeight = 1.0;

   // ====== register trees ====================================================
   // you can add an arbitrary number of signal or background trees
   factory->AddSignalTree    ( signal,     signalWeight     );
   factory->AddBackgroundTree( background, backgroundWeight );

   // tell the factory to use all remaining events in the trees after training for testing:
   factory->PrepareTrainingAndTestTree( TCut(mycuts), TCut(mycutb),
                                        "nTrain_Signal=0:nTrain_Background=0:SplitMode=Random:NormMode=NumEvents:!V" );

   // If no numbers of events are given, half of the events in the tree are used for training, and 
   // the other half for testing:

   // ---- Use BDT: Adaptive Boost
   factory->BookMethod( TMVA::Types::kBDT, "BDT", 
                        "!H:!V:NTrees=400:nEventsMin=400:MaxDepth=3:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
 
   // ---- Train MVAs using the set of training events
   factory->TrainAllMethods();

   // ---- Evaluate all MVAs using the set of test events
   factory->TestAllMethods();

   // ----- Evaluate and compare performance of all configured MVAs
   factory->EvaluateAllMethods();    

   // Save the output
   outputFile->Close();

   std::cout << "==> TMVAClassification is done!" << std::endl;      

   delete factory;
}
开发者ID:kalanand,项目名称:OptimalCarInsurancePolicy,代码行数:59,代码来源:Analyze.C

示例6: trainBDT

void trainBDT(void)
{
	// Open input file and get tree
	TFile *infile = new TFile("l3bdt.root");
	TTree *l3tree = (TTree*)infile->Get("l3tree");
	if(l3tree == NULL){
		cout << "Couldn't open \"l3bdt.root\"!" << endl;
		return;
	}

	// Open output root file (for TMVA)
	TFile *outfile = new TFile("l3BDT_out.root", "RECREATE");
	TMVA::Factory *fac = new TMVA::Factory("L3",outfile,"");

	// Specify input tree that contains both signal and background 
	TCut signalCut("is_good==1");
	TCut backgroundCut("is_good==0");
	fac->SetInputTrees(l3tree, signalCut, backgroundCut);

	// Add variables
	fac->AddVariable("Nstart_counter",      'I');
	fac->AddVariable("Ntof",                'I');
	fac->AddVariable("Nbcal_points",        'I');
	fac->AddVariable("Nbcal_clusters",      'I');
	fac->AddVariable("Ebcal_points",        'F');
	fac->AddVariable("Ebcal_clusters",      'F');
	fac->AddVariable("Nfcal_clusters",      'I');
	fac->AddVariable("Efcal_clusters",      'F');
	fac->AddVariable("Ntrack_candidates",   'I');
	fac->AddVariable("Ptot_candidates",     'F');

	TCut preSelectCut("");
	fac->PrepareTrainingAndTestTree(preSelectCut,"");
	fac->BookMethod(TMVA::Types::kBDT, "BDT", "");

	fac->TrainAllMethods();
	fac->TestAllMethods();
	fac->EvaluateAllMethods();

	delete fac;

	outfile->Close();
	delete outfile;
}
开发者ID:JeffersonLab,项目名称:sim-recon,代码行数:44,代码来源:trainBDT.C

示例7: trainBJetIdMVA

void trainBJetIdMVA(TString SELECTION)
{
  // the training is done using a dedicated tree format
  TFile *src = TFile::Open("bjetId_"+SELECTION+".root");
  TTree *tr  = (TTree*)src->Get("jets"); 
  
  TFile *outf    = new TFile("bjetId_"+SELECTION+"_MVA.root","RECREATE");

  TCut signalCut       = "abs(partonId) == 5";
  TCut bkgCut          = "abs(partonId) != 5";
  TCut preselectionCut = "btagIdx<4 && etaIdx<4 && etaIdx>-1 && ptIdx<4";
  
  int N = 100000;
  cout<<"NUMBER OF TRAINING EVENTS = "<<N<<endl;
  
  TMVA::Factory* factory = new TMVA::Factory("factory_"+SELECTION+"_",outf,"!V:!Silent:Color:DrawProgressBar:Transformations=I;G:AnalysisType=Classification" );
  
  factory->SetInputTrees(tr,signalCut,bkgCut);
  
  factory->AddVariable("btagIdx",'I');
  factory->AddVariable("etaIdx" ,'I');
  factory->AddVariable("btag"   ,'F');
  factory->AddVariable("eta"    ,'F');

  char name[1000];
  sprintf(name,"nTrain_Signal=%d:nTrain_Background=%d:nTest_Signal=%d:nTest_Background=%d",N,N,N,N);
  factory->PrepareTrainingAndTestTree(preselectionCut,name);

  // specify the training methods
  factory->BookMethod(TMVA::Types::kLikelihood,"Likelihood");
  //factory->BookMethod(TMVA::Types::kBDT,"BDT_DEF");
  //factory->BookMethod(TMVA::Types::kBDT,"BDT_ADA","NTrees=600:AdaBoostBeta=0.1:nCuts=35"); 
  //factory->BookMethod(TMVA::Types::kBDT,"BDT_GRAD1","NTrees=600:nCuts=40:BoostType=Grad:Shrinkage=0.5");  
  factory->BookMethod(TMVA::Types::kBDT,"BDT_GRAD2","NTrees=600:nCuts=25:BoostType=Grad:Shrinkage=0.2");
  factory->TrainAllMethods();
  factory->TestAllMethods();
  factory->EvaluateAllMethods(); 
}
开发者ID:UAEDF,项目名称:vbfHbb,代码行数:38,代码来源:trainBJetIdMVA.C

示例8: TMVAtest

void TMVAtest(){
  //gSystem->Load("../lib/slc5_amd64_gcc462/libTAMUWWMEPATNtuple.so");
  gSystem->Load("libPhysics");
  //gSystem->Load("EvtTreeForAlexx_h.so");
  gSystem->Load("libTMVA.1");
  gSystem->Load("AutoDict_vector_TLorentzVector__cxx.so");
  TMVA::Tools::Instance();
  TFile* outputFile = TFile::Open("TMVA1.root", "RECREATE");
  TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification",outputFile,"V=true:Color:DrawProgressBar");// ":Transformations=I;D;P;G,D" );
  TFile* signal = TFile::Open("/uscms_data/d2/aperloff/Spring12ME7TeV/MEResults/microNtuples_oldStructure/microWW_EPDv01.root");
  TFile* bkg = TFile::Open("/uscms_data/d2/aperloff/Spring12ME7TeV/MEResults/microNtuples_oldStructure/microWJets_EPDv01.root");

  TTree* stree = (TTree*)signal->Get("METree");
  TTree* btree = (TTree*)bkg->Get("METree");
  factory->AddSignalTree(stree,1.0);
  factory->AddBackgroundTree(btree,1.0);


  factory->SetSignalWeightExpression("1.0");
  factory->SetBackgroundWeightExpression("1.0");
  factory->AddVariable("tEventProb[0]");
  factory->AddVariable("tEventProb[1]");
  factory->AddVariable("tEventProb[2]");

  //factory->AddVariable("tEventProb0 := tEventProb[0]",'F');
  //factory->AddVariable("tEventProb1 := tEventProb[1]",'F');
  //factory->AddVariable("tEventProb2 := tEventProb[2]",'F');
  TCut test("Entry$>-2 && jLV[1].Pt()>30");
  TCut mycuts (test);
  factory->PrepareTrainingAndTestTree(mycuts,mycuts,"nTrain_Signal=0:nTrain_Background=0:nTest_Signal=0:nTest_Background=0:SplitMode=Random:NormMode=None:V=true:VerboseLevel=DEBUG");
  factory->BookMethod( TMVA::Types::kBDT, "BDT","!H:!V:NTrees=400:nEventsMin=400:MaxDepth=3:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
  factory->TrainAllMethods();
  factory->TestAllMethods();
  factory->EvaluateAllMethods();
  outputFile->Close(); 

}
开发者ID:aperloff,项目名称:TAMUWW,代码行数:37,代码来源:TMVAtest.C

示例9: main


//.........这里部分代码省略.........
 // The first argument is the base of the name of all the
 // weightfiles in the directory weight/ 
 // All TMVA output can be suppressed by removing the "!" (not) in 
 // front of the "Silent" argument in the option string

 // Read training and test data (see TMVAClassification for reading ASCII files)
 // load the signal and background event samples from ROOT trees
 std::string inputFileList =  gConfigParser -> readStringOption("Input::inputFileList");
 std::string treeNameDATA =  gConfigParser -> readStringOption("Input::treeNameDATA");

 std::cout<<" Input Data List = "<<inputFileList<<std::endl;

 TChain* treeDATA = new TChain(treeNameDATA.c_str());

 FillChain(*treeDATA,inputFileList.c_str());


 TMVA::Factory *factory = new TMVA::Factory( "TMVARegression", outputFile, 
                                               "!V:!Silent:Color:DrawProgressBar" );

 // If you wish to modify default settings 
 // (please check "src/Config.h" to see all available global options)
 //    (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
 //    (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";
 // Define the input variables that shall be used for the MVA training
 // note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
 // [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
 std::string RegionOfTraining =  gConfigParser -> readStringOption("Input::RegionOfTraining");
 std::cout<<" RegionOfTraining = "<<RegionOfTraining<<std::endl;
 
 if(RegionOfTraining=="EB"){


 factory->AddVariable( "ele1_scE/ele1_scERaw" , 'F');   
 factory->AddVariable( "ele1_eRegrInput_nPV" , 'F');
 factory->AddVariable( "ele1_eRegrInput_r9" , 'F');
 factory->AddVariable( "ele1_fbrem" , 'F');
 factory->AddVariable( "ele1_eta" , 'F');
 factory->AddVariable( "ele1_DphiIn" , 'F');
 factory->AddVariable( "ele1_DetaIn" , 'F');
 factory->AddVariable( "ele1_sigmaIetaIeta" , 'F');

 factory->AddVariable( "ele1_eRegrInput_etaW" , 'F');
 factory->AddVariable( "ele1_eRegrInput_phiW" , 'F');

 factory->AddVariable( "ele1_eRegrInput_bCE_Over_sCE", 'F');
 factory->AddVariable( "ele1_eRegrInput_sigietaieta_bC1" , 'F');
 factory->AddVariable( "ele1_eRegrInput_sigiphiiphi_bC1" , 'F');
 factory->AddVariable( "ele1_eRegrInput_sigietaiphi_bC1" , 'F');
 factory->AddVariable( "ele1_eRegrInput_e3x3_Over_bCE" , 'F');
 factory->AddVariable( "ele1_eRegrInput_Deta_bC_sC" , 'F');
 factory->AddVariable( "ele1_eRegrInput_Dphi_bC_sC" , 'F');
 factory->AddVariable( "ele1_eRegrInput_bEMax_Over_bCE" , 'F');


 factory->AddVariable( "ele1_dxy_PV" , 'F');
 factory->AddVariable( "ele1_dz_PV" , 'F');
 factory->AddVariable( "ele1_sigmaP/ele1_tkP" , 'F');

 factory->AddVariable( "ele1_eRegrInput_bCELow_Over_sCE", 'F');
 factory->AddVariable( "ele1_eRegrInput_e3x3_Over_bCELow" , 'F');
 factory->AddVariable( "ele1_eRegrInput_Deta_bCLow_sC" , 'F');
 factory->AddVariable( "ele1_eRegrInput_Dphi_bCLow_sC" , 'F');

 factory->AddVariable( "ele1_eRegrInput_seedbC_etacry" , 'F');
 factory->AddVariable( "ele1_eRegrInput_seedbC_phicry" , 'F');
开发者ID:Bicocca,项目名称:EOverPCalibration,代码行数:67,代码来源:MVARegression.cpp

示例10: TMVAClassification

void TMVAClassification( TString fname = "./tmva_class_example.root")
{
   // The explicit loading of the shared libTMVA is done in TMVAlogon.C, defined in .rootrc
   // if you use your private .rootrc, or run from a different directory, please copy the
   // corresponding lines from .rootrc

   // methods to be processed can be given as an argument; use format:
   //
   // mylinux~> root -l TMVAClassification.C\(\"myMethod1,myMethod2,myMethod3\"\)
   //
   // if you like to use a method via the plugin mechanism, we recommend using
   //
   // mylinux~> root -l TMVAClassification.C\(\"P_myMethod\"\)
   // (an example is given for using the BDT as plugin (see below),
   // but of course the real application is when you write your own
   // method based)

   //---------------------------------------------------------------
   // This loads the library
   TMVA::Tools::Instance();

   // to get access to the GUI and all tmva macros
   TString tmva_dir(TString(gRootDir) + "/tmva");
   if(gSystem->Getenv("TMVASYS"))
      tmva_dir = TString(gSystem->Getenv("TMVASYS"));
   gROOT->SetMacroPath(tmva_dir + "/test/:" + gROOT->GetMacroPath() );
   gROOT->ProcessLine(".L TMVAGui.C");

   // Default MVA methods to be trained + tested
   std::map<std::string,int> Use;

   
   Use["KNN"]             = 1; // k-nearest neighbour method
   
   // ---------------------------------------------------------------

   std::cout << std::endl;
   std::cout << "==> Start TMVAClassification" << std::endl;

  

   // --------------------------------------------------------------------------------------------------

   // --- Here the preparation phase begins

   // Create a ROOT output file where TMVA will store ntuples, histograms, etc.
   TString outfileName( "TMVA.root" );
   TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

   // Create the factory object. Later you can choose the methods
   // whose performance you'd like to investigate. The factory is 
   // the only TMVA object you have to interact with
   //
   // The first argument is the base of the name of all the
   // weightfiles in the directory weight/
   //
   // The second argument is the output file for the training results
   // All TMVA output can be suppressed by removing the "!" (not) in
   // front of the "Silent" argument in the option string
   TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I:AnalysisType=Classification" );

   // If you wish to modify default settings
   // (please check "src/Config.h" to see all available global options)
   //    (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
   //    (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";

   // Define the input variables that shall be used for the MVA training
   // note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
   // [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
   factory->AddVariable( "pt_eH", 'D' );
   factory->AddVariable( "max(pt_jet_eH,pt_eH)", 'D' );
   factory->AddVariable( "njets", 'I' );
   
   // You can add so-called "Spectator variables", which are not used in the MVA training,
   // but will appear in the final "TestTree" produced by TMVA. This TestTree will contain the
   // input variables, the response values of all trained MVAs, and the spectator variables
  /// factory->AddSpectator( "spec1 := var1*2",  "Spectator 1", "units", 'F' );
  /// factory->AddSpectator( "spec2 := var1*3",  "Spectator 2", "units", 'F' );

   // Read training and test data
   // (it is also possible to use ASCII format as input -> see TMVA Users Guide)
  
   TFile *input(0);
   if (gSystem->AccessPathName( fname )){  // file does not exist in local directory
      gSystem->Exec("wget http://root.cern.ch/files/tmva_class_example.root");
	  fname = "./tmva_class_example.root";
  }else{
	input= TFile::Open( fname );
  }
  if (!input) {
     std::cout << "ERROR: could not open data file " << fname << std::endl;
     exit(1);
  }
   
   std::cout << "--- TMVAClassification       : Using input file: " << input->GetName() << std::endl;
   
   // --- Register the training and test trees

   TTree *inputTree     = (TTree*)input->Get("FakeTreeSig");
//.........这里部分代码省略.........
开发者ID:jpavel,项目名称:cms-ucl-tau,代码行数:101,代码来源:WH_kNN_Classification.C

示例11: Classification

void Classification()
{
   TMVA::Tools::Instance();
   TMVA::PyMethodBase::PyInitialize();

   TString outfileName("TMVA.root");
   TFile *outputFile = TFile::Open(outfileName, "RECREATE");

   TMVA::Factory *factory = new TMVA::Factory("TMVAClassification", outputFile,
         "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification");


   factory->AddVariable("myvar1 := var1+var2", 'F');
   factory->AddVariable("myvar2 := var1-var2", "Expression 2", "", 'F');
   factory->AddVariable("var3",                "Variable 3", "units", 'F');
   factory->AddVariable("var4",                "Variable 4", "units", 'F');


   factory->AddSpectator("spec1 := var1*2",  "Spectator 1", "units", 'F');
   factory->AddSpectator("spec2 := var1*3",  "Spectator 2", "units", 'F');


   TString fname = "./tmva_class_example.root";

   if (gSystem->AccessPathName(fname))    // file does not exist in local directory
      gSystem->Exec("curl -O http://root.cern.ch/files/tmva_class_example.root");

   TFile *input = TFile::Open(fname);

   std::cout << "--- TMVAClassification       : Using input file: " << input->GetName() << std::endl;

   // --- Register the training and test trees

   TTree *tsignal     = (TTree *)input->Get("TreeS");
   TTree *tbackground = (TTree *)input->Get("TreeB");

   // global event weights per tree (see below for setting event-wise weights)
   Double_t signalWeight     = 1.0;
   Double_t backgroundWeight = 1.0;

   // You can add an arbitrary number of signal or background trees
   factory->AddSignalTree(tsignal,     signalWeight);
   factory->AddBackgroundTree(tbackground, backgroundWeight);


   // Set individual event weights (the variables must exist in the original TTree)
   factory->SetBackgroundWeightExpression("weight");


   // Apply additional cuts on the signal and background samples (can be different)
   TCut mycuts = ""; // for example: TCut mycuts = "abs(var1)<0.5 && abs(var2-0.5)<1";
   TCut mycutb = ""; // for example: TCut mycutb = "abs(var1)<0.5";

   // Tell the factory how to use the training and testing events
   factory->PrepareTrainingAndTestTree(mycuts, mycutb,
                                       "nTrain_Signal=0:nTrain_Background=0:nTest_Signal=0:nTest_Background=0:SplitMode=Random:NormMode=NumEvents:!V");


   ///////////////////
   //Booking         //
   ///////////////////
   // Boosted Decision Trees

   //PyMVA methods
   factory->BookMethod(TMVA::Types::kPyRandomForest, "PyRandomForest",
                       "!V:NEstimators=150:Criterion=gini:MaxFeatures=auto:MaxDepth=3:MinSamplesLeaf=1:MinWeightFractionLeaf=0:Bootstrap=kTRUE");
   factory->BookMethod(TMVA::Types::kPyAdaBoost, "PyAdaBoost",
                       "!V:BaseEstimator=None:NEstimators=100:LearningRate=1:Algorithm=SAMME.R:RandomState=None");
   factory->BookMethod(TMVA::Types::kPyGTB, "PyGTB",
                       "!V:NEstimators=150:Loss=deviance:LearningRate=0.1:Subsample=1:MaxDepth=6:MaxFeatures='auto'");


   // Train MVAs using the set of training events
   factory->TrainAllMethods();

   // ---- Evaluate all MVAs using the set of test events
   factory->TestAllMethods();

   // ----- Evaluate and compare performance of all configured MVAs
   factory->EvaluateAllMethods();
   // --------------------------------------------------------------

   // Save the output
   outputFile->Close();

   std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
   std::cout << "==> TMVAClassification is done!" << std::endl;

}
开发者ID:MycrofD,项目名称:root,代码行数:89,代码来源:Classification.C

示例12: TMVAClassification_cc1pcoh_bdt_ver6noveract


//.........这里部分代码省略.........
    // 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 = TMVA::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;
        }
    }

    // ---------------------------------------------------------------
    // --- Here the preparation phase begins

    // Create a ROOT output file where TMVA will store ntuples, histograms, etc.
    TString outfileName( "TMVA_cc1pcoh_bdt_ver6noveract.root" );//newchange
    TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

    // Create the factory object.
    TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification_ver6noveract", outputFile,//newchange
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );

    
    // Add variable
    //sprintf(select,  "Ntrack==2&&mumucl>0.6&&pmucl>0.25&&pang<90&&muang_t<15 && veract*7.66339869e-2<34");
    //factory->AddVariable( "Ntrack", 'F' );
    factory->AddVariable( "mumucl", 'F' );
    factory->AddVariable( "pmucl", 'F' );
    factory->AddVariable( "pang_t", 'F' );//use pang instead of pang_t
    factory->AddVariable( "muang_t", 'F' );
    //factory->AddVariable( "veract", 'F' );
    factory->AddVariable( "ppe", 'F');
    factory->AddVariable( "mupe", 'F');
    factory->AddVariable( "range", 'F');
    factory->AddVariable( "coplanarity", 'F');
    factory->AddVariable( "opening", 'F');//newadd

    // Add spectator
    factory->AddSpectator( "fileIndex", 'I' );
    factory->AddSpectator( "nuE", 'F' );
    factory->AddSpectator( "inttype", 'I' );
    factory->AddSpectator( "norm", 'F' );
    factory->AddSpectator( "totcrsne", 'F' );
    factory->AddSpectator( "veract", 'F' );
    factory->AddSpectator( "pang", 'F' );
    factory->AddSpectator( "mupdg", 'I' );
    factory->AddSpectator( "ppdg", 'I' );

    // ---------------------------------------------------------------
    // --- Get weight
    TString fratioStr="/home/kikawa/macros/nd34_tuned_11bv3.1_250ka.root";
    
    
    
    // ---------------------------------------------------------------
    // --- Add sample
    TString fsignalStr="/home/cvson/cc1picoh/frkikawa/meAna/ip4tmva/pm_merged_ccqe_tot.root";
    TString fbarStr="/home/cvson/cc1picoh/frkikawa/meAna/ip4tmva/pmbar_merged_ccqe.root";
    TString fbkgStr="/home/cvson/cc1picoh/frkikawa/meAna/ip4tmva/wall_merged_ccqe_tot.root";
开发者ID:cvson,项目名称:tmvaccohPM,代码行数:67,代码来源:TMVAClassification_cc1pcoh_bdt_ver6noveract.C

示例13: ZTMVAClassification

void ZTMVAClassification( TString myMethodList = "" )
{
   

   //---------------------------------------------------------------
   // This loads the library
   TMVA::Tools::Instance();

   // Default MVA methods to be trained + tested
   std::map<std::string,int> 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"]             = 1; // 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"]            = 1; // uses Gradient Boost
   Use["BDTB"]            = 0; // uses Bagging
   Use["BDTD"]            = 1; // decorrelation + Adaptive Boost
   Use["BDTF"]            = 0; // allow usage of fisher discriminant for node splitting 
   // 
   // --- Friedman's RuleFit method, ie, an optimised series of cuts ("rules")
   Use["RuleFit"]         = 0;
   // ---------------------------------------------------------------

   std::cout << std::endl;
   std::cout << "==> Start TMVAClassification" << std::endl;



   // --------------------------------------------------------------------------------------------------

   // --- Here the preparation phase begins

   // Create a ROOT output file where TMVA will store ntuples, histograms, etc.
   TString outfileName( "TMVA.root" );
   TFile* outputFile = TFile::Open( outfileName, "RECREATE" );


   TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );

   //factory->AddVariable( "maxpioneta", "maxpioneta", "", 'F' );
   //factory->AddVariable( "minpioneta", "minpioneta", "", 'F' );
   factory->AddVariable( "nTT", "nTT", "", 'F' );
   // factory->AddVariable( "pidpimin", "pidpimin", "", 'F' );
   // factory->AddVariable( "pidpimax", "pidpimax", "", 'F' );
   factory->AddVariable( "normxpt", "normxpt", "", 'F' );
   factory->AddVariable( "eta", "eta", "", 'F' );
   //factory->AddVariable( "phi", "phi", "", 'F' );
   //  factory->AddVariable( "normptsum", "normptsum", "", 'F' );
    //factory->AddVariable( "ptAsym", "ptAsym", "", 'F' );
   //factory->AddVariable( "dphimax", "dphimax", "", 'F' );
 //factory->AddVariable( "dphimin", "dphimin", "", 'F' );
   //factory->AddVariable( "drmax", "drmax", "", 'F' );
   // factory->AddVariable( "drmin", "drmin", "", 'F' );
//.........这里部分代码省略.........
开发者ID:goi42,项目名称:lhcb,代码行数:101,代码来源:ZTMVAClassification.C

示例14: main


//.........这里部分代码省略.........
    bkgfiles.push_back("MC_EWK-Z2jiglep");
    bkgfiles.push_back("MC_EWK-W2jminus_enu");
    bkgfiles.push_back("MC_EWK-W2jplus_enu");
    bkgfiles.push_back("MC_EWK-W2jminus_munu");
    bkgfiles.push_back("MC_EWK-W2jplus_munu");
    bkgfiles.push_back("MC_EWK-W2jminus_taunu");
    bkgfiles.push_back("MC_EWK-W2jplus_taunu");
  }

   // Create a ROOT output file where TMVA will store ntuples, histograms, etc.
  TFile *output_tmva = TFile::Open((folder+"/TMVA_QCDrej.root").c_str(),"RECREATE");

  // Create the factory object. Later you can choose the methods
  // whose performance you'd like to investigate. The factory is 
  // the only TMVA object you have to interact with
   //
   // The first argument is the base of the name of all the
   // weightfiles in the directory weight/
   //
   // The second argument is the output file for the training results
   // All TMVA output can be suppressed by removing the "!" (not) in
   // front of the "Silent" argument in the option string
   TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", output_tmva,
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );


  //fill the variables with event weight from the trees
  //const unsigned nVars = 4;

   
   factory->AddSpectator("jet1_pt","Jet 1 p_{T}", "GeV", 'F');
   factory->AddSpectator("jet2_pt","Jet 2 p_{T}", "GeV", 'F');
   factory->AddSpectator("jet1_eta","Jet 1 #eta", "", 'F');
   factory->AddVariable("jet2_eta","Jet 2 #eta", "", 'F');// **
   factory->AddSpectator("jet1_phi","Jet 1 #phi", "", 'F');
   factory->AddSpectator("jet2_phi","Jet 2 #phi", "", 'F');
   factory->AddSpectator("dijet_M","M_{jj}", " GeV", 'F');
   factory->AddSpectator("dijet_deta","#Delta#eta_{jj}", "", 'F');
   factory->AddSpectator("dijet_sumeta","#eta_{j1}+#eta_{j2}", "", 'F');
   factory->AddSpectator("dijet_dphi","#Delta#phi_{jj}", "", 'F');
   factory->AddSpectator("met","MET", "GeV", 'F');// **
   factory->AddSpectator("met_phi","MET #phi", "", 'F');
   factory->AddVariable("met_significance","MET significance", "", 'F');// **
   factory->AddSpectator("sumet","#Sum E_{T}", "GeV", 'F');
   factory->AddSpectator("ht","H_{T}", "GeV", 'F');
   factory->AddVariable("mht","MH_{T}", "GeV", 'F');// **
   factory->AddSpectator("sqrt_ht","#sqrt{H_{T}}", "GeV^{0.5}", 'F');
   factory->AddSpectator("unclustered_et","Unclustered E_{T}", "GeV", 'F');
   factory->AddSpectator("unclustered_phi","Unclustered #phi", "GeV", 'F');
   factory->AddSpectator("jet1met_dphi","#Delta#phi(MET,jet1)", "", 'F');
   factory->AddVariable("jet2met_dphi","#Delta#phi(MET,jet2)", "", 'F');// **
   factory->AddVariable("jetmet_mindphi","minimum #Delta#phi(MET,jet)", "", 'F');// **
   factory->AddVariable("jetunclet_mindphi","minimum #Delta#phi(unclustered,jet)", "",  'F');// **
   factory->AddVariable("metunclet_dphi","#Delta#phi(MET,unclustered)", "",  'F');// **
   factory->AddVariable("dijetmet_scalarSum_pt", "p_{T}^{jet1}+p_{T}^{jet2}+MET", "GeV", 'F');// **
   factory->AddSpectator("dijetmet_vectorialSum_pt","p_{T}(#vec{j1}+#vec{j2}+#vec{MET})", "GeV", 'F');
   factory->AddVariable("dijetmet_ptfraction","p_{T}^{dijet}/(p_{T}^{dijet}+MET)", "", 'F');// **
   //factory->AddVariable("jet1met_scalarprod := (jet1_pt*cos(jet1_phi)*met_x+jet1_pt*sin(jet1_phi)*met_y)/met", "#vec{p_{T}^{jet1}}.#vec{MET}/MET", "GeV" , 'F');
   //factory->AddVariable("jet2met_scalarprod := (jet2_pt*cos(jet2_phi)*met_x+jet2_pt*sin(jet2_phi)*met_y)/met", "#vec{p_{T}^{jet2}}.#vec{MET}/MET", "GeV" , 'F');
   factory->AddVariable("jet1met_scalarprod", "#vec{p_{T}^{jet1}}.#vec{MET}/MET", "GeV" , 'F');// **
   factory->AddVariable("jet2met_scalarprod", "#vec{p_{T}^{jet2}}.#vec{MET}/MET", "GeV" , 'F');// **
   factory->AddVariable("jet1met_scalarprod_frac := jet1met_scalarprod/met", "#vec{p_{T}^{jet1}}.#vec{MET}/MET^{2}", "" , 'F');// **
   factory->AddVariable("jet2met_scalarprod_frac := jet2met_scalarprod/met", "#vec{p_{T}^{jet2}}.#vec{MET}/MET^{2}", "" , 'F');// **
   factory->AddSpectator("n_jets_cjv_30","CJV jets (30 GeV)", "" , 'I');
   factory->AddSpectator("n_jets_cjv_20EB_30EE","CJV jets (|#eta|<2.4 and 20 GeV, or 30 GeV)", "" , 'I');
   
开发者ID:achilleasatha,项目名称:ICHiggsTauTau,代码行数:66,代码来源:RunTmva.cpp

示例15: TrainRegressionFJ


//.........这里部分代码省略.........
    TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

    // Create the factory object. Later you can choose the methods
    // whose performance you'd like to investigate. The factory will
    // then run the performance analysis for you.
    //
    // The first argument is the base of the name of all the
    // weightfiles in the directory weights/
    //
    // The second argument is the output file for the training results
    // All TMVA output can be suppressed by removing the "!" (not) in 
    // front of the "Silent" argument in the option string
    TMVA::Factory *factory = new TMVA::Factory( "TMVARegressionFJ", outputFile, 
                                                "!V:!Silent:!Color:!DrawProgressBar:Transformations=I:AnalysisType=Regression" );

    // If you wish to modify default settings
    // (please check "src/Config.h" to see all available global options)
    //    (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
    //    (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";

    const std::vector<std::string> & inputExpressions      = GetInputExpressionsFJReg();
    const std::vector<std::string> & inputExpressionLabels = GetInputExpressionLabelsFJReg();
    assert(inputExpressions.size() == inputExpressionLabels.size());

    // Define the input variables that shall be used for the MVA training
    // note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
    // [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
    //factory->AddVariable( "var1", "Variable 1", "units", 'F' );
    //factory->AddVariable( "var2", "Variable 2", "units", 'F' );
    
    for (UInt_t iexpr=0; iexpr!=inputExpressions.size(); iexpr++){
        Label label = MakeLabel(inputExpressionLabels.at(iexpr));
        TString expr = inputExpressions.at(iexpr);
        factory->AddVariable(expr, label.xlabel, label.unit, label.type);
    }

    // You can add so-called "Spectator variables", which are not used in the MVA training,
    // but will appear in the final "TestTree" produced by TMVA. This TestTree will contain the
    // input variables, the response values of all trained MVAs, and the spectator variables
    //factory->AddSpectator( "spec1 := var1*2",  "Spectator 1", "units", 'F' );
    //factory->AddSpectator( "spec2 := var1*3",  "Spectator 2", "units", 'F' );

    // Add the variable carrying the regression target
    //factory->AddTarget( "fvalue" );
    factory->AddTarget( "fathFilterJets_genPt" );

    // It is also possible to declare additional targets for multi-dimensional regression, ie:
    // -- factory->AddTarget( "fvalue2" );
    // BUT: this is currently ONLY implemented for MLP

    //--------------------------------------------------------------------------
    // Read training and test data
    TFile *input(0);
    TString dirname = "skim_ZnnH_regression_fj/";
    TString prefix  = "skim_";
    TString suffix  = ".root";
    TTree *regTrainTree(0), *regTestTree(0);
    
    std::vector<std::string> processes;
    processes.push_back("ZnnH110");
    processes.push_back("ZnnH115");
    processes.push_back("ZnnH120");
    processes.push_back("ZnnH125");
    processes.push_back("ZnnH130");
    processes.push_back("ZnnH135");
    processes.push_back("ZnnH140");
开发者ID:degrutto,项目名称:VHbbUF,代码行数:67,代码来源:TrainRegressionFJ.C


注:本文中的tmva::Factory::AddVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。