ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/MultivariateAnalysis/macros/TMVAnalysis_QCD-el.C
Revision: 1.2
Committed: Thu May 21 16:38:01 2009 UTC (15 years, 11 months ago) by jindal
Content type: text/plain
Branch: MAIN
CVS Tags: V00-03-01, ZMorph_BASE_20100408, gak040610_morphing, V00-02-02, gak011410, gak010310, ejterm2010_25nov2009, V00-02-01, V00-02-00, gak112409, CMSSW_22X_branch_base, segala101609, V00-01-15, HEAD
Branch point for: ZMorph-V00-03-01, CMSSW_22X_branch
Changes since 1.1: +22 -21 lines
Log Message:
update

File Contents

# User Rev Content
1 jindal 1.2 // @(#)root/tmva $Id: TMVAnalysis_QCD-el.C,v 1.1 2009/05/14 17:08:04 jindal Exp $
2 jindal 1.1 /**********************************************************************************
3     * Project : TMVA - a Root-integrated toolkit for multivariate data analysis *
4     * Package : TMVA *
5     * Root Macro: TMVAnalysis *
6     * *
7     * This macro provides examples for the training and testing of all the *
8     * TMVA classifiers. *
9     * *
10     * As input data is used a toy-MC sample consisting of four Gaussian-distributed *
11     * and linearly correlated input variables. *
12     * *
13     * The methods to be used can be switched on and off by means of booleans, or *
14     * via the prompt command, for example: *
15     * *
16     * root -l TMVAnalysis.C\(\"Fisher,Likelihood\"\) *
17     * *
18     * (note that the backslashes are mandatory) *
19     * *
20     * The output file "TMVA.root" can be analysed with the use of dedicated *
21     * macros (simply say: root -l <macro.C>), which can be conveniently *
22     * invoked through a GUI that will appear at the end of the run of this macro. *
23     **********************************************************************************/
24    
25     #include <iostream>
26    
27     #include "TCut.h"
28     #include "TFile.h"
29     #include "TSystem.h"
30     #include "TTree.h"
31     // requires links
32     #include "TMVA/Factory.h"
33     #include "TMVA/Tools.h"
34     #include "TMVA/Config.h"
35    
36     #include "TMVAGui.C"
37    
38     // ---------------------------------------------------------------
39     // choose MVA methods to be trained + tested
40     Bool_t Use_Cuts = 0;
41     Bool_t Use_CutsD = 0;
42     Bool_t Use_CutsGA = 1;
43     // ---
44     Bool_t Use_Likelihood = 1;
45     Bool_t Use_LikelihoodD = 0; // the "D" extension indicates decorrelated input variables (see option strings)
46     Bool_t Use_LikelihoodPCA = 1; // the "PCA" extension indicates PCA-transformed input variables (see option strings)
47     Bool_t Use_LikelihoodKDE = 0;
48     Bool_t Use_LikelihoodMIX = 0;
49     // ---
50     Bool_t Use_PDERS = 1;
51     Bool_t Use_PDERSD = 0;
52     Bool_t Use_PDERSPCA = 0;
53     Bool_t Use_KNN = 1;
54     // ---
55     Bool_t Use_HMatrix = 1;
56     Bool_t Use_Fisher = 1;
57     // ---
58     Bool_t Use_FDA_GA = 0;
59     Bool_t Use_FDA_MC = 0;
60     Bool_t Use_FDA_SA = 0;
61     Bool_t Use_FDA_MT = 1;
62     Bool_t Use_FDA_GAMT = 0;
63     Bool_t Use_FDA_MCMT = 0;
64     // ---
65     Bool_t Use_MLP = 1; // this is the recommended ANN
66     Bool_t Use_CFMlpANN = 0;
67     Bool_t Use_TMlpANN = 0;
68     // ---
69     Bool_t Use_BDT = 1;
70     Bool_t Use_BDTD = 0;
71     // ---
72     Bool_t Use_RuleFitTMVA = 1;
73     Bool_t Use_RuleFitJF = 0;
74     // ---
75     Bool_t Use_SVM_Gauss = 1;
76     Bool_t Use_SVM_Poly = 0;
77     Bool_t Use_SVM_Lin = 0;
78     // ---------------------------------------------------------------
79    
80     // read input data file with ascii format (otherwise ROOT) ?
81     Bool_t ReadDataFromAsciiIFormat = kFALSE;
82    
83     void TMVAnalysis( TString myMethodList = "" )
84     {
85     // explicit loading of the shared libTMVA is done in TMVAlogon.C, defined in .rootrc
86     // if you use your private .rootrc, or run from a different directory, please copy the
87     // corresponding lines from .rootrc
88    
89     // methods to be processed can be given as an argument; use format:
90     //
91     // mylinux~> root -l TMVAnalysis.C\(\"myMethod1,myMethod2,myMethod3\"\)
92     //
93     TList* mlist = TMVA::Tools::ParseFormatLine( myMethodList, " :," );
94    
95     if (mlist->GetSize()>0) {
96     Use_CutsGA = Use_CutsD = Use_Cuts
97     = Use_LikelihoodKDE = Use_LikelihoodMIX = Use_LikelihoodPCA = Use_LikelihoodD = Use_Likelihood
98     = Use_PDERSPCA = Use_PDERSD = Use_PDERS
99     = Use_KNN
100     = Use_MLP = Use_CFMlpANN = Use_TMlpANN
101     = Use_HMatrix = Use_Fisher = Use_BDTD = Use_BDT
102     = Use_RuleFitTMVA = Use_RuleFitJF
103     = Use_SVM_Gauss = Use_SVM_Poly = Use_SVM_Lin
104     = Use_FDA_GA = Use_FDA_MC = Use_FDA_SA = Use_FDA_MT = Use_FDA_GAMT = Use_FDA_MCMT
105     = 0;
106    
107     if (mlist->FindObject( "Cuts" ) != 0) Use_Cuts = 1;
108     if (mlist->FindObject( "CutsD" ) != 0) Use_CutsD = 1;
109     if (mlist->FindObject( "CutsGA" ) != 0) Use_CutsGA = 1;
110     if (mlist->FindObject( "Likelihood" ) != 0) Use_Likelihood = 1;
111     if (mlist->FindObject( "LikelihoodD" ) != 0) Use_LikelihoodD = 1;
112     if (mlist->FindObject( "LikelihoodPCA" ) != 0) Use_LikelihoodPCA = 1;
113     if (mlist->FindObject( "LikelihoodKDE" ) != 0) Use_LikelihoodKDE = 1;
114     if (mlist->FindObject( "LikelihoodMIX" ) != 0) Use_LikelihoodMIX = 1;
115     if (mlist->FindObject( "PDERSPCA" ) != 0) Use_PDERSPCA = 1;
116     if (mlist->FindObject( "PDERSD" ) != 0) Use_PDERSD = 1;
117     if (mlist->FindObject( "PDERS" ) != 0) Use_PDERS = 1;
118     if (mlist->FindObject( "KNN" ) != 0) Use_KNN = 1;
119     if (mlist->FindObject( "HMatrix" ) != 0) Use_HMatrix = 1;
120     if (mlist->FindObject( "Fisher" ) != 0) Use_Fisher = 1;
121     if (mlist->FindObject( "MLP" ) != 0) Use_MLP = 1;
122     if (mlist->FindObject( "CFMlpANN" ) != 0) Use_CFMlpANN = 1;
123     if (mlist->FindObject( "TMlpANN" ) != 0) Use_TMlpANN = 1;
124     if (mlist->FindObject( "BDTD" ) != 0) Use_BDTD = 1;
125     if (mlist->FindObject( "BDT" ) != 0) Use_BDT = 1;
126     if (mlist->FindObject( "RuleFitJF" ) != 0) Use_RuleFitJF = 1;
127     if (mlist->FindObject( "RuleFitTMVA" ) != 0) Use_RuleFitTMVA = 1;
128     if (mlist->FindObject( "SVM_Gauss" ) != 0) Use_SVM_Gauss = 1;
129     if (mlist->FindObject( "SVM_Poly" ) != 0) Use_SVM_Poly = 1;
130     if (mlist->FindObject( "SVM_Lin" ) != 0) Use_SVM_Lin = 1;
131     if (mlist->FindObject( "FDA_MC" ) != 0) Use_FDA_MC = 1;
132     if (mlist->FindObject( "FDA_GA" ) != 0) Use_FDA_GA = 1;
133     if (mlist->FindObject( "FDA_SA" ) != 0) Use_FDA_SA = 1;
134     if (mlist->FindObject( "FDA_MT" ) != 0) Use_FDA_MT = 1;
135     if (mlist->FindObject( "FDA_GAMT" ) != 0) Use_FDA_GAMT = 1;
136     if (mlist->FindObject( "FDA_MCMT" ) != 0) Use_FDA_MCMT = 1;
137    
138     delete mlist;
139     }
140    
141     std::cout << "Start Test TMVAnalysis" << std::endl
142     << "======================" << std::endl
143     << std::endl;
144     std::cout << "Testing all standard methods may take about 10 minutes of running..." << std::endl;
145    
146     // Create a new root output file.
147     TString outfileName( "TMVA_QCD.root" );
148     TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
149    
150     // Create the factory object. Later you can choose the methods
151     // whose performance you'd like to investigate. The factory will
152     // then run the performance analysis for you.
153     //
154     // The first argument is the base of the name of all the
155     // weightfiles in the directory weight/
156     //
157     // The second argument is the output file for the training results
158     TMVA::Factory *factory = new TMVA::Factory( "TMVAnalysis", outputFile, Form("V:%sColor", gROOT->IsBatch()?"!":"") );
159    
160     // if you wish to modify default settings
161     // (please check "src/Config.h" to see all available global options)
162     // (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
163     // (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";
164    
165     if (ReadDataFromAsciiIFormat) {
166     // load the signal and background event samples from ascii files
167     // format in file must be:
168     // var1/F:var2/F:var3/F:var4/F
169     // 0.04551 0.59923 0.32400 -0.19170
170     // ...
171    
172     TString datFileS = "data/toy_sig_lincorr.dat";
173     TString datFileB = "data/toy_bkg_lincorr.dat";
174     if (!factory->SetInputTrees( datFileS, datFileB )) exit(1);
175     }
176     else {
177     // load the signal and background event samples from ROOT trees
178     TFile *input(0);
179     //TString fname = "./tmva_training.root";
180     //TString fname = "./tmva_training-12sep2008.root";
181     //TString fname = "./tmva_training-15sep2008.root";
182     //TString fname = "./tmva_training-17sep2008.root";
183     //TString fname = "./tmva_training-20nov2008.root";
184     //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/training/tmva_training-summer08-22dec2008.root";
185     //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/training/tmva_training-summer08-09jan2009.root";
186     //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/training/tmva_training_noQCD-summer08-06feb2009.root";
187     //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/training/tmva_training-summer08-25feb2009.root";
188     //TString fname = "muon_jets_training-summer08-08apr2009.root";
189 jindal 1.2 TString fname = "/uscms_data/d2/lpcljm/MVA/Summer08/training/electron_jets_training-wzfastsim-summer08-15may2009.root";
190 jindal 1.1 if (!gSystem->AccessPathName( fname )) {
191     // first we try to find tmva_example.root in the local directory
192     std::cout << "--- TMVAnalysis : accessing " << fname << std::endl;
193     input = TFile::Open( fname );
194     }
195     else {
196     // second we try accessing the file via the web from
197     // http://root.cern.ch/files/tmva_example.root
198     std::cout << "--- TMVAnalysis : accessing tmva_example.root file from http://root.cern.ch/files" << std::endl;
199     std::cout << "--- TMVAnalysis : for faster startup you may consider downloading it into you local directory" << std::endl;
200     input = TFile::Open( "http://root.cern.ch/files/tmva_example.root" );
201     }
202    
203     if (!input) {
204     std::cout << "ERROR: could not open data file" << std::endl;
205     exit(1);
206     }
207    
208     TTree *signal = (TTree*)input->Get("ttbar");
209     //TTree *background = (TTree*)input->Get("wzjets");
210     TTree *background = (TTree*)input->Get("qcd");
211    
212     // global event weights (see below for setting event-wise weights)
213     Double_t signalWeight = 1.0;
214     Double_t backgroundWeight = 1.0;
215    
216     factory->AddSignalTree ( signal, signalWeight );
217     factory->AddBackgroundTree( background, backgroundWeight );
218     }
219    
220     // Define the input variables that shall be used for the MVA training
221     // note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
222     // [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
223    
224     /*
225     factory->AddVariable("getHt3", 'F');
226     factory->AddVariable("aplanarity", 'F');
227     factory->AddVariable("dPhiLMet", 'F');
228     factory->AddVariable("sphericity", 'F');
229     factory->AddVariable("jet1Jet2DeltaR", 'F');
230     factory->AddVariable("leptonJetDeltaR", 'F');
231     */
232     //
233     //_____ D0 vars ______________________________________________________
234     //
235     /*
236     //factory->AddVariable("ht", 'F');
237     factory->AddVariable("ht2p", 'F');
238     //factory->AddVariable("et3", 'F');
239     //factory->AddVariable("metHtPlusLepton", 'F'); // degenerates L: causes a peak at zero
240     //factory->AddVariable("htPlusLepton", 'F');// degenerates L: causes a peak at zero
241     factory->AddVariable("sphericity", 'F');
242     factory->AddVariable("aplanarity", 'F');
243     factory->AddVariable("jet1Jet2DeltaR", 'F');
244     factory->AddVariable("maxJetEta", 'F');
245     //factory->AddVariable("h", 'F');
246     factory->AddVariable("jet1_eta", 'F');
247     factory->AddVariable("jet2_eta", 'F');
248     //factory->AddVariable("hz", 'F');
249     factory->AddVariable("dPhiLMet", 'F');
250     factory->AddVariable("minDiJetDeltaR", 'F');
251     factory->AddVariable("leptonJetDeltaR", 'F');
252     factory->AddVariable("DphiJMET", 'F');
253     */
254     //
255     /*
256     factory->AddVariable("aplanarity", 'F');
257     factory->AddVariable("getHt3", 'F');
258     factory->AddVariable("ktMinPrime", 'F');
259     factory->AddVariable("DphiJMET", 'F');
260     factory->AddVariable("W_MT", 'F');
261     */
262     //
263     //_____ BDT test vars ________________________________________________
264     //
265     /*
266     factory->AddVariable("aplanarity", 'F');
267     factory->AddVariable("et3", 'F');
268     factory->AddVariable("getEta2Sum", 'F');
269     factory->AddVariable("getKtminpReduced", 'F');
270     factory->AddVariable("getMdijetMin", 'F');
271     factory->AddVariable("ht", 'F');
272     factory->AddVariable("jet1Jet2DeltaR", 'F');
273     factory->AddVariable("jet1Jet2_M", 'F');
274     factory->AddVariable("lepton_eta", 'F');
275     factory->AddVariable("maxJetEta", 'F');
276     factory->AddVariable("metHtPlusLepton", 'F'); // degenerates L: causes a peak at zero
277     factory->AddVariable("minDiJetDeltaR", 'F');
278     factory->AddVariable("minDijetMass", 'F');
279     factory->AddVariable("sphericity", 'F');
280     //
281     */
282    
283 jindal 1.2 /*
284 jindal 1.1 //_____ "best" set for BDT wzjets ____________________________________
285     //
286     factory->AddVariable("jet3_pt", 'F');
287     factory->AddVariable("jet4_pt", 'F');
288     factory->AddVariable("jet2_pt", 'F');
289     factory->AddVariable("met_pt", 'F');
290     // factory->AddVariable("lepton_energy", 'F');
291     factory->AddVariable("metHtPlusLepton", 'F');
292     factory->AddVariable("getHt", 'F');
293     factory->AddVariable("htPlusLepton", 'F');// degenerates L: causes a peak at zero
294     factory->AddVariable("jet1_pt", 'F');
295     factory->AddVariable("getHt3", 'F');
296     factory->AddVariable("getHt2", 'F');
297     factory->AddVariable("sphericity", 'F');
298     factory->AddVariable("getAplMu", 'F');
299     factory->AddVariable("getHt2p", 'F');
300     factory->AddVariable("dPhiLMet", 'F');
301 jindal 1.2 */
302 jindal 1.1
303 jindal 1.2
304 jindal 1.1 //_____ "best" set for BDT multijets ____________________________________
305     //
306    
307    
308 jindal 1.2 factory->AddVariable("metHtPlusLepton", 'F'); // degenerates L: causes a peak at zero
309     factory->AddVariable("lepton_pt", 'F');
310 jindal 1.1 factory->AddVariable("jet4_pt", 'F');
311 jindal 1.2 factory->AddVariable("getAplMu", 'F');
312     factory->AddVariable("dPhiLMet", 'F');
313 jindal 1.1 factory->AddVariable("W_Pt", 'F'); // MET
314 jindal 1.2 factory->AddVariable("met_pt", 'F');
315 jindal 1.1 factory->AddVariable("W_MT", 'F'); // MET
316     factory->AddVariable("lepton_eta", 'F');
317     factory->AddVariable("getMwRec", 'F');
318 jindal 1.2 factory->AddVariable("sphericity", 'F');
319     factory->AddVariable("jet1_pt", 'F');
320     factory->AddVariable("htPlusLepton", 'F');// degenerates L: causes a peak at zero
321     factory->AddVariable("DphiJMET", 'F');
322     factory->AddVariable("getHt3", 'F');
323 jindal 1.1
324    
325    
326 jindal 1.2
327    
328     //
329 jindal 1.1 /*
330     //_____ all variables (not ranked) ___________________________________
331     //
332    
333     factory->AddVariable("DphiJMET", 'F');
334     factory->AddVariable("dPhiLMet", 'F');
335     factory->AddVariable("W_MT", 'F'); // MET
336     factory->AddVariable("W_Pt", 'F'); // MET
337     factory->AddVariable("getApl", 'F');
338     factory->AddVariable("getAplMu", 'F'); // identical to aplanarity (machine precision)
339     factory->AddVariable("getCen", 'F'); // identical to centrality
340     factory->AddVariable("getSph", 'F');
341     factory->AddVariable("getDrMinJetJet", 'F');
342     factory->AddVariable("getEta2Sum", 'F');
343     factory->AddVariable("getH", 'F');
344     factory->AddVariable("getHt", 'F'); // identical to ht
345     factory->AddVariable("getHt2", 'F'); // identical to HT2
346     factory->AddVariable("getHt2p", 'F'); // identical to ht2p
347     factory->AddVariable("getHt2pp", 'F');
348     factory->AddVariable("getHt3", 'F');
349     factory->AddVariable("getHt3p", 'F');
350     factory->AddVariable("getHt3pp", 'F');
351     factory->AddVariable("getHtp", 'F');
352     factory->AddVariable("getHtpp", 'F');
353     factory->AddVariable("getJetEtaMax", 'F');
354     factory->AddVariable("getKtminp", 'F');
355     factory->AddVariable("getKtminpReduced", 'F'); // ktmin
356     factory->AddVariable("getMdijetMin", 'F');
357     factory->AddVariable("getMtjets", 'F');
358     factory->AddVariable("getMwRec", 'F');
359     factory->AddVariable("getPzOverHT", 'F');
360     factory->AddVariable("htPlusLepton", 'F');// degenerates L: causes a peak at zero
361     factory->AddVariable("hz", 'F'); // ???MET
362     factory->AddVariable("jet1Jet2DeltaPhi", 'F');
363     factory->AddVariable("jet1Jet2DeltaR", 'F');
364     factory->AddVariable("jet1Jet2W_M", 'F');
365     factory->AddVariable("jet1Jet2_Pt", 'F');
366     factory->AddVariable("jet1Jet2_M", 'F');
367     factory->AddVariable("jet1_energy", 'F');
368     factory->AddVariable("jet1_eta", 'F');
369     factory->AddVariable("jet1_phi", 'F');
370     factory->AddVariable("jet1_pt", 'F');
371     factory->AddVariable("jet2_energy", 'F');
372     factory->AddVariable("jet2_eta", 'F');
373     factory->AddVariable("jet2_phi", 'F');
374     factory->AddVariable("jet2_pt", 'F');
375     factory->AddVariable("jet3_energy", 'F');
376     factory->AddVariable("jet3_eta", 'F');
377     factory->AddVariable("jet3_phi", 'F');
378     factory->AddVariable("jet3_pt", 'F');
379     factory->AddVariable("jet4_energy", 'F');
380     factory->AddVariable("jet4_eta", 'F');
381     factory->AddVariable("jet4_phi", 'F');
382     factory->AddVariable("jet4_pt", 'F');
383 jindal 1.2 //factory->AddVariable("ktMinPrime", 'F');
384 jindal 1.1 // factory->AddVariable("leptonJetDeltaR", 'F');
385     factory->AddVariable("lepton_energy", 'F');
386     factory->AddVariable("lepton_eta", 'F');
387     factory->AddVariable("lepton_phi", 'F');
388     factory->AddVariable("lepton_pt", 'F');
389     factory->AddVariable("metHtPlusLepton", 'F'); // degenerates L: causes a peak at zero
390     factory->AddVariable("met_phi", 'F');
391     factory->AddVariable("met_pt", 'F');
392     factory->AddVariable("sphericity", 'F');
393 jindal 1.2
394     */
395 jindal 1.1 //______ duplicates __________________________________________________
396     //
397     /*
398     factory->AddVariable("minDiJetDeltaR", 'F'); // getDrMinJetJet
399     factory->AddVariable("minDijetMass", 'F'); // getMdijetMin
400     factory->AddVariable("maxJetEta", 'F'); // getJetEtaMax
401     factory->AddVariable("ht", 'F'); // getHt
402     factory->AddVariable("h", 'F'); // getH
403     factory->AddVariable("ht2p", 'F'); // identical to getHt2p
404     factory->AddVariable("HT2prime", 'F'); // ht2p
405     factory->AddVariable("HT2", 'F'); // identical to getHt2
406     factory->AddVariable("aplanarity", 'F'); // identical to getApl (machine precision)
407     factory->AddVariable("centrality", 'F'); // getCen
408     */
409     //
410     //_____ variables probably not for MVA _______________________________
411     //
412     /*
413     factory->AddVariable("met_eta", 'F'); // not filled?
414     factory->AddVariable("lepton_track_iso", 'F');
415     factory->AddVariable("lepton_calo_iso", 'F');
416     factory->AddVariable("n_electrons", 'F');
417     factory->AddVariable("n_jets", 'F');
418     factory->AddVariable("n_jets", 'F');
419     factory->AddVariable("n_met", 'F');
420     factory->AddVariable("n_muons", 'F');
421     factory->AddVariable("n_tagged_jets_jetProb_loose", 'F');
422     factory->AddVariable("n_tagged_jets_jetProb_medium", 'F');
423     factory->AddVariable("n_tagged_jets_jetProb_tight", 'F');
424     factory->AddVariable("n_tagged_jets_trackCounting_loose", 'F');
425     factory->AddVariable("n_tagged_jets_trackCounting_medium", 'F');
426     factory->AddVariable("n_tagged_jets_trackCounting_tight", 'F');
427     factory->AddVariable("electron_id_loose", 'F');
428     factory->AddVariable("electron_id_robust", 'F');
429     factory->AddVariable("electron_id_tight", 'F');
430     factory->AddVariable("electron_tdrid_loose", 'F');
431     factory->AddVariable("electron_tdrid_medium", 'F');
432     factory->AddVariable("electron_tdrid_tight", 'F');
433     */
434    
435     // This would set individual event weights (the variables defined in the
436     // expression need to exist in the original TTree)
437     factory->SetWeightExpression("event_weight");
438    
439     // Apply additional cuts on the signal and background sample.
440     //gROOT->Macro("./cuts.C");
441     //TCut mycut = "et3<500.0 && getHt3<500.0"; // for LL ratio, cut tails
442     TCut mycut = "";
443    
444     // tell the factory to use all remaining events in the trees after training for testing:
445     //TString split_opt = "NSigTrain=3000:NBkgTrain=638:SplitMode=Random:NormMode=NumEvents:!V";
446     //TString split_opt = "NSigTrain=3000:NBkgTrain=1510:SplitMode=Random:NormMode=NumEvents:!V";
447     //TString split_opt = "NSigTrain=60000:NBkgTrain=6000:SplitMode=Random:NormMode=NumEvents:!V";
448     //TString split_opt = "NSigTrain=30000:NBkgTrain=1668:SplitMode=Random:NormMode=NumEvents:!V";
449     //TString split_opt = "NSigTrain=26000:NBkgTrain=1061:SplitMode=Random:NormMode=NumEvents:V";
450 jindal 1.2 TString split_opt = "NSigTrain=10000:NBkgTrain=10000:SplitMode=Random:NormMode=NumEvents:!V";
451 jindal 1.1
452     factory->PrepareTrainingAndTestTree( mycut, split_opt );
453    
454    
455     // ===> Set a different testing tree
456     //FIXME:
457     //factory->AddSignalTree();
458    
459    
460     // If no numbers of events are given, half of the events in the tree are used for training, and
461     // the other half for testing:
462     // factory->PrepareTrainingAndTestTree( mycut, "SplitMode=random:!V" );
463     // To also specify the number of testing events, use:
464     // factory->PrepareTrainingAndTestTree( mycut,
465     // "NSigTrain=3000:NBkgTrain=3000:NSigTest=3000:NBkgTest=3000:SplitMode=Random:!V" );
466    
467     // ---- Book MVA methods
468     //
469     // please lookup the various method configuration options in the corresponding cxx files, eg:
470     // src/MethoCuts.cxx, etc.
471     // it is possible to preset ranges in the option string in which the cut optimisation should be done:
472     // "...:CutRangeMin[2]=-1:CutRangeMax[2]=1"...", where [2] is the third input variable
473    
474     // Cut optimisation
475     if (Use_Cuts)
476     factory->BookMethod( TMVA::Types::kCuts, "Cuts",
477     "!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart" );
478    
479     if (Use_CutsD)
480     factory->BookMethod( TMVA::Types::kCuts, "CutsD",
481     "!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart:VarTransform=Decorrelate" );
482    
483     if (Use_CutsGA)
484     factory->BookMethod( TMVA::Types::kCuts, "CutsGA",
485     "!H:!V:FitMethod=GA:EffSel:Steps=30:Cycles=3:PopSize=100:SC_steps=10:SC_rate=5:SC_factor=0.95:VarProp=FSmart" );
486    
487     // Likelihood
488     if (Use_Likelihood)
489     factory->BookMethod( TMVA::Types::kLikelihood, "Likelihood",
490     "H:V:!TransformOutput:PDFInterpol=Spline2:\
491     NSmooth=0:NSmoothSig=0:NSmoothBkg=5:\
492     NAvEvtPerBin=50:NAvEvtPerBinSig=50:NAvEvtPerBinBkg=50:\
493     CreateMVAPdfs=True:NbinsMVAPdf=15" );
494    
495    
496    
497     // test the decorrelated likelihood
498     if (Use_LikelihoodD)
499     factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodD",
500     "!H:!V:!TransformOutput:PDFInterpol=Spline3:\
501     NSmooth=0:NSmoothSig=0:NSmoothBkg=0:\
502     NAvEvtPerBin=50:NAvEvtPerBinSig=50:NAvEvtPerBinBkg=50:\
503     VarTransform=Decorrelate:\
504     NSmoothSig[0]=0:NSmoothBkg[0]=0" );
505    
506     if (Use_LikelihoodPCA)
507     factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodPCA",
508     "!H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=100:NSmoothBkg[0]=10:NSmooth=5:NAvEvtPerBin=50:VarTransform=PCA" );
509    
510     // test the new kernel density estimator
511     if (Use_LikelihoodKDE)
512     factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodKDE",
513     "!H:!V:!TransformOutput:PDFInterpol=KDE:KDEtype=Gauss:KDEiter=Nonadaptive:KDEborder=None:NAvEvtPerBin=50" );
514    
515     // test the mixed splines and kernel density estimator (depending on which variable)
516     if (Use_LikelihoodMIX)
517     factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodMIX",
518     "!H:!V:!TransformOutput:PDFInterpol[0]=KDE:PDFInterpol[1]=KDE:PDFInterpol[2]=Spline2:PDFInterpol[3]=Spline2:KDEtype=Gauss:KDEiter=Nonadaptive:KDEborder=None:NAvEvtPerBin=50" );
519    
520     // PDE - RS method
521     if (Use_PDERS)
522     factory->BookMethod( TMVA::Types::kPDERS, "PDERS",
523     "!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:InitialScale=0.99" );
524    
525     if (Use_PDERSD)
526     factory->BookMethod( TMVA::Types::kPDERS, "PDERSD",
527     "!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:InitialScale=0.99:VarTransform=Decorrelate" );
528    
529     if (Use_PDERSPCA)
530     factory->BookMethod( TMVA::Types::kPDERS, "PDERSPCA",
531     "!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:InitialScale=0.99:VarTransform=PCA" );
532    
533     // K-Nearest Neighbour classifier (KNN)
534     if (Use_KNN)
535     factory->BookMethod( TMVA::Types::kKNN, "KNN",
536     "nkNN=40:TreeOptDepth=6:ScaleFrac=0.8:!UseKernel:!Trim" );
537    
538     // H-Matrix (chi2-squared) method
539     if (Use_HMatrix)
540     factory->BookMethod( TMVA::Types::kHMatrix, "HMatrix", "!H:!V" );
541    
542     // Fisher discriminant
543     if (Use_Fisher)
544     factory->BookMethod( TMVA::Types::kFisher, "Fisher",
545     "H:!V:!Normalise:CreateMVAPdfs:Fisher:NbinsMVAPdf=50:NsmoothMVAPdf=1" );
546    
547     // Function discrimination analysis (FDA) -- test of various fitters - the recommended one is Minuit or GA
548     if (Use_FDA_MC)
549     factory->BookMethod( TMVA::Types::kFDA, "FDA_MC",
550     "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:SampleSize=100000:Sigma=0.1" );
551    
552     if (Use_FDA_GA)
553     factory->BookMethod( TMVA::Types::kFDA, "FDA_GA",
554     "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:PopSize=100:Cycles=3:Steps=20:Trim=True:SaveBestGen=0" );
555    
556     if (Use_FDA_SA)
557     factory->BookMethod( TMVA::Types::kFDA, "FDA_SA",
558     "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=SA:MaxCalls=50000:TemperatureGradient=0.7:InitialTemperature=2000000:MinTemperature=500:Eps=1e-04:NFunLoops=5:NEps=4" );
559    
560     if (Use_FDA_MT)
561     factory->BookMethod( TMVA::Types::kFDA, "FDA_MT",
562     "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=2:UseImprove:UseMinos:SetBatch" );
563    
564     if (Use_FDA_GAMT)
565     factory->BookMethod( TMVA::Types::kFDA, "FDA_GAMT",
566     "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:Cycles=1:PopSize=5:Steps=5:Trim" );
567    
568     if (Use_FDA_MCMT)
569     factory->BookMethod( TMVA::Types::kFDA, "FDA_MCMT",
570     "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:SampleSize=20" );
571    
572     // TMVA ANN: MLP (recommended ANN) -- all ANNs in TMVA are Multilayer Perceptrons
573     if (Use_MLP)
574     factory->BookMethod( TMVA::Types::kMLP, "MLP", "Normalise:H:!V:NCycles=200:HiddenLayers=N+1,N:TestRate=5" );
575    
576     // CF(Clermont-Ferrand)ANN
577     if (Use_CFMlpANN)
578     factory->BookMethod( TMVA::Types::kCFMlpANN, "CFMlpANN", "!H:!V:NCycles=500:HiddenLayers=N+1,N" ); // n_cycles:#nodes:#nodes:...
579    
580     // Tmlp(Root)ANN
581     if (Use_TMlpANN)
582     factory->BookMethod( TMVA::Types::kTMlpANN, "TMlpANN", "!H:!V:NCycles=200:HiddenLayers=N+1,N" ); // n_cycles:#nodes:#nodes:...
583    
584     // Support Vector Machines using three different Kernel types (Gauss, polynomial and linear)
585     if (Use_SVM_Gauss)
586     factory->BookMethod( TMVA::Types::kSVM, "SVM_Gauss", "Sigma=2:C=1:Tol=0.001:Kernel=Gauss" );
587    
588     if (Use_SVM_Poly)
589     factory->BookMethod( TMVA::Types::kSVM, "SVM_Poly", "Order=4:Theta=1:C=0.1:Tol=0.001:Kernel=Polynomial" );
590    
591     if (Use_SVM_Lin)
592     factory->BookMethod( TMVA::Types::kSVM, "SVM_Lin", "!H:!V:Kernel=Linear:C=1:Tol=0.001" );
593    
594     // Boosted Decision Trees (second one with decorrelation)
595     if (Use_BDT)
596     factory->BookMethod( TMVA::Types::kBDT, "BDT",
597     "H:V:NTrees=1000:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=10:PruneMethod=CostComplexity:PruneStrength=15.0:nEventsMin=20 ");
598    
599     if (Use_BDTD)
600     factory->BookMethod( TMVA::Types::kBDT, "BDTD",
601     "!H:!V:NTrees=100:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=CostComplexity:PruneStrength=4.5:VarTransform=Decorrelate" );
602    
603     // RuleFit -- TMVA implementation of Friedman's method
604     if (Use_RuleFitTMVA)
605     factory->BookMethod( TMVA::Types::kRuleFit, "RuleFitTMVA",
606     "H:!V:RuleFitModule=RFTMVA:Model=ModRuleLinear:MinImp=0.0001:RuleMinDist=0.0001:NTrees=20:fEventsMin=0.01:fEventsMax=0.5:GDTau=-1.0:GDTauPrec=0.01:GDStep=0.001:GDNSteps=100000:GDErrScale=1.02" );
607     //"H:!V:RuleFitModule=RFTMVA:Model=ModRuleLinear:MinImp=0.001:RuleMinDist=0.001:NTrees=20:fEventsMin=0.01:fEventsMax=0.1:GDTau=-1.0:GDTauPrec=0.01:GDStep=0.0001:GDNSteps=100000:GDErrScale=1.02" );
608     //"H:!V:RuleFitModule=RFTMVA:Model=ModRuleLinear:MinImp=0.001:RuleMinDist=0.001:NTrees=20:fEventsMin=0.01:fEventsMax=0.5:GDTau=-1.0:GDTauPrec=0.01:GDStep=0.01:GDNSteps=100000:GDErrScale=1.02" );
609    
610     // Friedman's RuleFit method, implementation by J. Friedman
611     if (Use_RuleFitJF)
612     factory->BookMethod( TMVA::Types::kRuleFit, "RuleFitJF",
613     "!V:RuleFitModule=RFFriedman:Model=ModRuleLinear:GDStep=0.01:GDNSteps=10000:GDErrScale=1.1:RFNendnodes=4" );
614    
615     // ---- Now you can tell the factory to train, test, and evaluate the MVAs
616    
617     // Train MVAs using the set of training events
618     factory->TrainAllMethods();
619    
620     // ---- Evaluate all MVAs using the set of test events
621     factory->TestAllMethods();
622    
623     // ----- Evaluate and compare performance of all configured MVAs
624     factory->EvaluateAllMethods();
625    
626     // --------------------------------------------------------------
627    
628     // Save the output
629     outputFile->Close();
630    
631     std::cout << "==> wrote root file TMVA.root" << std::endl;
632     std::cout << "==> TMVAnalysis is done!" << std::endl;
633    
634     // Clean up
635     delete factory;
636    
637     // Launch the GUI for the root macros
638     if (!gROOT->IsBatch()) TMVAGui( outfileName );
639     }