1 |
bortigno |
1.1 |
// @(#)root/tmva $Id: TMVAClassification.cxx 37399 2010-12-08 15:22:07Z evt $
|
2 |
|
|
/**********************************************************************************
|
3 |
|
|
* Project : TMVA - a ROOT-integrated toolkit for multivariate data analysis *
|
4 |
|
|
* Package : TMVA *
|
5 |
|
|
* Exectuable: TMVAClassification *
|
6 |
|
|
* *
|
7 |
|
|
* This executable provides examples for the training and testing of 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. *
|
14 |
|
|
* *
|
15 |
|
|
* Compile and run the example with the following commands *
|
16 |
|
|
* *
|
17 |
|
|
* make *
|
18 |
|
|
* ./TMVAClassification <Methods> *
|
19 |
|
|
* *
|
20 |
|
|
* where: <Methods> = "method1 method2" *
|
21 |
|
|
* are the TMVA classifier names *
|
22 |
|
|
* *
|
23 |
|
|
* example: *
|
24 |
|
|
* ./TMVAClassification Fisher LikelihoodPCA BDT *
|
25 |
|
|
* *
|
26 |
|
|
* If no method given, a default set is of classifiers is used *
|
27 |
|
|
* *
|
28 |
|
|
* The output file "TMVA.root" can be analysed with the use of dedicated *
|
29 |
|
|
* macros (simply say: root -l <../macros/macro.C>), which can be conveniently *
|
30 |
|
|
* invoked through a GUI launched by the command *
|
31 |
|
|
* *
|
32 |
|
|
* root -l ./TMVAGui.C *
|
33 |
|
|
**********************************************************************************/
|
34 |
|
|
|
35 |
|
|
#include <cstdlib>
|
36 |
|
|
#include <iostream>
|
37 |
|
|
#include <map>
|
38 |
|
|
#include <string>
|
39 |
|
|
|
40 |
|
|
#include "TChain.h"
|
41 |
|
|
#include "TFile.h"
|
42 |
|
|
#include "TTree.h"
|
43 |
|
|
#include "TString.h"
|
44 |
|
|
#include "TObjString.h"
|
45 |
|
|
#include "TSystem.h"
|
46 |
|
|
#include "TROOT.h"
|
47 |
|
|
|
48 |
|
|
#include "TMVA/Factory.h"
|
49 |
|
|
#include "TMVA/Tools.h"
|
50 |
|
|
#include "TMVA/Config.h"
|
51 |
|
|
|
52 |
|
|
#include "../macros/samples.h"
|
53 |
|
|
|
54 |
|
|
// read input data file with ascii format (otherwise ROOT) ?
|
55 |
|
|
Bool_t ReadDataFromAsciiIFormat = kFALSE;
|
56 |
|
|
|
57 |
|
|
int main( int argc, char** argv )
|
58 |
|
|
{
|
59 |
|
|
//---------------------------------------------------------------
|
60 |
|
|
// Default MVA methods to be trained + tested
|
61 |
|
|
std::map<std::string,int> Use;
|
62 |
|
|
|
63 |
|
|
// --- Cut optimisation
|
64 |
|
|
Use["Cuts"] = 1;
|
65 |
|
|
Use["CutsD"] = 0;
|
66 |
|
|
Use["CutsPCA"] = 0;
|
67 |
|
|
Use["CutsGA"] = 0;
|
68 |
|
|
Use["CutsSA"] = 0;
|
69 |
|
|
//
|
70 |
|
|
// --- 1-dimensional likelihood ("naive Bayes estimator")
|
71 |
|
|
Use["Likelihood"] = 1;
|
72 |
|
|
Use["LikelihoodD"] = 0; // the "D" extension indicates decorrelated input variables (see option strings)
|
73 |
|
|
Use["LikelihoodPCA"] = 0; // the "PCA" extension indicates PCA-transformed input variables (see option strings)
|
74 |
|
|
Use["LikelihoodKDE"] = 0;
|
75 |
|
|
Use["LikelihoodMIX"] = 0;
|
76 |
|
|
//
|
77 |
|
|
// --- Mutidimensional likelihood and Nearest-Neighbour methods
|
78 |
|
|
Use["PDERS"] = 0;
|
79 |
|
|
Use["PDERSD"] = 0;
|
80 |
|
|
Use["PDERSPCA"] = 0;
|
81 |
|
|
Use["PDEFoam"] = 0;
|
82 |
|
|
Use["PDEFoamBoost"] = 0; // uses generalised MVA method boosting
|
83 |
|
|
Use["KNN"] = 0; // k-nearest neighbour method
|
84 |
|
|
//
|
85 |
|
|
// --- Linear Discriminant Analysis
|
86 |
|
|
Use["LD"] = 0; // Linear Discriminant identical to Fisher
|
87 |
|
|
Use["Fisher"] = 0;
|
88 |
|
|
Use["FisherG"] = 0;
|
89 |
|
|
Use["BoostedFisher"] = 0; // uses generalised MVA method boosting
|
90 |
|
|
Use["HMatrix"] = 0;
|
91 |
|
|
//
|
92 |
|
|
// --- Function Discriminant analysis
|
93 |
|
|
Use["FDA_GA"] = 0; // minimisation of user-defined function using Genetics Algorithm
|
94 |
|
|
Use["FDA_SA"] = 0;
|
95 |
|
|
Use["FDA_MC"] = 0;
|
96 |
|
|
Use["FDA_MT"] = 0;
|
97 |
|
|
Use["FDA_GAMT"] = 0;
|
98 |
|
|
Use["FDA_MCMT"] = 0;
|
99 |
|
|
//
|
100 |
|
|
// --- Neural Networks (all are feed-forward Multilayer Perceptrons)
|
101 |
|
|
Use["MLP"] = 0; // Recommended ANN
|
102 |
|
|
Use["MLPBFGS"] = 0; // Recommended ANN with optional training method
|
103 |
|
|
Use["MLPBNN"] = 0; // Recommended ANN with BFGS training method and bayesian regulator
|
104 |
|
|
Use["CFMlpANN"] = 0; // Depreciated ANN from ALEPH
|
105 |
|
|
Use["TMlpANN"] = 0; // ROOT's own ANN
|
106 |
|
|
//
|
107 |
|
|
// --- Support Vector Machine
|
108 |
|
|
Use["SVM"] = 0;
|
109 |
|
|
//
|
110 |
|
|
// --- Boosted Decision Trees
|
111 |
|
|
Use["BDT"] = 1; // uses Adaptive Boost
|
112 |
|
|
Use["BDTG"] = 0; // uses Gradient Boost
|
113 |
|
|
Use["BDTB"] = 0; // uses Bagging
|
114 |
|
|
Use["BDTD"] = 0; // decorrelation + Adaptive Boost
|
115 |
|
|
//
|
116 |
|
|
// --- Friedman's RuleFit method, ie, an optimised series of cuts ("rules")
|
117 |
|
|
Use["RuleFit"] = 0;
|
118 |
|
|
// ---------------------------------------------------------------
|
119 |
|
|
|
120 |
|
|
std::cout << std::endl << "==> Start TMVAClassification" << std::endl;
|
121 |
|
|
|
122 |
|
|
bool batchMode(false);
|
123 |
|
|
bool useDefaultMethods(true);
|
124 |
|
|
|
125 |
|
|
// // Select methods (don't look at this code - not of interest)
|
126 |
|
|
// for (int i=1; i<argc; i++) {
|
127 |
|
|
// std::string regMethod(argv[i]);
|
128 |
|
|
// if(regMethod=="-b" || regMethod=="--batch") {
|
129 |
|
|
// batchMode=true;
|
130 |
|
|
// continue;
|
131 |
|
|
// }
|
132 |
|
|
// if (Use.find(regMethod) == Use.end()) {
|
133 |
|
|
// std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl;
|
134 |
|
|
// for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first << " ";
|
135 |
|
|
// std::cout << std::endl;
|
136 |
|
|
// return 1;
|
137 |
|
|
// }
|
138 |
|
|
// useDefaultMethods = false;
|
139 |
|
|
// }
|
140 |
|
|
|
141 |
|
|
// if (!useDefaultMethods) {
|
142 |
|
|
// for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
|
143 |
|
|
// for (int i=1; i<argc; i++) {
|
144 |
|
|
// std::string regMethod(argv[i]);
|
145 |
|
|
// if(regMethod=="-b" || regMethod=="--batch") continue;
|
146 |
|
|
// Use[regMethod] = 1;
|
147 |
|
|
// }
|
148 |
|
|
// }
|
149 |
|
|
|
150 |
|
|
// --------------------------------------------------------------------------------------------------
|
151 |
|
|
|
152 |
|
|
// --- Here the preparation phase begins
|
153 |
|
|
// string channel="Zmm";
|
154 |
|
|
|
155 |
|
|
// std::cout << "argc = " << argc << std::endl;
|
156 |
|
|
std::string channel;
|
157 |
|
|
if( argc > 1 )
|
158 |
|
|
channel=argv[1];
|
159 |
|
|
else{
|
160 |
|
|
std::cerr << "no channel selected" << std::endl;
|
161 |
|
|
return -1;
|
162 |
|
|
}
|
163 |
|
|
// Create a ROOT output file where TMVA will store ntuples, histograms, etc.
|
164 |
|
|
TString outfileName( "TMVA.root" );
|
165 |
|
|
outfileName=channel+outfileName;
|
166 |
|
|
TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
|
167 |
|
|
|
168 |
|
|
// Create the factory object. Later you can choose the methods
|
169 |
|
|
// whose performance you'd like to investigate. The factory is
|
170 |
|
|
// the only TMVA object you have to interact with
|
171 |
|
|
//
|
172 |
|
|
// The first argument is the base of the name of all the
|
173 |
|
|
// weightfiles in the directory weight/
|
174 |
|
|
//
|
175 |
|
|
// The second argument is the output file for the training results
|
176 |
|
|
// All TMVA output can be suppressed by removing the "!" (not) in
|
177 |
|
|
// front of the "Silent" argument in the option string
|
178 |
|
|
TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
|
179 |
|
|
"!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );
|
180 |
|
|
|
181 |
|
|
// If you wish to modify default settings
|
182 |
|
|
// (please check "src/Config.h" to see all available global options)
|
183 |
|
|
// (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
|
184 |
|
|
// (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";
|
185 |
|
|
(TMVA::gConfig().GetIONames()).fWeightFileExtension = channel+"_weight";
|
186 |
|
|
|
187 |
|
|
// Define the input variables that shall be used for the MVA training
|
188 |
|
|
// note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
|
189 |
|
|
// [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
|
190 |
|
|
|
191 |
|
|
float BR115 = 0.704;
|
192 |
|
|
float BR120 = 0.648;
|
193 |
|
|
float BR125 = 0.577;
|
194 |
|
|
float BR130 = 0.493;
|
195 |
|
|
float BR135 = 0.403;
|
196 |
|
|
|
197 |
|
|
// 115
|
198 |
|
|
float xSecWH = 0.7546*BR115;
|
199 |
|
|
float xSecZH = 0.4107*BR115;
|
200 |
|
|
float backgroundXsecWJets = 31314;
|
201 |
|
|
float backgroundXsecDY = 3048;
|
202 |
|
|
float backgroundXsecWZ = 18.3;
|
203 |
|
|
float backgroundXsecWW = 42.9;
|
204 |
|
|
float backgroundXsecZZ = 5.9;
|
205 |
|
|
float backgroundXsecTT = 165;
|
206 |
|
|
float backgroundXsecT_tchannel = 41.92;
|
207 |
|
|
float backgroundXsecT_tWDRchannel = 7.87;
|
208 |
|
|
float backgroundXsecTbar_tchannel = 22.65;
|
209 |
|
|
float backgroundXsecTbar_tWDRchannel = 7.87;
|
210 |
|
|
// float backgroundXsecTbar_tWDSchannel = 25;
|
211 |
|
|
|
212 |
|
|
//get Lumi from something serius
|
213 |
|
|
float lumi = 2047.0+8872.0;
|
214 |
|
|
|
215 |
|
|
float signalXsec;
|
216 |
|
|
std::vector<double> backgroundXsec;
|
217 |
|
|
std::vector<TFile*> myInputFile_signal;
|
218 |
|
|
std::vector<TFile*> myInputFile_background;
|
219 |
|
|
|
220 |
|
|
TCut mycuts = "";
|
221 |
|
|
TCut mycutb = "";
|
222 |
|
|
bool origCuts = true;
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
//signal for Z
|
226 |
|
|
if( channel == "Zmm" or channel == "Zee" or channel == "Znn" ){
|
227 |
|
|
myInputFile_signal.push_back(TFile::Open("MC_files/file_ZH_ZToLL_HToBB_M-115_7TeV-powheg-herwigppTreeFile.root"));
|
228 |
|
|
signalXsec = xSecZH;
|
229 |
|
|
}
|
230 |
|
|
//signal for W
|
231 |
|
|
if( channel == "Wm" or channel == "We" ){
|
232 |
|
|
myInputFile_signal.push_back(TFile::Open("MC_files/file_ZH_ZToLL_HToBB_M-115_7TeV-powheg-herwigppTreeFile.root"));
|
233 |
|
|
signalXsec = xSecWH;
|
234 |
|
|
}
|
235 |
|
|
//background
|
236 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files/file_DYJetsToLL_TuneZ2_M-50_7TeV-madgraph-tauolaTreeFile.root"));
|
237 |
|
|
backgroundXsec.push_back(backgroundXsecDY);
|
238 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_WJetsToLNu_TuneZ2_7TeV-madgraph-tauolaTreeFile.root"));
|
239 |
|
|
backgroundXsec.push_back(backgroundXsecWJets);
|
240 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_TTJets_TuneZ2_7TeV-madgraph-tauolaTreeFile.root"));
|
241 |
|
|
backgroundXsec.push_back(backgroundXsecTT);
|
242 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_T_TuneZ2_t-channel_7TeV-powheg-tauolaTreeFile.root"));
|
243 |
|
|
backgroundXsec.push_back(backgroundXsecT_tchannel);
|
244 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_T_TuneZ2_tW-channel-DR_7TeV-powheg-tauolaTreeFile.root"));
|
245 |
|
|
backgroundXsec.push_back(backgroundXsecT_tWDRchannel);
|
246 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_Tbar_TuneZ2_t-channel_7TeV-powheg-tauolaTreeFile.root"));
|
247 |
|
|
backgroundXsec.push_back(backgroundXsecTbar_tchannel);
|
248 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_Tbar_TuneZ2_tW-channel-DR_7TeV-powheg-tauolaTreeFile.root"));
|
249 |
|
|
backgroundXsec.push_back(backgroundXsecTbar_tWDRchannel);
|
250 |
|
|
// myInputFile_background.push_back(TFile::Open("MC_files//file_Tbar_TuneZ2_tW-channel-DS_7TeV-powheg-tauolaTreeFile.root"));
|
251 |
|
|
// backgroundXsec.push_back(backgroundXsecTbar_tWDSchannel);
|
252 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files///file_ZZ_TuneZ2_7TeV_pythia6_tauolaTreeFile.root"));
|
253 |
|
|
backgroundXsec.push_back(backgroundXsecZZ);
|
254 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files/file_WW_TuneZ2_7TeV_pythia6_tauolaTreeFile.root"));
|
255 |
|
|
backgroundXsec.push_back(backgroundXsecWW);
|
256 |
|
|
//WZ still missing
|
257 |
|
|
// myInputFile_background.push_back(TFile::Open("MC_files/"));
|
258 |
|
|
// backgroundXsec.push_back(backgroundXsecWZ);
|
259 |
|
|
myInputFile_background.push_back(TFile::Open("MC_files//file_ZZ_TuneZ2_7TeV_pythia6_tauolaTreeFile.root"));
|
260 |
|
|
backgroundXsec.push_back(backgroundXsecZZ);
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
if(channel == "Zmm"){
|
264 |
|
|
factory->AddVariable( "bbMass", "bb mass" , "GeV/c2", 'F' );
|
265 |
|
|
factory->AddVariable( "VMass", "vector mass" , "GeV/c2", 'F' );
|
266 |
|
|
factory->AddVariable( "bbPt", "bb pt" , "GeV/c" , 'F' );
|
267 |
|
|
factory->AddVariable( "VPt", "vector pt" , "GeV/c" , 'F' );
|
268 |
|
|
factory->AddVariable( "btag1", "btag1" , "csv" , 'F' );
|
269 |
|
|
factory->AddVariable( "btag2", "btag2" , "csv" , 'F' );
|
270 |
|
|
factory->AddVariable( "DeltaPhiVH", "DeltaPhi(V,H)" , "" , 'F' );
|
271 |
|
|
factory->AddVariable( "DeltaEtabb", "DeltaEta(b,b)" , "" , 'F' );
|
272 |
|
|
|
273 |
|
|
//PRESELECTION
|
274 |
|
|
mycuts="(bPt1>20) && (bPt2>20) && (btag1>0.5) && (btag2>0.5) && (NaddJet<2) && (DeltaPhiVH>2.4)";
|
275 |
|
|
mycutb="(bPt1>20) && (bPt2>20) && (btag1>0.5) && (btag2>0.5) && (NaddJet<2) && (DeltaPhiVH>2.4)";
|
276 |
|
|
|
277 |
|
|
}
|
278 |
|
|
else if(channel == "Zee"){
|
279 |
|
|
factory->AddVariable( "bbMass", "bb mass" , "GeV/c2", 'F' );
|
280 |
|
|
factory->AddVariable( "VMass", "vector mass" , "GeV/c2", 'F' );
|
281 |
|
|
factory->AddVariable( "bbPt", "bb pt" , "GeV/c" , 'F' );
|
282 |
|
|
factory->AddVariable( "VPt", "vector pt" , "GeV/c" , 'F' );
|
283 |
|
|
factory->AddVariable( "btag1", "btag1" , "csv" , 'F' );
|
284 |
|
|
factory->AddVariable( "btag2", "btag2" , "csv" , 'F' );
|
285 |
|
|
factory->AddVariable( "DeltaPhiVH", "DeltaPhi(V,H)" , "" , 'F' );
|
286 |
|
|
factory->AddVariable( "DeltaEtabb", "DeltaEta(b,b)" , "" , 'F' );
|
287 |
|
|
|
288 |
|
|
//PRESELECTION
|
289 |
|
|
mycuts="bPt1>20 && bPt2>20 && btag1>0.5 && btag2>0.5 && NaddJet<2 && DeltaPhiVH>2.4";
|
290 |
|
|
mycutb="bPt1>20 && bPt2>20 && btag1>0.5 && btag2>0.5 && NaddJet<2 && DeltaPhiVH>2.4";
|
291 |
|
|
|
292 |
|
|
}
|
293 |
|
|
else if(channel == "Znn"){
|
294 |
|
|
factory->AddVariable( "bbMass", "bb mass" , "GeV/c2", 'F' );
|
295 |
|
|
factory->AddVariable( "bbPt", "bb pt" , "GeV/c" , 'F' );
|
296 |
|
|
factory->AddVariable( "pfMET", "met pt" , "GeV/c" , 'F' );
|
297 |
|
|
factory->AddVariable( "btag1", "btag1" , "csv" , 'F' );
|
298 |
|
|
factory->AddVariable( "btag2", "btag2" , "csv" , 'F' );
|
299 |
|
|
factory->AddVariable( "DeltaPhiVH", "DeltaPhi(V,H)" , "" , 'F' );
|
300 |
|
|
//NaddJet is imposed to be 0
|
301 |
|
|
// factory->AddVariable( "NaddJet", "NaddJet" , "" , 'F' );
|
302 |
|
|
|
303 |
|
|
//PRESELECTION
|
304 |
|
|
mycuts="bPt1>80 && bPt2>20 && bbPt>160 && btag1>0.5 && btag2>0.5 && NaddJet<1 && deltaPhipfMETjet1>0.5 && deltaPhipfMETjet2 && pfMETsig>5";
|
305 |
|
|
mycutb="bPt1>80 && bPt2>20 && bbPt>160 && btag1>0.5 && btag2>0.5 && NaddJet<1 && deltaPhipfMETjet1>0.5 && deltaPhipfMETjet2 && pfMETsig>5";
|
306 |
|
|
|
307 |
|
|
}
|
308 |
|
|
else if(channel == "We"){
|
309 |
|
|
factory->AddVariable( "bbMass", "bb mass" , "GeV/c2", 'F' );
|
310 |
|
|
factory->AddVariable( "bbPt", "bb pt" , "GeV/c" , 'F' );
|
311 |
|
|
factory->AddVariable( "VPt", "vector pt" , "GeV/c" , 'F' );
|
312 |
|
|
factory->AddVariable( "btag1", "btag1" , "csv" , 'F' );
|
313 |
|
|
factory->AddVariable( "btag2", "btag2" , "csv" , 'F' );
|
314 |
|
|
factory->AddVariable( "DeltaPhiVH", "DeltaPhi(V,H)" , "" , 'F' );
|
315 |
|
|
factory->AddVariable( "DeltaEtabb", "DeltaEta(b,b)" , "" , 'F' );
|
316 |
|
|
//NaddJet is imposed to be 0
|
317 |
|
|
// factory->AddVariable( "NaddJet", "NaddJet" , "" , 'F' );
|
318 |
|
|
|
319 |
|
|
//PRESELECTION
|
320 |
|
|
mycuts="bPt1>30 && bPt2>30 && bbPt>150 && VPt>150 && btag1>0.4 && btag2>0.4 && NaddJet<1 && pfMETsig>2";
|
321 |
|
|
mycutb="bPt1>30 && bPt2>30 && bbPt>150 && VPt>150 && btag1>0.4 && btag2>0.4 && NaddJet<1 && pfMETsig>2";
|
322 |
|
|
|
323 |
|
|
}
|
324 |
|
|
else if(channel == "Wm"){
|
325 |
|
|
factory->AddVariable( "bbMass", "bb mass" , "GeV/c2", 'F' );
|
326 |
|
|
factory->AddVariable( "bbPt", "bb pt" , "GeV/c" , 'F' );
|
327 |
|
|
factory->AddVariable( "VPt", "vector pt" , "GeV/c" , 'F' );
|
328 |
|
|
factory->AddVariable( "btag1", "btag1" , "csv" , 'F' );
|
329 |
|
|
factory->AddVariable( "btag2", "btag2" , "csv" , 'F' );
|
330 |
|
|
factory->AddVariable( "DeltaPhiVH", "DeltaPhi(V,H)" , "" , 'F' );
|
331 |
|
|
factory->AddVariable( "DeltaEtabb", "DeltaEta(b,b)" , "" , 'F' );
|
332 |
|
|
//NaddJet is imposed to be 0
|
333 |
|
|
// factory->AddVariable( "NaddJet", "NaddJet" , "" , 'F' );
|
334 |
|
|
|
335 |
|
|
//PRESELECTION
|
336 |
|
|
mycuts="bPt1>30 && bPt2>30 && bbPt>150 && VPt>150 && btag1>0.4 && btag2>0.4 && NaddJet<1";
|
337 |
|
|
mycutb="bPt1>30 && bPt2>30 && bbPt>150 && VPt>150 && btag1>0.4 && btag2>0.4 && NaddJet<1";
|
338 |
|
|
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
std::vector<Sample> samples_signal;
|
342 |
|
|
std::vector<Sample> samples_background;
|
343 |
|
|
|
344 |
|
|
std::string str_toReplace("TreeFile");
|
345 |
|
|
|
346 |
|
|
std::vector<TTree*> myInputTree_signal;
|
347 |
|
|
std::vector<TTree*> myInputTree_backgound;
|
348 |
|
|
for(unsigned int i = 0; i < myInputFile_signal.size(); ++i ){
|
349 |
|
|
std::string name = myInputFile_signal.at(0)->GetName();
|
350 |
|
|
samples_signal.push_back(Sample(signalXsec,"signal", name.replace(name.find("TreeFile"),str_toReplace.length() ,"_histos" ) , kRed,false));
|
351 |
|
|
TTree * tmpTree = (TTree*)myInputFile_signal.at(i)->Get("treeMVA");
|
352 |
|
|
factory->AddSignalTree( tmpTree , samples_signal.at(i).scale(lumi) );
|
353 |
|
|
}
|
354 |
|
|
for(unsigned int i = 0; i < myInputFile_background.size(); ++i ){
|
355 |
|
|
std::string name = myInputFile_background.at(i)->GetName();
|
356 |
|
|
samples_background.push_back(Sample(backgroundXsec.at(i),"background", name.replace(name.find("TreeFile"),str_toReplace.length() ,"_histos" ) ,i+10,false));
|
357 |
|
|
TTree * tmpbackTree = (TTree*)myInputFile_background.at(i)->Get("treeMVA");
|
358 |
|
|
factory->AddBackgroundTree( tmpbackTree, samples_background.at(i).scale(lumi) );
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
//from Michele and Matt
|
362 |
|
|
factory->PrepareTrainingAndTestTree( mycuts, mycutb,
|
363 |
|
|
"nTrain_Signal=0:nTrain_Background=0:SplitMode=Random:NormMode=NumEvents:!V" );
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
// ---- Book MVA methods
|
367 |
|
|
//
|
368 |
|
|
// Please lookup the various method configuration options in the corresponding cxx files, eg:
|
369 |
|
|
// src/MethoCuts.cxx, etc, or here: http://tmva.sourceforge.net/optionRef.html
|
370 |
|
|
// it is possible to preset ranges in the option string in which the cut optimisation should be done:
|
371 |
|
|
// "...:CutRangeMin[2]=-1:CutRangeMax[2]=1"...", where [2] is the third input variable
|
372 |
|
|
|
373 |
|
|
// Cut optimisation
|
374 |
|
|
if (Use["Cuts"])
|
375 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "Cuts",
|
376 |
|
|
"!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart" );
|
377 |
|
|
|
378 |
|
|
if (Use["CutsD"])
|
379 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "CutsD",
|
380 |
|
|
"!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart:VarTransform=Decorrelate" );
|
381 |
|
|
|
382 |
|
|
if (Use["CutsPCA"])
|
383 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "CutsPCA",
|
384 |
|
|
"!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart:VarTransform=PCA" );
|
385 |
|
|
|
386 |
|
|
if (Use["CutsGA"])
|
387 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "CutsGA",
|
388 |
|
|
"H:!V:FitMethod=GA:CutRangeMin[0]=-10:CutRangeMax[0]=10:VarProp[1]=FMax:EffSel:Steps=30:Cycles=3:PopSize=400:SC_steps=10:SC_rate=5:SC_factor=0.95" );
|
389 |
|
|
|
390 |
|
|
if (Use["CutsSA"])
|
391 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "CutsSA",
|
392 |
|
|
"!H:!V:FitMethod=SA:EffSel:MaxCalls=150000:KernelTemp=IncAdaptive:InitialTemp=1e+6:MinTemp=1e-6:Eps=1e-10:UseDefaultScale" );
|
393 |
|
|
|
394 |
|
|
// Likelihood ("naive Bayes estimator")
|
395 |
|
|
if (Use["Likelihood"])
|
396 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "Likelihood",
|
397 |
|
|
"H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmoothBkg[1]=10:NSmooth=1:NAvEvtPerBin=50" );
|
398 |
|
|
|
399 |
|
|
// Decorrelated likelihood
|
400 |
|
|
if (Use["LikelihoodD"])
|
401 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodD",
|
402 |
|
|
"!H:!V:TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmooth=5:NAvEvtPerBin=50:VarTransform=Decorrelate" );
|
403 |
|
|
|
404 |
|
|
// PCA-transformed likelihood
|
405 |
|
|
if (Use["LikelihoodPCA"])
|
406 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodPCA",
|
407 |
|
|
"!H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmooth=5:NAvEvtPerBin=50:VarTransform=PCA" );
|
408 |
|
|
|
409 |
|
|
// Use a kernel density estimator to approximate the PDFs
|
410 |
|
|
if (Use["LikelihoodKDE"])
|
411 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodKDE",
|
412 |
|
|
"!H:!V:!TransformOutput:PDFInterpol=KDE:KDEtype=Gauss:KDEiter=Adaptive:KDEFineFactor=0.3:KDEborder=None:NAvEvtPerBin=50" );
|
413 |
|
|
|
414 |
|
|
// Use a variable-dependent mix of splines and kernel density estimator
|
415 |
|
|
if (Use["LikelihoodMIX"])
|
416 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodMIX",
|
417 |
|
|
"!H:!V:!TransformOutput:PDFInterpolSig[0]=KDE:PDFInterpolBkg[0]=KDE:PDFInterpolSig[1]=KDE:PDFInterpolBkg[1]=KDE:PDFInterpolSig[2]=Spline2:PDFInterpolBkg[2]=Spline2:PDFInterpolSig[3]=Spline2:PDFInterpolBkg[3]=Spline2:KDEtype=Gauss:KDEiter=Nonadaptive:KDEborder=None:NAvEvtPerBin=50" );
|
418 |
|
|
|
419 |
|
|
// Test the multi-dimensional probability density estimator
|
420 |
|
|
// here are the options strings for the MinMax and RMS methods, respectively:
|
421 |
|
|
// "!H:!V:VolumeRangeMode=MinMax:DeltaFrac=0.2:KernelEstimator=Gauss:GaussSigma=0.3" );
|
422 |
|
|
// "!H:!V:VolumeRangeMode=RMS:DeltaFrac=3:KernelEstimator=Gauss:GaussSigma=0.3" );
|
423 |
|
|
if (Use["PDERS"])
|
424 |
|
|
factory->BookMethod( TMVA::Types::kPDERS, "PDERS",
|
425 |
|
|
"!H:!V:NormTree=T:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600" );
|
426 |
|
|
|
427 |
|
|
if (Use["PDERSD"])
|
428 |
|
|
factory->BookMethod( TMVA::Types::kPDERS, "PDERSD",
|
429 |
|
|
"!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:VarTransform=Decorrelate" );
|
430 |
|
|
|
431 |
|
|
if (Use["PDERSPCA"])
|
432 |
|
|
factory->BookMethod( TMVA::Types::kPDERS, "PDERSPCA",
|
433 |
|
|
"!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:VarTransform=PCA" );
|
434 |
|
|
|
435 |
|
|
// Multi-dimensional likelihood estimator using self-adapting phase-space binning
|
436 |
|
|
if (Use["PDEFoam"])
|
437 |
|
|
factory->BookMethod( TMVA::Types::kPDEFoam, "PDEFoam",
|
438 |
|
|
"H:!V:SigBgSeparate=F:TailCut=0.001:VolFrac=0.0333:nActiveCells=500:nSampl=2000:nBin=5:Nmin=100:Kernel=None:Compress=T" );
|
439 |
|
|
|
440 |
|
|
if (Use["PDEFoamBoost"])
|
441 |
|
|
factory->BookMethod( TMVA::Types::kPDEFoam, "PDEFoamBoost",
|
442 |
|
|
"!H:!V:Boost_Num=30:Boost_Transform=linear:SigBgSeparate=F:MaxDepth=4:UseYesNoCell=T:DTLogic=MisClassificationError:FillFoamWithOrigWeights=F:TailCut=0:nActiveCells=500:nBin=20:Nmin=400:Kernel=None:Compress=T" );
|
443 |
|
|
|
444 |
|
|
// K-Nearest Neighbour classifier (KNN)
|
445 |
|
|
if (Use["KNN"])
|
446 |
|
|
factory->BookMethod( TMVA::Types::kKNN, "KNN",
|
447 |
|
|
"H:nkNN=20:ScaleFrac=0.8:SigmaFact=1.0:Kernel=Gaus:UseKernel=F:UseWeight=T:!Trim" );
|
448 |
|
|
|
449 |
|
|
// H-Matrix (chi2-squared) method
|
450 |
|
|
if (Use["HMatrix"])
|
451 |
|
|
factory->BookMethod( TMVA::Types::kHMatrix, "HMatrix", "!H:!V" );
|
452 |
|
|
|
453 |
|
|
// Linear discriminant (same as Fisher discriminant)
|
454 |
|
|
if (Use["LD"])
|
455 |
|
|
factory->BookMethod( TMVA::Types::kLD, "LD", "H:!V:VarTransform=None:CreateMVAPdfs:PDFInterpolMVAPdf=Spline2:NbinsMVAPdf=50:NsmoothMVAPdf=10" );
|
456 |
|
|
|
457 |
|
|
// Fisher discriminant (same as LD)
|
458 |
|
|
if (Use["Fisher"])
|
459 |
|
|
factory->BookMethod( TMVA::Types::kFisher, "Fisher", "H:!V:Fisher:CreateMVAPdfs:PDFInterpolMVAPdf=Spline2:NbinsMVAPdf=50:NsmoothMVAPdf=10" );
|
460 |
|
|
|
461 |
|
|
// Fisher with Gauss-transformed input variables
|
462 |
|
|
if (Use["FisherG"])
|
463 |
|
|
factory->BookMethod( TMVA::Types::kFisher, "FisherG", "H:!V:VarTransform=Gauss" );
|
464 |
|
|
|
465 |
|
|
// Composite classifier: ensemble (tree) of boosted Fisher classifiers
|
466 |
|
|
if (Use["BoostedFisher"])
|
467 |
|
|
factory->BookMethod( TMVA::Types::kFisher, "BoostedFisher", "H:!V:Boost_Num=20:Boost_Transform=log:Boost_Type=AdaBoost:Boost_AdaBoostBeta=0.2");
|
468 |
|
|
|
469 |
|
|
// Function discrimination analysis (FDA) -- test of various fitters - the recommended one is Minuit (or GA or SA)
|
470 |
|
|
if (Use["FDA_MC"])
|
471 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_MC",
|
472 |
|
|
"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" );
|
473 |
|
|
|
474 |
|
|
if (Use["FDA_GA"]) // can also use Simulated Annealing (SA) algorithm (see Cuts_SA options])
|
475 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_GA",
|
476 |
|
|
"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=300:Cycles=3:Steps=20:Trim=True:SaveBestGen=1" );
|
477 |
|
|
|
478 |
|
|
if (Use["FDA_SA"]) // can also use Simulated Annealing (SA) algorithm (see Cuts_SA options])
|
479 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_SA",
|
480 |
|
|
"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=15000:KernelTemp=IncAdaptive:InitialTemp=1e+6:MinTemp=1e-6:Eps=1e-10:UseDefaultScale" );
|
481 |
|
|
|
482 |
|
|
if (Use["FDA_MT"])
|
483 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_MT",
|
484 |
|
|
"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" );
|
485 |
|
|
|
486 |
|
|
if (Use["FDA_GAMT"])
|
487 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_GAMT",
|
488 |
|
|
"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" );
|
489 |
|
|
|
490 |
|
|
if (Use["FDA_MCMT"])
|
491 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_MCMT",
|
492 |
|
|
"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" );
|
493 |
|
|
|
494 |
|
|
// TMVA ANN: MLP (recommended ANN) -- all ANNs in TMVA are Multilayer Perceptrons
|
495 |
|
|
if (Use["MLP"])
|
496 |
|
|
factory->BookMethod( TMVA::Types::kMLP, "MLP", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:!UseRegulator" );
|
497 |
|
|
|
498 |
|
|
if (Use["MLPBFGS"])
|
499 |
|
|
factory->BookMethod( TMVA::Types::kMLP, "MLPBFGS", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:TrainingMethod=BFGS:!UseRegulator" );
|
500 |
|
|
|
501 |
|
|
if (Use["MLPBNN"])
|
502 |
|
|
factory->BookMethod( TMVA::Types::kMLP, "MLPBNN", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:TrainingMethod=BFGS:UseRegulator" ); // BFGS training with bayesian regulators
|
503 |
|
|
|
504 |
|
|
// CF(Clermont-Ferrand)ANN
|
505 |
|
|
if (Use["CFMlpANN"])
|
506 |
|
|
factory->BookMethod( TMVA::Types::kCFMlpANN, "CFMlpANN", "!H:!V:NCycles=2000:HiddenLayers=N+1,N" ); // n_cycles:#nodes:#nodes:...
|
507 |
|
|
|
508 |
|
|
// Tmlp(Root)ANN
|
509 |
|
|
if (Use["TMlpANN"])
|
510 |
|
|
factory->BookMethod( TMVA::Types::kTMlpANN, "TMlpANN", "!H:!V:NCycles=200:HiddenLayers=N+1,N:LearningMethod=BFGS:ValidationFraction=0.3" ); // n_cycles:#nodes:#nodes:...
|
511 |
|
|
|
512 |
|
|
// Support Vector Machine
|
513 |
|
|
if (Use["SVM"])
|
514 |
|
|
factory->BookMethod( TMVA::Types::kSVM, "SVM", "Gamma=0.25:Tol=0.001:VarTransform=Norm" );
|
515 |
|
|
|
516 |
|
|
// Boosted Decision Trees
|
517 |
|
|
if (Use["BDTG"]) // Gradient Boost
|
518 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDTG",
|
519 |
|
|
"!H:!V:NTrees=1000:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.5:nCuts=20:NNodesMax=5" );
|
520 |
|
|
|
521 |
|
|
if (Use["BDT"]) // Adaptive Boost
|
522 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDT",
|
523 |
|
|
"!H:!V:NTrees=850:nEventsMin=150:MaxDepth=3:BoostType=AdaBoost:AdaBoostBeta=0.5:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
|
524 |
|
|
|
525 |
|
|
if (Use["BDTB"]) // Bagging
|
526 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDTB",
|
527 |
|
|
"!H:!V:NTrees=400:BoostType=Bagging:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
|
528 |
|
|
|
529 |
|
|
if (Use["BDTD"]) // Decorrelation + Adaptive Boost
|
530 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDTD",
|
531 |
|
|
"!H:!V:NTrees=400:nEventsMin=400:MaxDepth=3:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning:VarTransform=Decorrelate" );
|
532 |
|
|
|
533 |
|
|
// RuleFit -- TMVA implementation of Friedman's method
|
534 |
|
|
if (Use["RuleFit"])
|
535 |
|
|
factory->BookMethod( TMVA::Types::kRuleFit, "RuleFit",
|
536 |
|
|
"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=10000:GDErrScale=1.02" );
|
537 |
|
|
|
538 |
|
|
// For an example of the category classifier, see: TMVAClassificationCategory
|
539 |
|
|
|
540 |
|
|
// For an example of the category classifier usage, see: TMVAClassificationCategory
|
541 |
|
|
|
542 |
|
|
// --------------------------------------------------------------------------------------------------
|
543 |
|
|
|
544 |
|
|
// ---- Now you can optimize the setting (configuration) of the MVAs using the set of training events
|
545 |
|
|
|
546 |
|
|
// factory->OptimizeAllMethods("SigEffAt001","Scan");
|
547 |
|
|
// factory->OptimizeAllMethods("ROCIntegral","GA");
|
548 |
|
|
|
549 |
|
|
// --------------------------------------------------------------------------------------------------
|
550 |
|
|
|
551 |
|
|
// ---- Now you can tell the factory to train, test, and evaluate the MVAs
|
552 |
|
|
|
553 |
|
|
// Train MVAs using the set of training events
|
554 |
|
|
factory->TrainAllMethods();
|
555 |
|
|
|
556 |
|
|
// ---- Evaluate all MVAs using the set of test events
|
557 |
|
|
factory->TestAllMethods();
|
558 |
|
|
|
559 |
|
|
// ----- Evaluate and compare performance of all configured MVAs
|
560 |
|
|
factory->EvaluateAllMethods();
|
561 |
|
|
|
562 |
|
|
// --------------------------------------------------------------
|
563 |
|
|
|
564 |
|
|
// Save the output
|
565 |
|
|
outputFile->Close();
|
566 |
|
|
|
567 |
|
|
std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl
|
568 |
|
|
<< "==> TMVAClassification is done!" << std::endl
|
569 |
|
|
<< std::endl
|
570 |
|
|
<< "==> To view the results, launch the GUI: \"root -l ./TMVAGui.C\"" << std::endl
|
571 |
|
|
<< std::endl;
|
572 |
|
|
|
573 |
|
|
// Clean up
|
574 |
|
|
delete factory;
|
575 |
|
|
}
|
576 |
|
|
|