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


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

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


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

示例1: regressphi

void regressphi() {
   TMVA::Tools::Instance();
   std::cout << "==> Start TMVAClassification" << std::endl;
  
   // 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( "mva", outputFile,
                                               "!V:!Silent:Color:DrawProgressBar" );
   factory->AddVariable( "npv"                , 'F' ); 
   factory->AddVariable( "u"                  , 'F' ); 
   factory->AddVariable( "uphi"               , 'F' );
   factory->AddVariable( "chsumet/sumet"      , 'F' ); 
   factory->AddVariable( "tku"                , 'F' );
   factory->AddVariable( "tkuphi"             , 'F' );
   factory->AddVariable( "nopusumet/sumet"    , 'F' );
   factory->AddVariable( "nopuu"              , 'F' );
   factory->AddVariable( "nopuuphi"           , 'F' );
   factory->AddVariable( "pusumet/sumet"      , 'F' );
   factory->AddVariable( "pumet"              , 'F' );
   factory->AddVariable( "pumetphi"           , 'F' );
   factory->AddVariable( "pucsumet/sumet"     , 'F' );
   factory->AddVariable( "pucu"               , 'F' );
   factory->AddVariable( "pucuphi"            , 'F' );
   factory->AddVariable( "jspt_1"             , 'F' );
   factory->AddVariable( "jseta_1"            , 'F' );
   factory->AddVariable( "jsphi_1"            , 'F' );
   factory->AddVariable( "jspt_2"             , 'F' );
   factory->AddVariable( "jseta_2"            , 'F' );
   factory->AddVariable( "jsphi_2"            , 'F' );
   factory->AddVariable( "nalljet"            , 'I' );
   factory->AddVariable( "njet"               , 'I' );
    
   factory->AddTarget( "rphi_z-uphi+ 2.*TMath::Pi()*(rphi_z-uphi < -TMath::Pi()) - 2.*TMath::Pi()*(rphi_z-uphi > TMath::Pi())  " ); 
   TString  lName       = "../Jets/r11-dimu_nochs_v2.root";  TFile *lInput = TFile::Open(lName);
   TTree   *lRegress    = (TTree*)lInput    ->Get("Flat");

   Double_t lRWeight = 1.0;
   factory->AddRegressionTree( lRegress   , lRWeight );
   TCut lCut = "nbtag == 0"; //Cut to remove real MET
   //(rpt_z < 40 || (rpt_z > 40 && rpt_z+u1 < 40)) && nbtag == 0 "; ==> stronger cut to remove Real MET

   factory->PrepareTrainingAndTestTree( lCut,
					"nTrain_Regression=0:nTest_Regression=0:SplitMode=Block:NormMode=NumEvents:!V" );

   // Boosted Decision Trees
   factory->BookMethod( TMVA::Types::kBDT, "RecoilPhiRegress_data_clean2_njet",
			"!H:!V:VarTransform=None:nEventsMin=200:NTrees=100:BoostType=Grad:Shrinkage=0.1:MaxDepth=100:NNodesMax=100000:UseYesNoLeaf=F:nCuts=2000");//MaxDepth=100

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

   std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
   std::cout << "==> TMVAClassification is done!" << std::endl;
   delete factory;
   //if (!gROOT->IsBatch()) TMVAGui( outfileName );
}
开发者ID:anantoni,项目名称:CMG,代码行数:59,代码来源:regressphi.C

示例2: 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

示例3: main


//.........这里部分代码省略.........

 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');

 // 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("ele1_scE/ele1_E_true" ); 
   factory->AddTarget("ele1_tkP/ele1_E_true" ); 


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

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

 // You can add an arbitrary number of regression trees
 factory->AddRegressionTree( treeDATA, regWeight );

 // This would set individual event weights (the variables defined in the 
 // expression need to exist in the original TTree)
 // factory->SetWeightExpression( "var1", "Regression" );

//  TCut mycut = "ele1_isEB==1 && ele1_sigmaP/ele1_tkP<0.4 && ele1_fbrem>0 && abs(ele1_dxy_PV)<0.05 && abs(ele1_dz_PV)<0.05 && ele1_eRegrInput_etaW > 0.006 && ele1_eRegrInput_phiW<0.08 && ele1_eRegrInput_sigietaieta_bC1>0.006 && ele1_eRegrInput_sigiphiiphi_bC1>0.008  && abs(ele1_eRegrInput_Deta_bC_sC)<0.004 && abs(ele1_eRegrInput_Dphi_bC_sC)<0.04 && abs(ele1_eRegrInput_seedbC_etacry)<0.6 && abs(ele1_eRegrInput_seedbC_phicry)<0.6 && ele1_scE/ele1_scERaw<1.2 && (ele1_scE/ele1_E_true)<1.4 && (ele1_scE/ele1_E_true)>0.3"; // for example: TCut mycut = "abs(var1)<0.5 && abs(var2-0.5)<1";

  TCut mycut = "ele1_isEB==1 && ele1_sigmaP/ele1_tkP<0.4 && ele1_fbrem>0 && abs(ele1_dxy_PV)<0.05 && abs(ele1_dz_PV)<0.05 && ele1_eRegrInput_etaW > 0.006 && ele1_eRegrInput_phiW<0.08 && ele1_eRegrInput_sigietaieta_bC1>0.006 && ele1_eRegrInput_sigiphiiphi_bC1>0.008  && abs(ele1_eRegrInput_Deta_bC_sC)<0.004 && abs(ele1_eRegrInput_Dphi_bC_sC)<0.04 && abs(ele1_eRegrInput_seedbC_etacry)<0.6 && abs(ele1_eRegrInput_seedbC_phicry)<0.6 && ele1_scE/ele1_scERaw<1.2 && ele1_tkP/ele1_E_true<1.8 && ele1_tkP/ele1_E_true>0.2"; // for example: TCut mycut = "abs(var1)<0.5 && abs(var2-0.5)<1";


 // tell the factory to use all remaining events in the trees after training for testing:
 factory->PrepareTrainingAndTestTree( mycut, 
                                        "nTrain_Regression=2500000:nTest_Regression=2500000:SplitMode=Random:NormMode=NumEvents:!V" );
 
 TString Name = Form("weight_%s_%s_P_W",RegionOfTraining.c_str(),UseMethodFlag.c_str());
 (TMVA::gConfig().GetIONames()).fWeightFileDir = Name;
 } 

 if(RegionOfTraining=="EE"){

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

示例4: BJetRegression


//.........这里部分代码省略.........
   // 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( "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 inputVariables[] =  {"CSVJ1PtUncorr", "CSVJ1Pt", "CSVJ1Et", "CSVJ1Mt", "CSVJ1ptLeadTrk",
//                                               "CSVJ1Vtx3dL", "CSVJ1Vtx3deL", "CSVJ1vtxMass", "CSVJ1VtxPt",
//                                               "CSVJ1SoftLeptPtRel", "CSVJ1SoftLeptPt",
//                                               "CSVJ1SoftLeptdR" , "CSVJ1Ntot"};
   std::string inputVariables[] =  {"jetPtUncorr", "jetPt", "jetEt", "jetMt", "jetptLeadTrk",
                                              "jetVtx3dL", "jetVtx3deL", "jetvtxMass", "jetVtxPt",
                                              "jetSoftLeptPtRel", "jetSoftLeptPt",
                                              "jetSoftLeptdR" , "jetNtot", "jetJECUnc"}; //
   for(int ivar = 0; ivar < 14;  ivar++){
        factory->AddVariable( inputVariables[ivar], inputVariables[ivar], "units", 'F' );
    }
   // 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( "matchGenJet1Pt" ); 
   factory->AddTarget( "matchGenJetPt" ); 

   // 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 (see TMVAClassification for reading ASCII files)
   // load the signal and background event samples from ROOT trees
   TFile *input(0);
   TString fname = "/scratch/zmao/regression/allSample_both_isobTag.root";
   if (!gSystem->AccessPathName( fname )) 
      input = TFile::Open( fname ); // check if file in local directory exists
   else 
      input = TFile::Open( "http://root.cern.ch/files/tmva_reg_example.root" ); // if not: download from ROOT server
   
   if (!input) {
      std::cout << "ERROR: could not open data file" << std::endl;
      exit(1);
   }
   std::cout << "--- TMVARegression           : Using input file: " << input->GetName() << std::endl;

   // --- Register the regression tree

   TTree *regTree = (TTree*)input->Get("eventTree");

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

   // You can add an arbitrary number of regression trees
   factory->AddRegressionTree( regTree, regWeight );

   // This would set individual event weights (the variables defined in the 
   // expression need to exist in the original TTree)
开发者ID:zaixingmao,项目名称:H2hh2bbTauTau,代码行数:67,代码来源:BJetRegression.C

示例5: TrainRegressionFJ


//.........这里部分代码省略.........
    // 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");
    processes.push_back("ZnnH145");
    processes.push_back("ZnnH150");
#ifdef USE_WH
    processes.push_back("WlnH110");
    processes.push_back("WlnH115");
    processes.push_back("WlnH120");
    processes.push_back("WlnH125");
    processes.push_back("WlnH130");
    processes.push_back("WlnH135");
    processes.push_back("WlnH140");
    processes.push_back("WlnH145");
开发者ID:degrutto,项目名称:VHbbUF,代码行数:67,代码来源:TrainRegressionFJ.C

示例6: TMVARegression


//.........这里部分代码省略.........

   factory->AddVariable( "jet_eta", "jet_eta", "units", 'F' );
   factory->AddVariable( "jet_emfrac", "jet_emfrac", "units", 'F' );
   factory->AddVariable( "jet_hadfrac", "jet_hadfrac", "units", 'F' );
   factory->AddVariable( "jet_nconstituents", "jet_nconst", "units", 'F' );
   factory->AddVariable( "jet_vtx3dL", "jet_vtx3dL", "units", 'F' );
   factory->AddVariable( "MET", "MET", "units", 'F' );
   factory->AddVariable( "jet_dPhiMETJet", "jet_dPhiMETJet", "units", 'F' );
   
   //factory->AddVariable( "hJet_vtxPt", "hJet_vtxPt", "units", 'F' );
   //factory->AddVariable( "hJet_JECUnc", "hJet_JECUnc", "units", 'F' );
   //factory->AddVariable( "hJet_ptLeadTrack", "hJet_ptLeadTrack", "units", 'F' );
   //factory->AddVariable( "hJet_SoftLeptPtCut:=(hJet_SoftLeptIdlooseMu>0. || hJet_SoftLeptId95>0.) ? (hJet_SoftLeptPt) : (-99)", "hJet_SoftLeptPt", "units", 'F' );
   //factory->AddVariable( "hJet_En", "hJet_En", "units", 'F' );
   //factory->AddVariable( "hJet_Et", "hJet_Et", "units", 'F' );
   //factory->AddVariable( "hJet_Mt", "hJet_Mt", "units", 'F' );
   //factory->AddVariable( "hJet_nch", "hJet_nch", "units", 'F' );
   //factory->AddVariable( "hJet_vtx3deL", "hJet_vtx3deL", "units", 'F' );
   //factory->AddVariable( "hJet_vtxMass", "hJet_vtxMass", "units", 'F' );
   //factory->AddVariable( "hJet_ptRaw", "hJet_ptRaw", "units", 'F' );
   //factory->AddVariable( "hJet_EnRaw", "hJet_EnRaw", "units", 'F' );
   //factory->AddVariable( "hJet_SoftLeptptRelCut:=(hJet_SoftLeptIdlooseMu>0. || hJet_SoftLeptId95>0.) ? (hJet_SoftLeptptRel) : (-99)", "hJet_SoftLeptptRel", "units", 'F' );
   //factory->AddVariable( "hJet_SoftLeptdRCut:=(hJet_SoftLeptIdlooseMu>0. || hJet_SoftLeptId95>0.) ? (hJet_SoftLeptdR) : (-99)", "hJet_SoftLeptdR", "units", 'F' );
   //factory->AddVariable( "rho25", "rho25", "units", 'F' );
   //factory->AddVariable( "dPhiMETJet", "dPhiMETJet", "units", 'F' );


   // 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

   // Add the variable carrying the regression target
   //factory->AddTarget( "jet_genPt" ); 
   factory->AddTarget( "jet_genJetPt/jet_pt" ); 

   // 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 (see TMVAClassification for reading ASCII files)
   // load the signal and background event samples from ROOT trees
/*   TFile *input(0);
   TString fname = "./tmva_reg_example.root";
   if (!gSystem->AccessPathName( fname )) 
      input = TFile::Open( fname ); // check if file in local directory exists
   else 
      input = TFile::Open( "http://root.cern.ch/files/tmva_reg_example.root" ); // if not: download from ROOT server
   
   if (!input) {
      std::cout << "ERROR: could not open data file" << std::endl;
      exit(1);
   }
   std::cout << "--- TMVARegression           : Using input file: " << input->GetName() << std::endl;

   // --- Register the regression tree

   TTree *regTree = (TTree*)input->Get("TreeR");
*/

   TChain chainTraining("Events");
   chainTraining.Add("TrainingFiles/training.root");
   TTree *regTreeTraining = (TTree*) chainTraining;

   TChain chainTesting("Events");
   chainTesting.Add("TrainingFiles/testing.root");
   TTree *regTreeTesting = (TTree*) chainTesting;
开发者ID:hebda,项目名称:ggAnalysis,代码行数:67,代码来源:TMVARegression.C

示例7: TMVARegression


//.........这里部分代码省略.........
   // 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( "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" )]
//    factory->AddVariable( "laser.qmax", "Qmax", "ADC", 'D' );
//    factory->AddVariable( "laser.tmax", "T_{0}", "ns", 'D' );
//    factory->AddVariable( "laser.fwhm", "FWHM","ns", 'D');
//    factory->AddVariable( "laser.prepulse","Prepulse indicator","A.U.", 'D' );
//    factory->AddVariable( "laser.w10","Width at 10%","ns", 'D' );

   factory->AddVariable( "qmax[0]", "Qmax", "ADC", 'D' );
   factory->AddVariable( "tmax[0]", "T_{0}", "ns", 'D' );
   factory->AddVariable( "l_fwhm[0]", "FWHM","ns", 'D');
   factory->AddVariable( "l_prepulse[0]","Prepulse indicator","A.U.", 'D' );
   factory->AddVariable( "l_width90[0]","Width at 10%","ns", 'D' );

   // 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:=timeStamp",  "Spectator 1", "units", 'F' );

   // Add the variable carrying the regression target
   factory->AddTarget  ( "apdpnAB[0]" ); 

   // 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 (see TMVAClassification for reading ASCII files)
   // load the signal and background event samples from ROOT trees
//    TFile *input(0);
//    TString fname = "./stabTreeFed630.root";
//    if (!gSystem->AccessPathName( fname )) {
//       input = TFile::Open( fname ); // check if file in local directory exists
//    } 

//    if (!input) {
//       std::cout << "ERROR: could not open data file" << std::endl;
//       exit(1);
//    }
//    std::cout << "--- TMVARegression           : Using input file: " << input->GetName() << std::endl;


   TChain * ntu = new TChain("x");
   ntu->Add("/data2/EcalLaserMonitoringData/ntuples_2011_158851_178888/ntu_data_0015*.root");
   ntu->Add("/data2/EcalLaserMonitoringData/ntuples_2011_158851_178888/ntu_data_0016*.root");

   //TTree *regTree = (TTree*)input->Get("ntu");

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

   // ====== register trees ====================================================
   //
   // the following method is the prefered one:
开发者ID:martinamalberti,项目名称:UserCode,代码行数:67,代码来源:TMVARegression.C

示例8: autoencoder

TString autoencoder (std::string inputFileName) 
{

    std::string tmstr (now ());
    TString tmstmp (tmstr.c_str ());
   
  
    std::cout << "==> Start Autoencoder " << std::endl;
    std::cout << "-------------------- open input file ---------------- " << std::endl;
    TString fname = pathToData + TString (inputFileName.c_str ()) + TString (".root");
    TFile *input = TFile::Open( fname );

    std::cout << "-------------------- get tree ---------------- " << std::endl;
    TTree *tree     = (TTree*)input->Get("data");
   
    TString outfileName( "TMVAAutoEnc__" );
    outfileName += TString (inputFileName.c_str ()) + TString ("__") + tmstmp + TString (".root");

    std::cout << "-------------------- open output file ---------------- " << std::endl;
    TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

    std::cout << "-------------------- prepare factory ---------------- " << std::endl;
    TMVA::Factory *factory = new TMVA::Factory( "TMVAAutoencoder", outputFile,
						"AnalysisType=Regression:Color:DrawProgressBar" );
    std::cout << "-------------------- add variables ---------------- " << std::endl;


    for (auto varname : variableNames+additionalVariableNames)
    {
	factory->AddVariable (varname.c_str (), 'F');
	factory->AddTarget   (varname.c_str (), 'F');
    }



    std::cout << "-------------------- add tree ---------------- " << std::endl;
    // global event weights per tree (see below for setting event-wise weights)
    Double_t regWeight  = 1.0;   
    factory->AddRegressionTree (tree, regWeight);

   
    std::cout << "-------------------- prepare ---------------- " << std::endl;
    TCut mycut = ""; // for example: TCut mycut = "abs(var1)<0.5 && abs(var2-0.5)<1";
    factory->PrepareTrainingAndTestTree( mycut, 
					 "nTrain_Regression=0:nTest_Regression=0:SplitMode=Random:NormMode=NumEvents:!V" );


    /* // This would set individual event weights (the variables defined in the  */
    /* // expression need to exist in the original TTree) */
    /* factory->SetWeightExpression( "var1", "Regression" ); */


    if (true)
    {
	TString layoutString ("Layout=TANH|100,TANH|20,TANH|40,LINEAR");

	TString training0 ("LearningRate=1e-5,Momentum=0.5,Repetitions=1,ConvergenceSteps=500,BatchSize=50,TestRepetitions=7,WeightDecay=0.01,Regularization=NONE,DropConfig=0.5+0.5+0.5+0.5,DropRepetitions=2");
	TString training1 ("LearningRate=1e-5,Momentum=0.9,Repetitions=1,ConvergenceSteps=500,BatchSize=30,TestRepetitions=7,WeightDecay=0.01,Regularization=L2,DropConfig=0.1+0.1+0.1,DropRepetitions=1");
	TString training2 ("LearningRate=1e-4,Momentum=0.3,Repetitions=1,ConvergenceSteps=10,BatchSize=40,TestRepetitions=7,WeightDecay=0.1,Regularization=L2");
	TString training3 ("LearningRate=1e-5,Momentum=0.1,Repetitions=1,ConvergenceSteps=10,BatchSize=10,TestRepetitions=7,WeightDecay=0.001,Regularization=NONE");

	TString trainingStrategyString ("TrainingStrategy=");
	trainingStrategyString += training0 + "|" + training1 + "|" + training2 ; //+ "|" + training3;

       
	//       TString trainingStrategyString ("TrainingStrategy=LearningRate=1e-1,Momentum=0.3,Repetitions=3,ConvergenceSteps=20,BatchSize=30,TestRepetitions=7,WeightDecay=0.0,L1=false,DropFraction=0.0,DropRepetitions=5");

	TString nnOptions ("!H:V:ErrorStrategy=SUMOFSQUARES:VarTransform=N:WeightInitialization=XAVIERUNIFORM");
	//       TString nnOptions ("!H:V:VarTransform=Normalize:ErrorStrategy=CHECKGRADIENTS");
	nnOptions.Append (":"); nnOptions.Append (layoutString);
	nnOptions.Append (":"); nnOptions.Append (trainingStrategyString);

	factory->BookMethod( TMVA::Types::kNN, TString("NN_")+tmstmp, nnOptions ); // NN
    }


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

    outputFile->Close();

//    TMVA::TMVARegGui (outfileName);
   
    delete factory;
    return TString("NN_")+tmstmp;
}
开发者ID:bortigno,项目名称:tmva,代码行数:89,代码来源:competition.c


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