38 std::map<std::string,int> Use;
48 Use[
"Likelihood"] = 1;
49 Use[
"LikelihoodD"] = 0;
50 Use[
"LikelihoodPCA"] = 1;
51 Use[
"LikelihoodKDE"] = 0;
52 Use[
"LikelihoodMIX"] = 0;
59 Use[
"PDEFoamBoost"] = 0;
66 Use[
"BoostedFisher"] = 0;
102 std::cout << std::endl;
103 std::cout <<
"==> Start TMVAClassificationApplication" << std::endl;
106 if (myMethodList !=
"") {
107 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
110 for (
UInt_t i=0; i<mlist.size(); i++) {
111 std::string regMethod(mlist[i]);
113 if (Use.find(regMethod) == Use.end()) {
114 std::cout <<
"Method \"" << regMethod
115 <<
"\" not known in TMVA under this name. Choose among the following:" << std::endl;
116 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
117 std::cout << it->first <<
" ";
119 std::cout << std::endl;
136 reader->
AddVariable(
"myvar1 := var1+var2", &var1 );
137 reader->
AddVariable(
"myvar2 := var1-var2", &var2 );
146 Float_t Category_cat1, Category_cat2, Category_cat3;
147 if (Use[
"Category"]){
149 reader->
AddSpectator(
"Category_cat1 := var3<=0", &Category_cat1 );
150 reader->
AddSpectator(
"Category_cat2 := (var3>0)&&(var4<0)", &Category_cat2 );
151 reader->
AddSpectator(
"Category_cat3 := (var3>0)&&(var4>=0)", &Category_cat3 );
157 TString prefix =
"TMVAClassification";
160 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
164 reader->
BookMVA( methodName, weightfile );
170 TH1F *histLk(0), *histLkD(0), *histLkPCA(0), *histLkKDE(0), *histLkMIX(0), *histPD(0), *histPDD(0);
171 TH1F *histPDPCA(0), *histPDEFoam(0), *histPDEFoamErr(0), *histPDEFoamSig(0), *histKNN(0), *histHm(0);
172 TH1F *histFi(0), *histFiG(0), *histFiB(0), *histLD(0), *histNn(0),*histNnbfgs(0),*histNnbnn(0);
173 TH1F *histNnC(0), *histNnT(0), *histBdt(0), *histBdtG(0), *histBdtD(0), *histRf(0), *histSVMG(0);
174 TH1F *histSVMP(0), *histSVML(0), *histFDAMT(0), *histFDAGA(0), *histCat(0), *histPBdt(0);
176 if (Use[
"Likelihood"]) histLk =
new TH1F(
"MVA_Likelihood",
"MVA_Likelihood", nbin, -1, 1 );
177 if (Use[
"LikelihoodD"]) histLkD =
new TH1F(
"MVA_LikelihoodD",
"MVA_LikelihoodD", nbin, -1, 0.9999 );
178 if (Use[
"LikelihoodPCA"]) histLkPCA =
new TH1F(
"MVA_LikelihoodPCA",
"MVA_LikelihoodPCA", nbin, -1, 1 );
179 if (Use[
"LikelihoodKDE"]) histLkKDE =
new TH1F(
"MVA_LikelihoodKDE",
"MVA_LikelihoodKDE", nbin, -0.00001, 0.99999 );
180 if (Use[
"LikelihoodMIX"]) histLkMIX =
new TH1F(
"MVA_LikelihoodMIX",
"MVA_LikelihoodMIX", nbin, 0, 1 );
181 if (Use[
"PDERS"]) histPD =
new TH1F(
"MVA_PDERS",
"MVA_PDERS", nbin, 0, 1 );
182 if (Use[
"PDERSD"]) histPDD =
new TH1F(
"MVA_PDERSD",
"MVA_PDERSD", nbin, 0, 1 );
183 if (Use[
"PDERSPCA"]) histPDPCA =
new TH1F(
"MVA_PDERSPCA",
"MVA_PDERSPCA", nbin, 0, 1 );
184 if (Use[
"KNN"]) histKNN =
new TH1F(
"MVA_KNN",
"MVA_KNN", nbin, 0, 1 );
185 if (Use[
"HMatrix"]) histHm =
new TH1F(
"MVA_HMatrix",
"MVA_HMatrix", nbin, -0.95, 1.55 );
186 if (Use[
"Fisher"]) histFi =
new TH1F(
"MVA_Fisher",
"MVA_Fisher", nbin, -4, 4 );
187 if (Use[
"FisherG"]) histFiG =
new TH1F(
"MVA_FisherG",
"MVA_FisherG", nbin, -1, 1 );
188 if (Use[
"BoostedFisher"]) histFiB =
new TH1F(
"MVA_BoostedFisher",
"MVA_BoostedFisher", nbin, -2, 2 );
189 if (Use[
"LD"]) histLD =
new TH1F(
"MVA_LD",
"MVA_LD", nbin, -2, 2 );
190 if (Use[
"MLP"]) histNn =
new TH1F(
"MVA_MLP",
"MVA_MLP", nbin, -1.25, 1.5 );
191 if (Use[
"MLPBFGS"]) histNnbfgs =
new TH1F(
"MVA_MLPBFGS",
"MVA_MLPBFGS", nbin, -1.25, 1.5 );
192 if (Use[
"MLPBNN"]) histNnbnn =
new TH1F(
"MVA_MLPBNN",
"MVA_MLPBNN", nbin, -1.25, 1.5 );
193 if (Use[
"CFMlpANN"]) histNnC =
new TH1F(
"MVA_CFMlpANN",
"MVA_CFMlpANN", nbin, 0, 1 );
194 if (Use[
"TMlpANN"]) histNnT =
new TH1F(
"MVA_TMlpANN",
"MVA_TMlpANN", nbin, -1.3, 1.3 );
195 if (Use[
"BDT"]) histBdt =
new TH1F(
"MVA_BDT",
"MVA_BDT", nbin, -0.8, 0.8 );
196 if (Use[
"BDTD"]) histBdtD =
new TH1F(
"MVA_BDTD",
"MVA_BDTD", nbin, -0.8, 0.8 );
197 if (Use[
"BDTG"]) histBdtG =
new TH1F(
"MVA_BDTG",
"MVA_BDTG", nbin, -1.0, 1.0 );
198 if (Use[
"RuleFit"]) histRf =
new TH1F(
"MVA_RuleFit",
"MVA_RuleFit", nbin, -2.0, 2.0 );
199 if (Use[
"SVM_Gauss"]) histSVMG =
new TH1F(
"MVA_SVM_Gauss",
"MVA_SVM_Gauss", nbin, 0.0, 1.0 );
200 if (Use[
"SVM_Poly"]) histSVMP =
new TH1F(
"MVA_SVM_Poly",
"MVA_SVM_Poly", nbin, 0.0, 1.0 );
201 if (Use[
"SVM_Lin"]) histSVML =
new TH1F(
"MVA_SVM_Lin",
"MVA_SVM_Lin", nbin, 0.0, 1.0 );
202 if (Use[
"FDA_MT"]) histFDAMT =
new TH1F(
"MVA_FDA_MT",
"MVA_FDA_MT", nbin, -2.0, 3.0 );
203 if (Use[
"FDA_GA"]) histFDAGA =
new TH1F(
"MVA_FDA_GA",
"MVA_FDA_GA", nbin, -2.0, 3.0 );
204 if (Use[
"Category"]) histCat =
new TH1F(
"MVA_Category",
"MVA_Category", nbin, -2., 2. );
205 if (Use[
"Plugin"]) histPBdt =
new TH1F(
"MVA_PBDT",
"MVA_BDT", nbin, -0.8, 0.8 );
208 if (Use[
"PDEFoam"]) {
209 histPDEFoam =
new TH1F(
"MVA_PDEFoam",
"MVA_PDEFoam", nbin, 0, 1 );
210 histPDEFoamErr =
new TH1F(
"MVA_PDEFoamErr",
"MVA_PDEFoam error", nbin, 0, 1 );
211 histPDEFoamSig =
new TH1F(
"MVA_PDEFoamSig",
"MVA_PDEFoam significance", nbin, 0, 10 );
215 TH1F *probHistFi(0), *rarityHistFi(0);
217 probHistFi =
new TH1F(
"MVA_Fisher_Proba",
"MVA_Fisher_Proba", nbin, 0, 1 );
218 rarityHistFi =
new TH1F(
"MVA_Fisher_Rarity",
"MVA_Fisher_Rarity", nbin, 0, 1 );
226 TString fname =
"./tmva_example.root";
230 input =
TFile::Open(
"http://root.cern.ch/files/tmva_class_example.root" );
233 std::cout <<
"ERROR: could not open data file" << std::endl;
236 std::cout <<
"--- TMVAClassificationApp : Using input file: " << input->GetName() << std::endl;
245 std::cout <<
"--- Select signal sample" << std::endl;
254 Int_t nSelCutsGA = 0;
257 std::vector<Float_t> vecVar(4);
259 std::cout <<
"--- Processing: " << theTree->
GetEntries() <<
" events" << std::endl;
264 if (ievt%1000 == 0) std::cout <<
"--- ... Processing event: " << ievt << std::endl;
268 var1 = userVar1 + userVar2;
269 var2 = userVar1 - userVar2;
276 if (passed) nSelCutsGA++;
279 if (Use[
"Likelihood" ]) histLk ->Fill( reader->
EvaluateMVA(
"Likelihood method" ) );
280 if (Use[
"LikelihoodD" ]) histLkD ->Fill( reader->
EvaluateMVA(
"LikelihoodD method" ) );
281 if (Use[
"LikelihoodPCA"]) histLkPCA ->Fill( reader->
EvaluateMVA(
"LikelihoodPCA method" ) );
282 if (Use[
"LikelihoodKDE"]) histLkKDE ->Fill( reader->
EvaluateMVA(
"LikelihoodKDE method" ) );
283 if (Use[
"LikelihoodMIX"]) histLkMIX ->Fill( reader->
EvaluateMVA(
"LikelihoodMIX method" ) );
284 if (Use[
"PDERS" ]) histPD ->Fill( reader->
EvaluateMVA(
"PDERS method" ) );
285 if (Use[
"PDERSD" ]) histPDD ->Fill( reader->
EvaluateMVA(
"PDERSD method" ) );
286 if (Use[
"PDERSPCA" ]) histPDPCA ->Fill( reader->
EvaluateMVA(
"PDERSPCA method" ) );
287 if (Use[
"KNN" ]) histKNN ->Fill( reader->
EvaluateMVA(
"KNN method" ) );
288 if (Use[
"HMatrix" ]) histHm ->Fill( reader->
EvaluateMVA(
"HMatrix method" ) );
289 if (Use[
"Fisher" ]) histFi ->Fill( reader->
EvaluateMVA(
"Fisher method" ) );
290 if (Use[
"FisherG" ]) histFiG ->Fill( reader->
EvaluateMVA(
"FisherG method" ) );
291 if (Use[
"BoostedFisher"]) histFiB ->Fill( reader->
EvaluateMVA(
"BoostedFisher method" ) );
292 if (Use[
"LD" ]) histLD ->Fill( reader->
EvaluateMVA(
"LD method" ) );
293 if (Use[
"MLP" ]) histNn ->Fill( reader->
EvaluateMVA(
"MLP method" ) );
294 if (Use[
"MLPBFGS" ]) histNnbfgs ->Fill( reader->
EvaluateMVA(
"MLPBFGS method" ) );
295 if (Use[
"MLPBNN" ]) histNnbnn ->Fill( reader->
EvaluateMVA(
"MLPBNN method" ) );
296 if (Use[
"CFMlpANN" ]) histNnC ->Fill( reader->
EvaluateMVA(
"CFMlpANN method" ) );
297 if (Use[
"TMlpANN" ]) histNnT ->Fill( reader->
EvaluateMVA(
"TMlpANN method" ) );
298 if (Use[
"BDT" ]) histBdt ->Fill( reader->
EvaluateMVA(
"BDT method" ) );
299 if (Use[
"BDTD" ]) histBdtD ->Fill( reader->
EvaluateMVA(
"BDTD method" ) );
300 if (Use[
"BDTG" ]) histBdtG ->Fill( reader->
EvaluateMVA(
"BDTG method" ) );
301 if (Use[
"RuleFit" ]) histRf ->Fill( reader->
EvaluateMVA(
"RuleFit method" ) );
302 if (Use[
"SVM_Gauss" ]) histSVMG ->Fill( reader->
EvaluateMVA(
"SVM_Gauss method" ) );
303 if (Use[
"SVM_Poly" ]) histSVMP ->Fill( reader->
EvaluateMVA(
"SVM_Poly method" ) );
304 if (Use[
"SVM_Lin" ]) histSVML ->Fill( reader->
EvaluateMVA(
"SVM_Lin method" ) );
305 if (Use[
"FDA_MT" ]) histFDAMT ->Fill( reader->
EvaluateMVA(
"FDA_MT method" ) );
306 if (Use[
"FDA_GA" ]) histFDAGA ->Fill( reader->
EvaluateMVA(
"FDA_GA method" ) );
307 if (Use[
"Category" ]) histCat ->Fill( reader->
EvaluateMVA(
"Category method" ) );
308 if (Use[
"Plugin" ]) histPBdt ->Fill( reader->
EvaluateMVA(
"P_BDT method" ) );
311 if (Use[
"PDEFoam"]) {
314 histPDEFoam ->Fill( val );
315 histPDEFoamErr->Fill( err );
316 if (err>1.e-50) histPDEFoamSig->Fill( val/err );
321 probHistFi ->Fill( reader->
GetProba (
"Fisher method" ) );
322 rarityHistFi->Fill( reader->
GetRarity(
"Fisher method" ) );
328 std::cout <<
"--- End of event loop: "; sw.
Print();
331 if (Use[
"CutsGA"]) std::cout <<
"--- Efficiency for CutsGA method: " <<
double(nSelCutsGA)/theTree->
GetEntries()
332 <<
" (for a required signal efficiency of " << effS <<
")" << std::endl;
341 std::vector<Double_t> cutsMin;
342 std::vector<Double_t> cutsMax;
343 mcuts->
GetCuts( 0.7, cutsMin, cutsMax );
344 std::cout <<
"--- -------------------------------------------------------------" << std::endl;
345 std::cout <<
"--- Retrieve cut values for signal efficiency of 0.7 from Reader" << std::endl;
346 for (
UInt_t ivar=0; ivar<cutsMin.size(); ivar++) {
347 std::cout <<
"... Cut: "
352 << cutsMax[ivar] << std::endl;
354 std::cout <<
"--- -------------------------------------------------------------" << std::endl;
360 TFile *target =
new TFile(
"TMVApp.root",
"RECREATE" );
361 if (Use[
"Likelihood" ]) histLk ->Write();
362 if (Use[
"LikelihoodD" ]) histLkD ->Write();
363 if (Use[
"LikelihoodPCA"]) histLkPCA ->Write();
364 if (Use[
"LikelihoodKDE"]) histLkKDE ->Write();
365 if (Use[
"LikelihoodMIX"]) histLkMIX ->Write();
366 if (Use[
"PDERS" ]) histPD ->Write();
367 if (Use[
"PDERSD" ]) histPDD ->Write();
368 if (Use[
"PDERSPCA" ]) histPDPCA ->Write();
369 if (Use[
"KNN" ]) histKNN ->Write();
370 if (Use[
"HMatrix" ]) histHm ->Write();
371 if (Use[
"Fisher" ]) histFi ->Write();
372 if (Use[
"FisherG" ]) histFiG ->Write();
373 if (Use[
"BoostedFisher"]) histFiB ->Write();
374 if (Use[
"LD" ]) histLD ->Write();
375 if (Use[
"MLP" ]) histNn ->Write();
376 if (Use[
"MLPBFGS" ]) histNnbfgs ->Write();
377 if (Use[
"MLPBNN" ]) histNnbnn ->Write();
378 if (Use[
"CFMlpANN" ]) histNnC ->Write();
379 if (Use[
"TMlpANN" ]) histNnT ->Write();
380 if (Use[
"BDT" ]) histBdt ->Write();
381 if (Use[
"BDTD" ]) histBdtD ->Write();
382 if (Use[
"BDTG" ]) histBdtG ->Write();
383 if (Use[
"RuleFit" ]) histRf ->Write();
384 if (Use[
"SVM_Gauss" ]) histSVMG ->Write();
385 if (Use[
"SVM_Poly" ]) histSVMP ->Write();
386 if (Use[
"SVM_Lin" ]) histSVML ->Write();
387 if (Use[
"FDA_MT" ]) histFDAMT ->Write();
388 if (Use[
"FDA_GA" ]) histFDAGA ->Write();
389 if (Use[
"Category" ]) histCat ->Write();
390 if (Use[
"Plugin" ]) histPBdt ->Write();
393 if (Use[
"PDEFoam"]) { histPDEFoam->Write(); histPDEFoamErr->Write(); histPDEFoamSig->Write(); }
396 if (Use[
"Fisher"]) {
if (probHistFi != 0) probHistFi->Write();
if (rarityHistFi != 0) rarityHistFi->Write(); }
399 std::cout <<
"--- Created root file: \"TMVApp.root\" containing the MVA output histograms" << std::endl;
403 std::cout <<
"==> TMVAClassificationApplication is done!" << std::endl << std::endl;
406 int main(
int argc,
char** argv )
409 for (
int i=1; i<argc; i++) {
411 if(regMethod==
"-b" || regMethod==
"--batch")
continue;
413 methodList += regMethod;
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
int main(int argc, char **argv)
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Double_t GetRarity(const TString &methodTag, Double_t mvaVal=-9999999)
evaluates the MVA's rarity
const TString & GetInputVar(Int_t i) const
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
void Stop()
Stop the stopwatch.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Double_t GetCuts(Double_t effS, std::vector< Double_t > &cutMin, std::vector< Double_t > &cutMax) const
retrieve cut values for given signal efficiency
void TMVAClassificationApplication(TString myMethodList="")
Double_t GetMVAError() const
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
R__EXTERN TSystem * gSystem
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
Double_t EvaluateMVA(const std::vector< Float_t > &, const TString &methodTag, Double_t aux=0)
Evaluate a std::vector<float> of input data for a given method The parameter aux is obligatory for th...
virtual Long64_t GetEntries() const
A TTree object has a header with a name and a title.
Double_t GetProba(const TString &methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999)
evaluates probability of MVA for given set of input variables
MethodCuts * FindCutsMVA(const TString &methodTag)
special function for Cuts to avoid dynamic_casts in ROOT macros, which are not properly handled by CI...