ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MethodBase.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Kai Voss, Eckhard von Toerne, Jan Therhaag
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodBase *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
19  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
20  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
21  * *
22  * Copyright (c) 2005-2011: *
23  * CERN, Switzerland *
24  * U. of Victoria, Canada *
25  * MPI-K Heidelberg, Germany *
26  * U. of Bonn, Germany *
27  * *
28  * Redistribution and use in source and binary forms, with or without *
29  * modification, are permitted according to the terms listed in LICENSE *
30  * (http://tmva.sourceforge.net/LICENSE) *
31  * *
32  **********************************************************************************/
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 /* Begin_Html
37  Virtual base Class for all MVA method
38 
39  MethodBase hosts several specific evaluation methods.
40 
41  The kind of MVA that provides optimal performance in an analysis strongly
42  depends on the particular application. The evaluation factory provides a
43  number of numerical benchmark results to directly assess the performance
44  of the MVA training on the independent test sample. These are:
45  <ul>
46  <li> The <i>signal efficiency</i> at three representative background efficiencies
47  (which is 1 &minus; rejection).</li>
48  <li> The <i>significance</I> of an MVA estimator, defined by the difference
49  between the MVA mean values for signal and background, divided by the
50  quadratic sum of their root mean squares.</li>
51  <li> The <i>separation</i> of an MVA <i>x</i>, defined by the integral
52  &frac12;&int;(S(x) &minus; B(x))<sup>2</sup>/(S(x) + B(x))dx, where
53  S(x) and B(x) are the signal and background distributions, respectively.
54  The separation is zero for identical signal and background MVA shapes,
55  and it is one for disjunctive shapes.
56  <li> <a name="mu_transform">
57  The average, &int;x &mu;(S(x))dx, of the signal &mu;-transform.
58  The &mu;-transform of an MVA denotes the transformation that yields
59  a uniform background distribution. In this way, the signal distributions
60  S(x) can be directly compared among the various MVAs. The stronger S(x)
61  peaks towards one, the better is the discrimination of the MVA. The
62  &mu;-transform is
63  <a href=http://tel.ccsd.cnrs.fr/documents/archives0/00/00/29/91/index_fr.html>documented here</a>.
64  </ul>
65  The MVA standard output also prints the linear correlation coefficients between
66  signal and background, which can be useful to eliminate variables that exhibit too
67  strong correlations.
68 
69  End_Html */
70 //_______________________________________________________________________
71 
72 #include <iomanip>
73 #include <iostream>
74 #include <fstream>
75 #include <sstream>
76 #include <cstdlib>
77 #include <algorithm>
78 #include <limits>
79 
80 #include "TROOT.h"
81 #include "TSystem.h"
82 #include "TObjString.h"
83 #include "TQObject.h"
84 #include "TSpline.h"
85 #include "TMatrix.h"
86 #include "TMath.h"
87 #include "TH1F.h"
88 #include "TH2F.h"
89 #include "TFile.h"
90 #include "TKey.h"
91 #include "TGraph.h"
92 #include "Riostream.h"
93 #include "TXMLEngine.h"
94 
95 #include "TMVA/Config.h"
96 #include "TMVA/DataSetInfo.h"
97 #include "TMVA/DataSet.h"
98 #include "TMVA/Factory.h"
99 #include "TMVA/MsgLogger.h"
100 #include "TMVA/MethodBase.h"
101 #include "TMVA/PDF.h"
102 #include "TMVA/Ranking.h"
103 #include "TMVA/Results.h"
105 #include "TMVA/ResultsRegression.h"
106 #include "TMVA/ResultsMulticlass.h"
107 #include "TMVA/RootFinder.h"
108 #include "TMVA/Timer.h"
109 #include "TMVA/Tools.h"
110 #include "TMVA/TSpline1.h"
111 #include "TMVA/Types.h"
115 #include "TMVA/VariableInfo.h"
118 #include "TMVA/Version.h"
119 
121 
122 using std::endl;
123 using std::atof;
124 
125 //const Int_t MethodBase_MaxIterations_ = 200;
127 
128 //const Int_t NBIN_HIST_PLOT = 100;
129 const Int_t NBIN_HIST_HIGH = 10000;
130 
131 #ifdef _WIN32
132 /* Disable warning C4355: 'this' : used in base member initializer list */
133 #pragma warning ( disable : 4355 )
134 #endif
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// standard constructur
138 
140  Types::EMVA methodType,
141  const TString& methodTitle,
142  DataSetInfo& dsi,
143  const TString& theOption,
144  TDirectory* theBaseDir) :
145  IMethod(),
146  Configurable ( theOption ),
147  fTmpEvent ( 0 ),
148  fRanking ( 0 ),
149  fInputVars ( 0 ),
150  fAnalysisType ( Types::kNoAnalysisType ),
151  fRegressionReturnVal ( 0 ),
152  fMulticlassReturnVal ( 0 ),
153  fDisableWriting ( kFALSE ),
154  fDataSetInfo ( dsi ),
155  fSignalReferenceCut ( 0.5 ),
156  fSignalReferenceCutOrientation( 1. ),
157  fVariableTransformType ( Types::kSignal ),
158  fJobName ( jobName ),
159  fMethodName ( methodTitle ),
160  fMethodType ( methodType ),
161  fTestvar ( "" ),
162  fTMVATrainingVersion ( TMVA_VERSION_CODE ),
163  fROOTTrainingVersion ( ROOT_VERSION_CODE ),
164  fConstructedFromWeightFile ( kFALSE ),
165  fBaseDir ( 0 ),
166  fMethodBaseDir ( theBaseDir ),
167  fWeightFile ( "" ),
168  fEffS ( 0 ),
169  fDefaultPDF ( 0 ),
170  fMVAPdfS ( 0 ),
171  fMVAPdfB ( 0 ),
172  fSplS ( 0 ),
173  fSplB ( 0 ),
174  fSpleffBvsS ( 0 ),
175  fSplTrainS ( 0 ),
176  fSplTrainB ( 0 ),
177  fSplTrainEffBvsS ( 0 ),
178  fVarTransformString ( "None" ),
179  fTransformationPointer ( 0 ),
180  fTransformation ( dsi, methodTitle ),
181  fVerbose ( kFALSE ),
182  fVerbosityLevelString ( "Default" ),
183  fHelp ( kFALSE ),
184  fHasMVAPdfs ( kFALSE ),
185  fIgnoreNegWeightsInTraining( kFALSE ),
186  fSignalClass ( 0 ),
187  fBackgroundClass ( 0 ),
188  fSplRefS ( 0 ),
189  fSplRefB ( 0 ),
190  fSplTrainRefS ( 0 ),
191  fSplTrainRefB ( 0 ),
192  fSetupCompleted (kFALSE)
193 {
194  SetTestvarName();
195 
196  // default extension for weight files
197  SetWeightFileDir( gConfig().GetIONames().fWeightFileDir );
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// constructor used for Testing + Application of the MVA,
203 /// only (no training), using given WeightFiles
204 
206  DataSetInfo& dsi,
207  const TString& weightFile,
208  TDirectory* theBaseDir ) :
209  IMethod(),
210  Configurable(""),
211  fTmpEvent ( 0 ),
212  fRanking ( 0 ),
213  fInputVars ( 0 ),
214  fAnalysisType ( Types::kNoAnalysisType ),
215  fRegressionReturnVal ( 0 ),
216  fMulticlassReturnVal ( 0 ),
217  fDataSetInfo ( dsi ),
218  fSignalReferenceCut ( 0.5 ),
219  fVariableTransformType ( Types::kSignal ),
220  fJobName ( "" ),
221  fMethodName ( "MethodBase" ),
222  fMethodType ( methodType ),
223  fTestvar ( "" ),
224  fTMVATrainingVersion ( 0 ),
225  fROOTTrainingVersion ( 0 ),
226  fConstructedFromWeightFile ( kTRUE ),
227  fBaseDir ( theBaseDir ),
228  fMethodBaseDir ( 0 ),
229  fWeightFile ( weightFile ),
230  fEffS ( 0 ),
231  fDefaultPDF ( 0 ),
232  fMVAPdfS ( 0 ),
233  fMVAPdfB ( 0 ),
234  fSplS ( 0 ),
235  fSplB ( 0 ),
236  fSpleffBvsS ( 0 ),
237  fSplTrainS ( 0 ),
238  fSplTrainB ( 0 ),
239  fSplTrainEffBvsS ( 0 ),
240  fVarTransformString ( "None" ),
241  fTransformationPointer ( 0 ),
242  fTransformation ( dsi, "" ),
243  fVerbose ( kFALSE ),
244  fVerbosityLevelString ( "Default" ),
245  fHelp ( kFALSE ),
246  fHasMVAPdfs ( kFALSE ),
247  fIgnoreNegWeightsInTraining( kFALSE ),
248  fSignalClass ( 0 ),
249  fBackgroundClass ( 0 ),
250  fSplRefS ( 0 ),
251  fSplRefB ( 0 ),
252  fSplTrainRefS ( 0 ),
253  fSplTrainRefB ( 0 ),
254  fSetupCompleted (kFALSE)
255 {
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// destructor
260 
262 {
263  if (!fSetupCompleted) Log() << kFATAL << "Calling destructor of method which got never setup" << Endl;
264 
265  // destructor
266  if (fInputVars != 0) { fInputVars->clear(); delete fInputVars; }
267  if (fRanking != 0) delete fRanking;
268 
269  // PDFs
270  if (fDefaultPDF!= 0) { delete fDefaultPDF; fDefaultPDF = 0; }
271  if (fMVAPdfS != 0) { delete fMVAPdfS; fMVAPdfS = 0; }
272  if (fMVAPdfB != 0) { delete fMVAPdfB; fMVAPdfB = 0; }
273 
274  // Splines
275  if (fSplS) { delete fSplS; fSplS = 0; }
276  if (fSplB) { delete fSplB; fSplB = 0; }
277  if (fSpleffBvsS) { delete fSpleffBvsS; fSpleffBvsS = 0; }
278  if (fSplRefS) { delete fSplRefS; fSplRefS = 0; }
279  if (fSplRefB) { delete fSplRefB; fSplRefB = 0; }
280  if (fSplTrainRefS) { delete fSplTrainRefS; fSplTrainRefS = 0; }
281  if (fSplTrainRefB) { delete fSplTrainRefB; fSplTrainRefB = 0; }
282  if (fSplTrainEffBvsS) { delete fSplTrainEffBvsS; fSplTrainEffBvsS = 0; }
283 
284  for (Int_t i = 0; i < 2; i++ ) {
285  if (fEventCollections.at(i)) {
286  for (std::vector<Event*>::const_iterator it = fEventCollections.at(i)->begin();
287  it != fEventCollections.at(i)->end(); it++) {
288  delete (*it);
289  }
290  delete fEventCollections.at(i);
291  fEventCollections.at(i) = 0;
292  }
293  }
294 
295  if (fRegressionReturnVal) delete fRegressionReturnVal;
296  if (fMulticlassReturnVal) delete fMulticlassReturnVal;
297 }
298 
299 ////////////////////////////////////////////////////////////////////////////////
300 /// setup of methods
301 
303 {
304  if (fSetupCompleted) Log() << kFATAL << "Calling SetupMethod for the second time" << Endl;
305  InitBase();
306  DeclareBaseOptions();
307  Init();
308  DeclareOptions();
309  fSetupCompleted = kTRUE;
310 }
311 
312 ////////////////////////////////////////////////////////////////////////////////
313 /// process all options
314 /// the "CheckForUnusedOptions" is done in an independent call, since it may be overridden by derived class
315 /// (sometimes, eg, fitters are used which can only be implemented during training phase)
316 
318 {
319  ProcessBaseOptions();
320  ProcessOptions();
321 }
322 
323 ////////////////////////////////////////////////////////////////////////////////
324 /// check may be overridden by derived class
325 /// (sometimes, eg, fitters are used which can only be implemented during training phase)
326 
328 {
329  CheckForUnusedOptions();
330 }
331 
332 ////////////////////////////////////////////////////////////////////////////////
333 /// default initialization called by all constructors
334 
336 {
337  SetConfigDescription( "Configuration options for classifier architecture and tuning" );
338 
340  fNbinsMVAoutput = gConfig().fVariablePlotting.fNbinsMVAoutput;
341  fNbinsH = NBIN_HIST_HIGH;
342 
343  fSplTrainS = 0;
344  fSplTrainB = 0;
345  fSplTrainEffBvsS = 0;
346  fMeanS = -1;
347  fMeanB = -1;
348  fRmsS = -1;
349  fRmsB = -1;
350  fXmin = DBL_MAX;
351  fXmax = -DBL_MAX;
352  fTxtWeightsOnly = kTRUE;
353  fSplRefS = 0;
354  fSplRefB = 0;
355 
356  fTrainTime = -1.;
357  fTestTime = -1.;
358 
359  fRanking = 0;
360 
361  // temporary until the move to DataSet is complete
362  fInputVars = new std::vector<TString>;
363  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
364  fInputVars->push_back(DataInfo().GetVariableInfo(ivar).GetLabel());
365  }
366  fRegressionReturnVal = 0;
367  fMulticlassReturnVal = 0;
368 
369  fEventCollections.resize( 2 );
370  fEventCollections.at(0) = 0;
371  fEventCollections.at(1) = 0;
372 
373  // define "this" pointer
374  ResetThisBase();
375 
376  // retrieve signal and background class index
377  if (DataInfo().GetClassInfo("Signal") != 0) {
378  fSignalClass = DataInfo().GetClassInfo("Signal")->GetNumber();
379  }
380  if (DataInfo().GetClassInfo("Background") != 0) {
381  fBackgroundClass = DataInfo().GetClassInfo("Background")->GetNumber();
382  }
383 
384  SetConfigDescription( "Configuration options for MVA method" );
385  SetConfigName( TString("Method") + GetMethodTypeName() );
386 }
387 
388 ////////////////////////////////////////////////////////////////////////////////
389 /// define the options (their key words) that can be set in the option string
390 /// here the options valid for ALL MVA methods are declared.
391 /// know options: VariableTransform=None,Decorrelated,PCA to use transformed variables
392 /// instead of the original ones
393 /// VariableTransformType=Signal,Background which decorrelation matrix to use
394 /// in the method. Only the Likelihood
395 /// Method can make proper use of independent
396 /// transformations of signal and background
397 /// fNbinsMVAPdf = 50 Number of bins used to create a PDF of MVA
398 /// fNsmoothMVAPdf = 2 Number of times a histogram is smoothed before creating the PDF
399 /// fHasMVAPdfs create PDFs for the MVA outputs
400 /// V for Verbose output (!V) for non verbos
401 /// H for Help message
402 
404 {
405  DeclareOptionRef( fVerbose, "V", "Verbose output (short form of \"VerbosityLevel\" below - overrides the latter one)" );
406 
407  DeclareOptionRef( fVerbosityLevelString="Default", "VerbosityLevel", "Verbosity level" );
408  AddPreDefVal( TString("Default") ); // uses default defined in MsgLogger header
409  AddPreDefVal( TString("Debug") );
410  AddPreDefVal( TString("Verbose") );
411  AddPreDefVal( TString("Info") );
412  AddPreDefVal( TString("Warning") );
413  AddPreDefVal( TString("Error") );
414  AddPreDefVal( TString("Fatal") );
415 
416  // If True (default): write all training results (weights) as text files only;
417  // if False: write also in ROOT format (not available for all methods - will abort if not
418  fTxtWeightsOnly = kTRUE; // OBSOLETE !!!
419  fNormalise = kFALSE; // OBSOLETE !!!
420 
421  DeclareOptionRef( fVarTransformString, "VarTransform", "List of variable transformations performed before training, e.g., \"D_Background,P_Signal,G,N_AllClasses\" for: \"Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)\"" );
422 
423  DeclareOptionRef( fHelp, "H", "Print method-specific help message" );
424 
425  DeclareOptionRef( fHasMVAPdfs, "CreateMVAPdfs", "Create PDFs for classifier outputs (signal and background)" );
426 
427  DeclareOptionRef( fIgnoreNegWeightsInTraining, "IgnoreNegWeightsInTraining",
428  "Events with negative weights are ignored in the training (but are included for testing and performance evaluation)" );
429 }
430 
431 ////////////////////////////////////////////////////////////////////////////////
432 /// the option string is decoded, for availabel options see "DeclareOptions"
433 
435 {
436  if (HasMVAPdfs()) {
437  // setting the default bin num... maybe should be static ? ==> Please no static (JS)
438  // You can't use the logger in the constructor!!! Log() << kINFO << "Create PDFs" << Endl;
439  // reading every PDF's definition and passing the option string to the next one to be read and marked
440  fDefaultPDF = new PDF( TString(GetName())+"_PDF", GetOptions(), "MVAPdf" );
441  fDefaultPDF->DeclareOptions();
442  fDefaultPDF->ParseOptions();
443  fDefaultPDF->ProcessOptions();
444  fMVAPdfB = new PDF( TString(GetName())+"_PDFBkg", fDefaultPDF->GetOptions(), "MVAPdfBkg", fDefaultPDF );
445  fMVAPdfB->DeclareOptions();
446  fMVAPdfB->ParseOptions();
447  fMVAPdfB->ProcessOptions();
448  fMVAPdfS = new PDF( TString(GetName())+"_PDFSig", fMVAPdfB->GetOptions(), "MVAPdfSig", fDefaultPDF );
449  fMVAPdfS->DeclareOptions();
450  fMVAPdfS->ParseOptions();
451  fMVAPdfS->ProcessOptions();
452 
453  // the final marked option string is written back to the original methodbase
454  SetOptions( fMVAPdfS->GetOptions() );
455  }
456 
457  TMVA::MethodBase::CreateVariableTransforms( fVarTransformString,
458  DataInfo(),
459  GetTransformationHandler(),
460  Log() );
461 
462  if (!HasMVAPdfs()) {
463  if (fDefaultPDF!= 0) { delete fDefaultPDF; fDefaultPDF = 0; }
464  if (fMVAPdfS != 0) { delete fMVAPdfS; fMVAPdfS = 0; }
465  if (fMVAPdfB != 0) { delete fMVAPdfB; fMVAPdfB = 0; }
466  }
467 
468  if (fVerbose) { // overwrites other settings
469  fVerbosityLevelString = TString("Verbose");
470  Log().SetMinType( kVERBOSE );
471  }
472  else if (fVerbosityLevelString == "Debug" ) Log().SetMinType( kDEBUG );
473  else if (fVerbosityLevelString == "Verbose" ) Log().SetMinType( kVERBOSE );
474  else if (fVerbosityLevelString == "Info" ) Log().SetMinType( kINFO );
475  else if (fVerbosityLevelString == "Warning" ) Log().SetMinType( kWARNING );
476  else if (fVerbosityLevelString == "Error" ) Log().SetMinType( kERROR );
477  else if (fVerbosityLevelString == "Fatal" ) Log().SetMinType( kFATAL );
478  else if (fVerbosityLevelString != "Default" ) {
479  Log() << kFATAL << "<ProcessOptions> Verbosity level type '"
480  << fVerbosityLevelString << "' unknown." << Endl;
481  }
482  Event::SetIgnoreNegWeightsInTraining(fIgnoreNegWeightsInTraining);
483 }
484 
485 ////////////////////////////////////////////////////////////////////////////////
486 /// create variable transformations
487 
489  TMVA::DataSetInfo& dataInfo,
490  TMVA::TransformationHandler& transformationHandler,
492 {
493  TString trafoDefinition(trafoDefinitionIn);
494  if (trafoDefinition == "None") return; // no transformations
495 
496  // workaround for transformations to complicated to be handled by makeclass
497  // count number of transformations with incomplete set of variables
498  TString trafoDefinitionCheck(trafoDefinitionIn);
499  int npartial = 0, ntrafo=0;
500  for (Int_t pos = 0, siz = trafoDefinition.Sizeof(); pos < siz; ++pos) {
501  TString ch = trafoDefinition(pos,1);
502  if ( ch == "(" ) npartial++;
503  if ( ch == "+" || ch == ",") ntrafo++;
504  }
505  if (npartial>1) {
506  log << kWARNING << "The use of multiple partial variable transformations during the application phase can be properly invoked via the \"Reader\", but it is not yet implemented in \"MakeClass\", the creation mechanism for standalone C++ application classes. The standalone C++ class produced by this training job is thus INCOMPLETE AND MUST NOT BE USED! The transformation in question is: " << trafoDefinitionIn << Endl; // ToDo make info and do not write the standalone class
507  //
508  // this does not work since this function is static
509  // fDisableWriting=true; // disable creation of stand-alone class
510  // ToDo we need to tell the transformation that it cannot write itself
511  }
512  // workaround end
513 
514  Int_t parenthesisCount = 0;
515  for (Int_t position = 0, size = trafoDefinition.Sizeof(); position < size; ++position) {
516  TString ch = trafoDefinition(position,1);
517  if (ch == "(") ++parenthesisCount;
518  else if (ch == ")") --parenthesisCount;
519  else if (ch == "," && parenthesisCount == 0) trafoDefinition.Replace(position,1,'+');
520  }
521 
522  TList* trList = gTools().ParseFormatLine( trafoDefinition, "+" );
523  TListIter trIt(trList);
524  while (TObjString* os = (TObjString*)trIt()) {
525  TString tdef = os->GetString();
526  Int_t idxCls = -1;
527 
528  TString variables = "";
529  if (tdef.Contains("(")) { // contains selection of variables
530  Ssiz_t parStart = tdef.Index( "(" );
531  Ssiz_t parLen = tdef.Index( ")", parStart )-parStart+1;
532 
533  variables = tdef(parStart,parLen);
534  tdef.Remove(parStart,parLen);
535  variables.Remove(parLen-1,1);
536  variables.Remove(0,1);
537  }
538 
539  TList* trClsList = gTools().ParseFormatLine( tdef, "_" ); // split entry to get trf-name and class-name
540  TListIter trClsIt(trClsList);
541  if (trClsList->GetSize() < 1) log << kFATAL << "Incorrect transformation string provided." << Endl;
542  const TString& trName = ((TObjString*)trClsList->At(0))->GetString();
543 
544  if (trClsList->GetEntries() > 1) {
545  TString trCls = "AllClasses";
546  ClassInfo *ci = NULL;
547  trCls = ((TObjString*)trClsList->At(1))->GetString();
548  if (trCls != "AllClasses") {
549  ci = dataInfo.GetClassInfo( trCls );
550  if (ci == NULL)
551  log << kFATAL << "Class " << trCls << " not known for variable transformation "
552  << trName << ", please check." << Endl;
553  else
554  idxCls = ci->GetNumber();
555  }
556  }
557 
558  VariableTransformBase* transformation = NULL;
559  if (trName == "I" || trName == "Ident" || trName == "Identity") {
560  if (variables.Length() == 0) variables = "_V_";
561  transformation = new VariableIdentityTransform( dataInfo);
562  }
563  else if (trName == "D" || trName == "Deco" || trName == "Decorrelate") {
564  if (variables.Length() == 0) variables = "_V_";
565  transformation = new VariableDecorrTransform( dataInfo);
566  }
567  else if (trName == "P" || trName == "PCA") {
568  if (variables.Length() == 0) variables = "_V_";
569  transformation = new VariablePCATransform ( dataInfo);
570  }
571  else if (trName == "U" || trName == "Uniform") {
572  if (variables.Length() == 0) variables = "_V_,_T_";
573  transformation = new VariableGaussTransform ( dataInfo, "Uniform" );
574  }
575  else if (trName == "G" || trName == "Gauss") {
576  if (variables.Length() == 0) variables = "_V_";
577  transformation = new VariableGaussTransform ( dataInfo);
578  }
579  else if (trName == "N" || trName == "Norm" || trName == "Normalise" || trName == "Normalize") {
580  if (variables.Length() == 0) variables = "_V_,_T_";
581  transformation = new VariableNormalizeTransform( dataInfo);
582  }
583  else log << kFATAL << "<ProcessOptions> Variable transform '"
584  << trName << "' unknown." << Endl;
585 
586  if (transformation) {
587  ClassInfo* clsInfo = dataInfo.GetClassInfo(idxCls);
588  if (clsInfo )
589  log << kINFO << "Create Transformation \"" << trName << "\" with reference class "
590  << clsInfo->GetName() << "=("<< idxCls <<")"<<Endl;
591  else
592  log << kINFO << "Create Transformation \"" << trName << "\" with events from all classes." << Endl;
593 
594  transformation->SelectInput( variables );
595  transformationHandler.AddTransformation(transformation, idxCls);
596  }
597  }
598  return;
599 }
600 
601 ////////////////////////////////////////////////////////////////////////////////
602 /// options that are used ONLY for the READER to ensure backward compatibility
603 /// they are hence without any effect (the reader is only reading the training
604 /// options that HAD been used at the training of the .xml weightfile at hand
605 
607 {
608  DeclareOptionRef( fNormalise=kFALSE, "Normalise", "Normalise input variables" ); // don't change the default !!!
609  DeclareOptionRef( fUseDecorr=kFALSE, "D", "Use-decorrelated-variables flag" );
610  DeclareOptionRef( fVariableTransformTypeString="Signal", "VarTransformType",
611  "Use signal or background events to derive for variable transformation (the transformation is applied on both types of, course)" );
612  AddPreDefVal( TString("Signal") );
613  AddPreDefVal( TString("Background") );
614  DeclareOptionRef( fTxtWeightsOnly=kTRUE, "TxtWeightFilesOnly", "If True: write all training results (weights) as text files (False: some are written in ROOT format)" );
615  // Why on earth ?? was this here? Was the verbosity level option meant to 'disapear? Not a good idea i think..
616  // DeclareOptionRef( fVerbosityLevelString="Default", "VerboseLevel", "Verbosity level" );
617  // AddPreDefVal( TString("Default") ); // uses default defined in MsgLogger header
618  // AddPreDefVal( TString("Debug") );
619  // AddPreDefVal( TString("Verbose") );
620  // AddPreDefVal( TString("Info") );
621  // AddPreDefVal( TString("Warning") );
622  // AddPreDefVal( TString("Error") );
623  // AddPreDefVal( TString("Fatal") );
624  DeclareOptionRef( fNbinsMVAPdf = 60, "NbinsMVAPdf", "Number of bins used for the PDFs of classifier outputs" );
625  DeclareOptionRef( fNsmoothMVAPdf = 2, "NsmoothMVAPdf", "Number of smoothing iterations for classifier PDFs" );
626 }
627 
628 
629 ////////////////////////////////////////////////////////////////////////////////
630 /// call the Optimzier with the set of paremeters and ranges that
631 /// are meant to be tuned.
632 
633 std::map<TString,Double_t> TMVA::MethodBase::OptimizeTuningParameters(TString /* fomType */ , TString /* fitType */)
634 {
635  // this is just a dummy... needs to be implemented for each method
636  // individually (as long as we don't have it automatized via the
637  // configuraion string
638 
639  Log() << kWARNING << "Parameter optimization is not yet implemented for method "
640  << GetName() << Endl;
641  Log() << kWARNING << "Currently we need to set hardcoded which parameter is tuned in which ranges"<<Endl;
642 
643  std::map<TString,Double_t> tunedParameters;
644  tunedParameters.size(); // just to get rid of "unused" warning
645  return tunedParameters;
646 
647 }
648 
649 ////////////////////////////////////////////////////////////////////////////////
650 /// set the tuning parameters accoding to the argument
651 /// This is just a dummy .. have a look at the MethodBDT how you could
652 /// perhaps implment the same thing for the other Classifiers..
653 
654 void TMVA::MethodBase::SetTuneParameters(std::map<TString,Double_t> /* tuneParameters */)
655 {
656 }
657 
658 ////////////////////////////////////////////////////////////////////////////////
659 
661 {
662  Data()->SetCurrentType(Types::kTraining);
663  Event::SetIsTraining(kTRUE); // used to set negative event weights to zero if chosen to do so
664 
665  // train the MVA method
666  if (Help()) PrintHelpMessage();
667 
668  // all histograms should be created in the method's subdirectory
669  BaseDir()->cd();
670 
671  // once calculate all the transformation (e.g. the sequence of Decorr:Gauss:Decorr)
672  // needed for this classifier
673  GetTransformationHandler().CalcTransformations(Data()->GetEventCollection());
674 
675  // call training of derived MVA
676  Log() << kINFO << "Begin training" << Endl;
677  Long64_t nEvents = Data()->GetNEvents();
678  Timer traintimer( nEvents, GetName(), kTRUE );
679  Train();
680  Log() << kINFO << "End of training " << Endl;
681  SetTrainTime(traintimer.ElapsedSeconds());
682  Log() << kINFO << "Elapsed time for training with " << nEvents << " events: "
683  << traintimer.GetElapsedTime() << " " << Endl;
684 
685  Log() << kINFO << "Create MVA output for ";
686 
687  // create PDFs for the signal and background MVA distributions (if required)
688  if (DoMulticlass()) {
689  Log() << "Multiclass classification on training sample" << Endl;
690  AddMulticlassOutput(Types::kTraining);
691  }
692  else if (!DoRegression()) {
693 
694  Log() << "classification on training sample" << Endl;
695  AddClassifierOutput(Types::kTraining);
696  if (HasMVAPdfs()) {
697  CreateMVAPdfs();
698  AddClassifierOutputProb(Types::kTraining);
699  }
700 
701  } else {
702 
703  Log() << "regression on training sample" << Endl;
704  AddRegressionOutput( Types::kTraining );
705 
706  if (HasMVAPdfs() ) {
707  Log() << "Create PDFs" << Endl;
708  CreateMVAPdfs();
709  }
710  }
711 
712  // write the current MVA state into stream
713  // produced are one text file and one ROOT file
714  if (!fDisableWriting ) WriteStateToFile();
715 
716  // produce standalone make class (presently only supported for classification)
717  if ((!DoRegression()) && (!fDisableWriting)) MakeClass();
718 
719  // write additional monitoring histograms to main target file (not the weight file)
720  // again, make sure the histograms go into the method's subdirectory
721  BaseDir()->cd();
722  WriteMonitoringHistosToFile();
723 }
724 
725 ////////////////////////////////////////////////////////////////////////////////
726 
728 {
729  if (!DoRegression()) Log() << kFATAL << "Trying to use GetRegressionDeviation() with a classification job" << Endl;
730  Log() << kINFO << "Create results for " << (type==Types::kTraining?"training":"testing") << Endl;
732  bool truncate = false;
733  TH1F* h1 = regRes->QuadraticDeviation( tgtNum , truncate, 1.);
734  stddev = sqrt(h1->GetMean());
735  truncate = true;
736  Double_t yq[1], xq[]={0.9};
737  h1->GetQuantiles(1,yq,xq);
738  TH1F* h2 = regRes->QuadraticDeviation( tgtNum , truncate, yq[0]);
739  stddev90Percent = sqrt(h2->GetMean());
740  delete h1;
741  delete h2;
742 }
743 
744 ////////////////////////////////////////////////////////////////////////////////
745 /// prepare tree branch with the method's discriminating variable
746 
748 {
749  Data()->SetCurrentType(type);
750 
751  Log() << kINFO << "Create results for " << (type==Types::kTraining?"training":"testing") << Endl;
752 
753  ResultsRegression* regRes = (ResultsRegression*)Data()->GetResults(GetMethodName(), type, Types::kRegression);
754 
755  Long64_t nEvents = Data()->GetNEvents();
756 
757  // use timer
758  Timer timer( nEvents, GetName(), kTRUE );
759 
760  Log() << kINFO << "Evaluation of " << GetMethodName() << " on "
761  << (type==Types::kTraining?"training":"testing") << " sample" << Endl;
762 
763  regRes->Resize( nEvents );
764  for (Int_t ievt=0; ievt<nEvents; ievt++) {
765  Data()->SetCurrentEvent(ievt);
766  std::vector< Float_t > vals = GetRegressionValues();
767  regRes->SetValue( vals, ievt );
768  timer.DrawProgressBar( ievt );
769  }
770 
771  Log() << kINFO << "Elapsed time for evaluation of " << nEvents << " events: "
772  << timer.GetElapsedTime() << " " << Endl;
773 
774  // store time used for testing
775  if (type==Types::kTesting)
776  SetTestTime(timer.ElapsedSeconds());
777 
778  TString histNamePrefix(GetTestvarName());
779  histNamePrefix += (type==Types::kTraining?"train":"test");
780  regRes->CreateDeviationHistograms( histNamePrefix );
781 }
782 
783 ////////////////////////////////////////////////////////////////////////////////
784 /// prepare tree branch with the method's discriminating variable
785 
787 {
788  Data()->SetCurrentType(type);
789 
790  Log() << kINFO << "Create results for " << (type==Types::kTraining?"training":"testing") << Endl;
791 
792  ResultsMulticlass* resMulticlass = dynamic_cast<ResultsMulticlass*>(Data()->GetResults(GetMethodName(), type, Types::kMulticlass));
793  if (!resMulticlass) Log() << kFATAL<< "unable to create pointer in AddMulticlassOutput, exiting."<<Endl;
794 
795  Long64_t nEvents = Data()->GetNEvents();
796 
797  // use timer
798  Timer timer( nEvents, GetName(), kTRUE );
799 
800  Log() << kINFO << "Multiclass evaluation of " << GetMethodName() << " on "
801  << (type==Types::kTraining?"training":"testing") << " sample" << Endl;
802 
803  resMulticlass->Resize( nEvents );
804  for (Int_t ievt=0; ievt<nEvents; ievt++) {
805  Data()->SetCurrentEvent(ievt);
806  std::vector< Float_t > vals = GetMulticlassValues();
807  resMulticlass->SetValue( vals, ievt );
808  timer.DrawProgressBar( ievt );
809  }
810 
811  Log() << kINFO << "Elapsed time for evaluation of " << nEvents << " events: "
812  << timer.GetElapsedTime() << " " << Endl;
813 
814  // store time used for testing
815  if (type==Types::kTesting)
816  SetTestTime(timer.ElapsedSeconds());
817 
818  TString histNamePrefix(GetTestvarName());
819  histNamePrefix += (type==Types::kTraining?"_Train":"_Test");
820  resMulticlass->CreateMulticlassHistos( histNamePrefix, fNbinsMVAoutput, fNbinsH );
821 }
822 
823 
824 
825 ////////////////////////////////////////////////////////////////////////////////
826 
827 void TMVA::MethodBase::NoErrorCalc(Double_t* const err, Double_t* const errUpper) {
828  if (err) *err=-1;
829  if (errUpper) *errUpper=-1;
830 }
831 
832 ////////////////////////////////////////////////////////////////////////////////
833 
834 Double_t TMVA::MethodBase::GetMvaValue( const Event* const ev, Double_t* err, Double_t* errUpper ) {
835  fTmpEvent = ev;
836  Double_t val = GetMvaValue(err, errUpper);
837  fTmpEvent = 0;
838  return val;
839 }
840 
841 ////////////////////////////////////////////////////////////////////////////////
842 /// uses a pre-set cut on the MVA output (SetSignalReferenceCut and SetSignalReferenceCutOrientation)
843 /// for a quick determination if an event would be selected as signal or background
844 
846  return GetMvaValue()*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ? kTRUE : kFALSE;
847 }
848 ////////////////////////////////////////////////////////////////////////////////
849 /// uses a pre-set cut on the MVA output (SetSignalReferenceCut and SetSignalReferenceCutOrientation)
850 /// for a quick determination if an event with this mva output value would tbe selected as signal or background
851 
853  return mvaVal*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ? kTRUE : kFALSE;
854 }
855 
856 ////////////////////////////////////////////////////////////////////////////////
857 /// prepare tree branch with the method's discriminating variable
858 
860 {
861  Data()->SetCurrentType(type);
862 
863  ResultsClassification* clRes =
865 
866  Long64_t nEvents = Data()->GetNEvents();
867 
868  // use timer
869  Timer timer( nEvents, GetName(), kTRUE );
870 
871  Log() << kINFO << "Evaluation of " << GetMethodName() << " on "
872  << (type==Types::kTraining?"training":"testing") << " sample (" << nEvents << " events)" << Endl;
873 
874  clRes->Resize( nEvents );
875  for (Int_t ievt=0; ievt<nEvents; ievt++) {
876  Data()->SetCurrentEvent(ievt);
877  clRes->SetValue( GetMvaValue(), ievt );
878 
879  // print progress
880  Int_t modulo = Int_t(nEvents/100);
881  if (modulo <= 0 ) modulo = 1;
882  if (ievt%modulo == 0) timer.DrawProgressBar( ievt );
883  }
884 
885  Log() << kINFO << "Elapsed time for evaluation of " << nEvents << " events: "
886  << timer.GetElapsedTime() << " " << Endl;
887 
888  // store time used for testing
889  if (type==Types::kTesting)
890  SetTestTime(timer.ElapsedSeconds());
891 
892 }
893 
894 ////////////////////////////////////////////////////////////////////////////////
895 /// prepare tree branch with the method's discriminating variable
896 
898 {
899  Data()->SetCurrentType(type);
900 
901  ResultsClassification* mvaProb =
902  (ResultsClassification*)Data()->GetResults(TString("prob_")+GetMethodName(), type, Types::kClassification );
903 
904  Long64_t nEvents = Data()->GetNEvents();
905 
906  // use timer
907  Timer timer( nEvents, GetName(), kTRUE );
908 
909  Log() << kINFO << "Evaluation of " << GetMethodName() << " on "
910  << (type==Types::kTraining?"training":"testing") << " sample" << Endl;
911 
912  mvaProb->Resize( nEvents );
913  for (Int_t ievt=0; ievt<nEvents; ievt++) {
914 
915  Data()->SetCurrentEvent(ievt);
916  Float_t proba = ((Float_t)GetProba( GetMvaValue(), 0.5 ));
917  if (proba < 0) break;
918  mvaProb->SetValue( proba, ievt );
919 
920  // print progress
921  Int_t modulo = Int_t(nEvents/100);
922  if (modulo <= 0 ) modulo = 1;
923  if (ievt%modulo == 0) timer.DrawProgressBar( ievt );
924  }
925 
926  Log() << kINFO << "Elapsed time for evaluation of " << nEvents << " events: "
927  << timer.GetElapsedTime() << " " << Endl;
928 }
929 
930 ////////////////////////////////////////////////////////////////////////////////
931 /// calculate <sum-of-deviation-squared> of regression output versus "true" value from test sample
932 ///
933 /// bias = average deviation
934 /// dev = average absolute deviation
935 /// rms = rms of deviation
936 ///
937 
939  Double_t& dev, Double_t& devT,
940  Double_t& rms, Double_t& rmsT,
941  Double_t& mInf, Double_t& mInfT,
942  Double_t& corr,
944 {
945  Types::ETreeType savedType = Data()->GetCurrentType();
946  Data()->SetCurrentType(type);
947 
948  bias = 0; biasT = 0; dev = 0; devT = 0; rms = 0; rmsT = 0;
949  Double_t sumw = 0;
950  Double_t m1 = 0, m2 = 0, s1 = 0, s2 = 0, s12 = 0; // for correlation
951  const Int_t nevt = GetNEvents();
952  Float_t* rV = new Float_t[nevt];
953  Float_t* tV = new Float_t[nevt];
954  Float_t* wV = new Float_t[nevt];
955  Float_t xmin = 1e30, xmax = -1e30;
956  for (Long64_t ievt=0; ievt<nevt; ievt++) {
957 
958  const Event* ev = Data()->GetEvent(ievt); // NOTE: need untransformed event here !
959  Float_t t = ev->GetTarget(0);
960  Float_t w = ev->GetWeight();
961  Float_t r = GetRegressionValues()[0];
962  Float_t d = (r-t);
963 
964  // find min/max
965  xmin = TMath::Min(xmin, TMath::Min(t, r));
966  xmax = TMath::Max(xmax, TMath::Max(t, r));
967 
968  // store for truncated RMS computation
969  rV[ievt] = r;
970  tV[ievt] = t;
971  wV[ievt] = w;
972 
973  // compute deviation-squared
974  sumw += w;
975  bias += w * d;
976  dev += w * TMath::Abs(d);
977  rms += w * d * d;
978 
979  // compute correlation between target and regression estimate
980  m1 += t*w; s1 += t*t*w;
981  m2 += r*w; s2 += r*r*w;
982  s12 += t*r;
983  }
984 
985  // standard quantities
986  bias /= sumw;
987  dev /= sumw;
988  rms /= sumw;
989  rms = TMath::Sqrt(rms - bias*bias);
990 
991  // correlation
992  m1 /= sumw;
993  m2 /= sumw;
994  corr = s12/sumw - m1*m2;
995  corr /= TMath::Sqrt( (s1/sumw - m1*m1) * (s2/sumw - m2*m2) );
996 
997  // create histogram required for computeation of mutual information
998  TH2F* hist = new TH2F( "hist", "hist", 150, xmin, xmax, 100, xmin, xmax );
999  TH2F* histT = new TH2F( "histT", "histT", 150, xmin, xmax, 100, xmin, xmax );
1000 
1001  // compute truncated RMS and fill histogram
1002  Double_t devMax = bias + 2*rms;
1003  Double_t devMin = bias - 2*rms;
1004  sumw = 0;
1005  int ic=0;
1006  for (Long64_t ievt=0; ievt<nevt; ievt++) {
1007  Float_t d = (rV[ievt] - tV[ievt]);
1008  hist->Fill( rV[ievt], tV[ievt], wV[ievt] );
1009  if (d >= devMin && d <= devMax) {
1010  sumw += wV[ievt];
1011  biasT += wV[ievt] * d;
1012  devT += wV[ievt] * TMath::Abs(d);
1013  rmsT += wV[ievt] * d * d;
1014  histT->Fill( rV[ievt], tV[ievt], wV[ievt] );
1015  ic++;
1016  }
1017  }
1018  biasT /= sumw;
1019  devT /= sumw;
1020  rmsT /= sumw;
1021  rmsT = TMath::Sqrt(rmsT - biasT*biasT);
1022  mInf = gTools().GetMutualInformation( *hist );
1023  mInfT = gTools().GetMutualInformation( *histT );
1024 
1025  delete hist;
1026  delete histT;
1027 
1028  delete [] rV;
1029  delete [] tV;
1030  delete [] wV;
1031 
1032  Data()->SetCurrentType(savedType);
1033 }
1034 
1035 
1036 ////////////////////////////////////////////////////////////////////////////////
1037 /// test multiclass classification
1038 
1040 {
1041  ResultsMulticlass* resMulticlass = dynamic_cast<ResultsMulticlass*>(Data()->GetResults(GetMethodName(), Types::kTesting, Types::kMulticlass));
1042  if (!resMulticlass) Log() << kFATAL<< "unable to create pointer in TestMulticlass, exiting."<<Endl;
1043  Log() << kINFO << "Determine optimal multiclass cuts for test data..." << Endl;
1044  for (UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
1045  resMulticlass->GetBestMultiClassCuts(icls);
1046  }
1047 }
1048 
1049 
1050 ////////////////////////////////////////////////////////////////////////////////
1051 /// initialization
1052 
1054 {
1055  Data()->SetCurrentType(Types::kTesting);
1056 
1057  ResultsClassification* mvaRes = dynamic_cast<ResultsClassification*>
1059 
1060  // sanity checks: tree must exist, and theVar must be in tree
1061  if (0==mvaRes && !(GetMethodTypeName().Contains("Cuts"))) {
1062  Log() << "mvaRes " << mvaRes << " GetMethodTypeName " << GetMethodTypeName()
1063  << " contains " << !(GetMethodTypeName().Contains("Cuts")) << Endl;
1064  Log() << kFATAL << "<TestInit> Test variable " << GetTestvarName()
1065  << " not found in tree" << Endl;
1066  }
1067 
1068  // basic statistics operations are made in base class
1069  gTools().ComputeStat( GetEventCollection(Types::kTesting), mvaRes->GetValueVector(),
1070  fMeanS, fMeanB, fRmsS, fRmsB, fXmin, fXmax, fSignalClass );
1071 
1072  // choose reasonable histogram ranges, by removing outliers
1073  Double_t nrms = 10;
1074  fXmin = TMath::Max( TMath::Min( fMeanS - nrms*fRmsS, fMeanB - nrms*fRmsB ), fXmin );
1075  fXmax = TMath::Min( TMath::Max( fMeanS + nrms*fRmsS, fMeanB + nrms*fRmsB ), fXmax );
1076 
1077  // determine cut orientation
1078  fCutOrientation = (fMeanS > fMeanB) ? kPositive : kNegative;
1079 
1080  // fill 2 types of histograms for the various analyses
1081  // this one is for actual plotting
1082 
1083  Double_t sxmax = fXmax+0.00001;
1084 
1085  // classifier response distributions for training sample
1086  // MVA plots used for graphics representation (signal)
1087  TH1* mva_s = new TH1D( GetTestvarName() + "_S",GetTestvarName() + "_S", fNbinsMVAoutput, fXmin, sxmax );
1088  TH1* mva_b = new TH1D( GetTestvarName() + "_B",GetTestvarName() + "_B", fNbinsMVAoutput, fXmin, sxmax );
1089  mvaRes->Store(mva_s, "MVA_S");
1090  mvaRes->Store(mva_b, "MVA_B");
1091  mva_s->Sumw2();
1092  mva_b->Sumw2();
1093 
1094  TH1* proba_s = 0;
1095  TH1* proba_b = 0;
1096  TH1* rarity_s = 0;
1097  TH1* rarity_b = 0;
1098  if (HasMVAPdfs()) {
1099  // P(MVA) plots used for graphics representation
1100  proba_s = new TH1D( GetTestvarName() + "_Proba_S", GetTestvarName() + "_Proba_S", fNbinsMVAoutput, 0.0, 1.0 );
1101  proba_b = new TH1D( GetTestvarName() + "_Proba_B", GetTestvarName() + "_Proba_B", fNbinsMVAoutput, 0.0, 1.0 );
1102  mvaRes->Store(proba_s, "Prob_S");
1103  mvaRes->Store(proba_b, "Prob_B");
1104  proba_s->Sumw2();
1105  proba_b->Sumw2();
1106 
1107  // R(MVA) plots used for graphics representation
1108  rarity_s = new TH1D( GetTestvarName() + "_Rarity_S", GetTestvarName() + "_Rarity_S", fNbinsMVAoutput, 0.0, 1.0 );
1109  rarity_b = new TH1D( GetTestvarName() + "_Rarity_B", GetTestvarName() + "_Rarity_B", fNbinsMVAoutput, 0.0, 1.0 );
1110  mvaRes->Store(rarity_s, "Rar_S");
1111  mvaRes->Store(rarity_b, "Rar_B");
1112  rarity_s->Sumw2();
1113  rarity_b->Sumw2();
1114  }
1115 
1116  // MVA plots used for efficiency calculations (large number of bins)
1117  TH1* mva_eff_s = new TH1D( GetTestvarName() + "_S_high", GetTestvarName() + "_S_high", fNbinsH, fXmin, sxmax );
1118  TH1* mva_eff_b = new TH1D( GetTestvarName() + "_B_high", GetTestvarName() + "_B_high", fNbinsH, fXmin, sxmax );
1119  mvaRes->Store(mva_eff_s, "MVA_HIGHBIN_S");
1120  mvaRes->Store(mva_eff_b, "MVA_HIGHBIN_B");
1121  mva_eff_s->Sumw2();
1122  mva_eff_b->Sumw2();
1123 
1124  // fill the histograms
1125  ResultsClassification* mvaProb = dynamic_cast<ResultsClassification*>
1126  (Data()->GetResults( TString("prob_")+GetMethodName(), Types::kTesting, Types::kMaxAnalysisType ) );
1127 
1128  Log() << kINFO << "Loop over test events and fill histograms with classifier response..." << Endl;
1129  if (mvaProb) Log() << kINFO << "Also filling probability and rarity histograms (on request)..." << Endl;
1130  for (Long64_t ievt=0; ievt<GetNEvents(); ievt++) {
1131 
1132  const Event* ev = GetEvent(ievt);
1133  Float_t v = (*mvaRes)[ievt][0];
1134  Float_t w = ev->GetWeight();
1135 
1136  if (DataInfo().IsSignal(ev)) {
1137  mva_s ->Fill( v, w );
1138  if (mvaProb) {
1139  proba_s->Fill( (*mvaProb)[ievt][0], w );
1140  rarity_s->Fill( GetRarity( v ), w );
1141  }
1142 
1143  mva_eff_s ->Fill( v, w );
1144  }
1145  else {
1146  mva_b ->Fill( v, w );
1147  if (mvaProb) {
1148  proba_b->Fill( (*mvaProb)[ievt][0], w );
1149  rarity_b->Fill( GetRarity( v ), w );
1150  }
1151  mva_eff_b ->Fill( v, w );
1152  }
1153  }
1154 
1155  // uncomment those (and several others if you want unnormalized output
1156  gTools().NormHist( mva_s );
1157  gTools().NormHist( mva_b );
1158  gTools().NormHist( proba_s );
1159  gTools().NormHist( proba_b );
1160  gTools().NormHist( rarity_s );
1161  gTools().NormHist( rarity_b );
1162  gTools().NormHist( mva_eff_s );
1163  gTools().NormHist( mva_eff_b );
1164 
1165  // create PDFs from histograms, using default splines, and no additional smoothing
1166  if (fSplS) { delete fSplS; fSplS = 0; }
1167  if (fSplB) { delete fSplB; fSplB = 0; }
1168  fSplS = new PDF( TString(GetName()) + " PDF Sig", mva_s, PDF::kSpline2 );
1169  fSplB = new PDF( TString(GetName()) + " PDF Bkg", mva_b, PDF::kSpline2 );
1170 }
1171 
1172 ////////////////////////////////////////////////////////////////////////////////
1173 /// general method used in writing the header of the weight files where
1174 /// the used variables, variable transformation type etc. is specified
1175 
1176 void TMVA::MethodBase::WriteStateToStream( std::ostream& tf ) const
1177 {
1178  TString prefix = "";
1179  UserGroup_t * userInfo = gSystem->GetUserInfo();
1180 
1181  tf << prefix << "#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1182  tf << prefix << "Method : " << GetMethodTypeName() << "::" << GetMethodName() << std::endl;
1183  tf.setf(std::ios::left);
1184  tf << prefix << "TMVA Release : " << std::setw(10) << GetTrainingTMVAVersionString() << " ["
1185  << GetTrainingTMVAVersionCode() << "]" << std::endl;
1186  tf << prefix << "ROOT Release : " << std::setw(10) << GetTrainingROOTVersionString() << " ["
1187  << GetTrainingROOTVersionCode() << "]" << std::endl;
1188  tf << prefix << "Creator : " << userInfo->fUser << std::endl;
1189  tf << prefix << "Date : "; TDatime *d = new TDatime; tf << d->AsString() << std::endl; delete d;
1190  tf << prefix << "Host : " << gSystem->GetBuildNode() << std::endl;
1191  tf << prefix << "Dir : " << gSystem->WorkingDirectory() << std::endl;
1192  tf << prefix << "Training events: " << Data()->GetNTrainingEvents() << std::endl;
1193 
1194  TString analysisType(((const_cast<TMVA::MethodBase*>(this)->GetAnalysisType()==Types::kRegression) ? "Regression" : "Classification"));
1195 
1196  tf << prefix << "Analysis type : " << "[" << ((GetAnalysisType()==Types::kRegression) ? "Regression" : "Classification") << "]" << std::endl;
1197  tf << prefix << std::endl;
1198 
1199  delete userInfo;
1200 
1201  // First write all options
1202  tf << prefix << std::endl << prefix << "#OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1203  WriteOptionsToStream( tf, prefix );
1204  tf << prefix << std::endl;
1205 
1206  // Second write variable info
1207  tf << prefix << std::endl << prefix << "#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1208  WriteVarsToStream( tf, prefix );
1209  tf << prefix << std::endl;
1210 }
1211 
1212 ////////////////////////////////////////////////////////////////////////////////
1213 /// xml writing
1214 
1215 void TMVA::MethodBase::AddInfoItem( void* gi, const TString& name, const TString& value) const
1216 {
1217  void* it = gTools().AddChild(gi,"Info");
1218  gTools().AddAttr(it,"name", name);
1219  gTools().AddAttr(it,"value", value);
1220 }
1221 
1222 ////////////////////////////////////////////////////////////////////////////////
1223 
1225  if (analysisType == Types::kRegression) {
1226  AddRegressionOutput( type );
1227  } else if (analysisType == Types::kMulticlass) {
1228  AddMulticlassOutput( type );
1229  } else {
1230  AddClassifierOutput( type );
1231  if (HasMVAPdfs())
1232  AddClassifierOutputProb( type );
1233  }
1234 }
1235 
1236 ////////////////////////////////////////////////////////////////////////////////
1237 /// general method used in writing the header of the weight files where
1238 /// the used variables, variable transformation type etc. is specified
1239 
1240 void TMVA::MethodBase::WriteStateToXML( void* parent ) const
1241 {
1242  if (!parent) return;
1243 
1244  UserGroup_t* userInfo = gSystem->GetUserInfo();
1245 
1246  void* gi = gTools().AddChild(parent, "GeneralInfo");
1247  AddInfoItem( gi, "TMVA Release", GetTrainingTMVAVersionString() + " [" + gTools().StringFromInt(GetTrainingTMVAVersionCode()) + "]" );
1248  AddInfoItem( gi, "ROOT Release", GetTrainingROOTVersionString() + " [" + gTools().StringFromInt(GetTrainingROOTVersionCode()) + "]");
1249  AddInfoItem( gi, "Creator", userInfo->fUser);
1250  TDatime dt; AddInfoItem( gi, "Date", dt.AsString());
1251  AddInfoItem( gi, "Host", gSystem->GetBuildNode() );
1252  AddInfoItem( gi, "Dir", gSystem->WorkingDirectory());
1253  AddInfoItem( gi, "Training events", gTools().StringFromInt(Data()->GetNTrainingEvents()));
1254  AddInfoItem( gi, "TrainingTime", gTools().StringFromDouble(const_cast<TMVA::MethodBase*>(this)->GetTrainTime()));
1255 
1256  Types::EAnalysisType aType = const_cast<TMVA::MethodBase*>(this)->GetAnalysisType();
1257  TString analysisType((aType==Types::kRegression) ? "Regression" :
1258  (aType==Types::kMulticlass ? "Multiclass" : "Classification"));
1259  AddInfoItem( gi, "AnalysisType", analysisType );
1260  delete userInfo;
1261 
1262  // write options
1263  AddOptionsXMLTo( parent );
1264 
1265  // write variable info
1266  AddVarsXMLTo( parent );
1267 
1268  // write spectator info
1269  if (!fDisableWriting)
1270  AddSpectatorsXMLTo( parent );
1271 
1272  // write class info if in multiclass mode
1273  AddClassesXMLTo(parent);
1274 
1275  // write target info if in regression mode
1276  if (DoRegression()) AddTargetsXMLTo(parent);
1277 
1278  // write transformations
1279  GetTransformationHandler(false).AddXMLTo( parent );
1280 
1281  // write MVA variable distributions
1282  void* pdfs = gTools().AddChild(parent, "MVAPdfs");
1283  if (fMVAPdfS) fMVAPdfS->AddXMLTo(pdfs);
1284  if (fMVAPdfB) fMVAPdfB->AddXMLTo(pdfs);
1285 
1286  // write weights
1287  AddWeightsXMLTo( parent );
1288 }
1289 
1290 ////////////////////////////////////////////////////////////////////////////////
1291 /// write reference MVA distributions (and other information)
1292 /// to a ROOT type weight file
1293 
1295 {
1296  Bool_t addDirStatus = TH1::AddDirectoryStatus();
1297  TH1::AddDirectory( 0 ); // this avoids the binding of the hists in PDF to the current ROOT file
1298  fMVAPdfS = (TMVA::PDF*)rf.Get( "MVA_PDF_Signal" );
1299  fMVAPdfB = (TMVA::PDF*)rf.Get( "MVA_PDF_Background" );
1300 
1301  TH1::AddDirectory( addDirStatus );
1302 
1303  ReadWeightsFromStream( rf );
1304 
1305  SetTestvarName();
1306 }
1307 
1308 ////////////////////////////////////////////////////////////////////////////////
1309 /// write options and weights to file
1310 /// note that each one text file for the main configuration information
1311 /// and one ROOT file for ROOT objects are created
1312 
1314 {
1315  // ---- create the text file
1316  TString tfname( GetWeightFileName() );
1317 
1318  // writing xml file
1319  TString xmlfname( tfname ); xmlfname.ReplaceAll( ".txt", ".xml" );
1320  Log() << kINFO << "Creating weight file in xml format: "
1321  << gTools().Color("lightblue") << xmlfname << gTools().Color("reset") << Endl;
1322  void* doc = gTools().xmlengine().NewDoc();
1323  void* rootnode = gTools().AddChild(0,"MethodSetup", "", true);
1324  gTools().xmlengine().DocSetRootElement(doc,rootnode);
1325  gTools().AddAttr(rootnode,"Method", GetMethodTypeName() + "::" + GetMethodName());
1326  WriteStateToXML(rootnode);
1327  gTools().xmlengine().SaveDoc(doc,xmlfname);
1328  gTools().xmlengine().FreeDoc(doc);
1329 }
1330 
1331 ////////////////////////////////////////////////////////////////////////////////
1332 /// Function to write options and weights to file
1333 
1335 {
1336  // get the filename
1337 
1338  TString tfname(GetWeightFileName());
1339 
1340  Log() << kINFO << "Reading weight file: "
1341  << gTools().Color("lightblue") << tfname << gTools().Color("reset") << Endl;
1342 
1343  if (tfname.EndsWith(".xml") ) {
1344 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,29,0)
1345  void* doc = gTools().xmlengine().ParseFile(tfname,gTools().xmlenginebuffersize()); // the default buffer size in TXMLEngine::ParseFile is 100k. Starting with ROOT 5.29 one can set the buffer size, see: http://savannah.cern.ch/bugs/?78864. This might be necessary for large XML files
1346 #else
1347  void* doc = gTools().xmlengine().ParseFile(tfname);
1348 #endif
1349  void* rootnode = gTools().xmlengine().DocGetRootElement(doc); // node "MethodSetup"
1350  ReadStateFromXML(rootnode);
1351  gTools().xmlengine().FreeDoc(doc);
1352  }
1353  else {
1354  std::filebuf fb;
1355  fb.open(tfname.Data(),std::ios::in);
1356  if (!fb.is_open()) { // file not found --> Error
1357  Log() << kFATAL << "<ReadStateFromFile> "
1358  << "Unable to open input weight file: " << tfname << Endl;
1359  }
1360  std::istream fin(&fb);
1361  ReadStateFromStream(fin);
1362  fb.close();
1363  }
1364  if (!fTxtWeightsOnly) {
1365  // ---- read the ROOT file
1366  TString rfname( tfname ); rfname.ReplaceAll( ".txt", ".root" );
1367  Log() << kINFO << "Reading root weight file: "
1368  << gTools().Color("lightblue") << rfname << gTools().Color("reset") << Endl;
1369  TFile* rfile = TFile::Open( rfname, "READ" );
1370  ReadStateFromStream( *rfile );
1371  rfile->Close();
1372  }
1373 }
1374 ////////////////////////////////////////////////////////////////////////////////
1375 /// for reading from memory
1376 
1377 void TMVA::MethodBase::ReadStateFromXMLString( const char* xmlstr ) {
1378 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
1379  void* doc = gTools().xmlengine().ParseString(xmlstr);
1380  void* rootnode = gTools().xmlengine().DocGetRootElement(doc); // node "MethodSetup"
1381  ReadStateFromXML(rootnode);
1382  gTools().xmlengine().FreeDoc(doc);
1383 #else
1384  Log() << kFATAL << "Method MethodBase::ReadStateFromXMLString( const char* xmlstr = "
1385  << xmlstr << " ) is not available for ROOT versions prior to 5.26/00." << Endl;
1386 #endif
1387 
1388  return;
1389 }
1390 
1391 ////////////////////////////////////////////////////////////////////////////////
1392 
1393 void TMVA::MethodBase::ReadStateFromXML( void* methodNode )
1394 {
1395  TString fullMethodName;
1396  gTools().ReadAttr( methodNode, "Method", fullMethodName );
1397  fMethodName = fullMethodName(fullMethodName.Index("::")+2,fullMethodName.Length());
1398 
1399  // update logger
1400  Log().SetSource( GetName() );
1401  Log() << kINFO << "Read method \"" << GetMethodName() << "\" of type \"" << GetMethodTypeName() << "\"" << Endl;
1402 
1403  // after the method name is read, the testvar can be set
1404  SetTestvarName();
1405 
1406  TString nodeName("");
1407  void* ch = gTools().GetChild(methodNode);
1408  while (ch!=0) {
1409  nodeName = TString( gTools().GetName(ch) );
1410 
1411  if (nodeName=="GeneralInfo") {
1412  // read analysis type
1413 
1414  TString name(""),val("");
1415  void* antypeNode = gTools().GetChild(ch);
1416  while (antypeNode) {
1417  gTools().ReadAttr( antypeNode, "name", name );
1418 
1419  if (name == "TrainingTime")
1420  gTools().ReadAttr( antypeNode, "value", fTrainTime );
1421 
1422  if (name == "AnalysisType") {
1423  gTools().ReadAttr( antypeNode, "value", val );
1424  val.ToLower();
1425  if (val == "regression" ) SetAnalysisType( Types::kRegression );
1426  else if (val == "classification" ) SetAnalysisType( Types::kClassification );
1427  else if (val == "multiclass" ) SetAnalysisType( Types::kMulticlass );
1428  else Log() << kFATAL << "Analysis type " << val << " is not known." << Endl;
1429  }
1430 
1431  if (name == "TMVA Release" || name == "TMVA") {
1432  TString s;
1433  gTools().ReadAttr( antypeNode, "value", s);
1434  fTMVATrainingVersion = TString(s(s.Index("[")+1,s.Index("]")-s.Index("[")-1)).Atoi();
1435  Log() << kINFO << "MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() << Endl;
1436  }
1437 
1438  if (name == "ROOT Release" || name == "ROOT") {
1439  TString s;
1440  gTools().ReadAttr( antypeNode, "value", s);
1441  fROOTTrainingVersion = TString(s(s.Index("[")+1,s.Index("]")-s.Index("[")-1)).Atoi();
1442  Log() << kINFO << "MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() << Endl;
1443  }
1444  antypeNode = gTools().GetNextChild(antypeNode);
1445  }
1446  }
1447  else if (nodeName=="Options") {
1448  ReadOptionsFromXML(ch);
1449  ParseOptions();
1450 
1451  }
1452  else if (nodeName=="Variables") {
1453  ReadVariablesFromXML(ch);
1454  }
1455  else if (nodeName=="Spectators") {
1456  ReadSpectatorsFromXML(ch);
1457  }
1458  else if (nodeName=="Classes") {
1459  if (DataInfo().GetNClasses()==0) ReadClassesFromXML(ch);
1460  }
1461  else if (nodeName=="Targets") {
1462  if (DataInfo().GetNTargets()==0 && DoRegression()) ReadTargetsFromXML(ch);
1463  }
1464  else if (nodeName=="Transformations") {
1465  GetTransformationHandler().ReadFromXML(ch);
1466  }
1467  else if (nodeName=="MVAPdfs") {
1468  TString pdfname;
1469  if (fMVAPdfS) { delete fMVAPdfS; fMVAPdfS=0; }
1470  if (fMVAPdfB) { delete fMVAPdfB; fMVAPdfB=0; }
1471  void* pdfnode = gTools().GetChild(ch);
1472  if (pdfnode) {
1473  gTools().ReadAttr(pdfnode, "Name", pdfname);
1474  fMVAPdfS = new PDF(pdfname);
1475  fMVAPdfS->ReadXML(pdfnode);
1476  pdfnode = gTools().GetNextChild(pdfnode);
1477  gTools().ReadAttr(pdfnode, "Name", pdfname);
1478  fMVAPdfB = new PDF(pdfname);
1479  fMVAPdfB->ReadXML(pdfnode);
1480  }
1481  }
1482  else if (nodeName=="Weights") {
1483  ReadWeightsFromXML(ch);
1484  }
1485  else {
1486  Log() << kWARNING << "Unparsed XML node: '" << nodeName << "'" << Endl;
1487  }
1488  ch = gTools().GetNextChild(ch);
1489 
1490  }
1491 
1492  // update transformation handler
1493  if (GetTransformationHandler().GetCallerName() == "") GetTransformationHandler().SetCallerName( GetName() );
1494 }
1495 
1496 ////////////////////////////////////////////////////////////////////////////////
1497 /// read the header from the weight files of the different MVA methods
1498 
1499 void TMVA::MethodBase::ReadStateFromStream( std::istream& fin )
1500 {
1501  char buf[512];
1502 
1503  // when reading from stream, we assume the files are produced with TMVA<=397
1504  SetAnalysisType(Types::kClassification);
1505 
1506 
1507  // first read the method name
1508  GetLine(fin,buf);
1509  while (!TString(buf).BeginsWith("Method")) GetLine(fin,buf);
1510  TString namestr(buf);
1511 
1512  TString methodType = namestr(0,namestr.Index("::"));
1513  methodType = methodType(methodType.Last(' '),methodType.Length());
1514  methodType = methodType.Strip(TString::kLeading);
1515 
1516  TString methodName = namestr(namestr.Index("::")+2,namestr.Length());
1517  methodName = methodName.Strip(TString::kLeading);
1518  if (methodName == "") methodName = methodType;
1519  fMethodName = methodName;
1520 
1521  Log() << kINFO << "Read method \"" << GetMethodName() << "\" of type \"" << GetMethodTypeName() << "\"" << Endl;
1522 
1523  // update logger
1524  Log().SetSource( GetName() );
1525 
1526  // now the question is whether to read the variables first or the options (well, of course the order
1527  // of writing them needs to agree)
1528  //
1529  // the option "Decorrelation" is needed to decide if the variables we
1530  // read are decorrelated or not
1531  //
1532  // the variables are needed by some methods (TMLP) to build the NN
1533  // which is done in ProcessOptions so for the time being we first Read and Parse the options then
1534  // we read the variables, and then we process the options
1535 
1536  // now read all options
1537  GetLine(fin,buf);
1538  while (!TString(buf).BeginsWith("#OPT")) GetLine(fin,buf);
1539  ReadOptionsFromStream(fin);
1540  ParseOptions();
1541 
1542  // Now read variable info
1543  fin.getline(buf,512);
1544  while (!TString(buf).BeginsWith("#VAR")) fin.getline(buf,512);
1545  ReadVarsFromStream(fin);
1546 
1547  // now we process the options (of the derived class)
1548  ProcessOptions();
1549 
1550  if (IsNormalised()) {
1552  GetTransformationHandler().AddTransformation( new VariableNormalizeTransform(DataInfo()), -1 );
1553  norm->BuildTransformationFromVarInfo( DataInfo().GetVariableInfos() );
1554  }
1555  VariableTransformBase *varTrafo(0), *varTrafo2(0);
1556  if ( fVarTransformString == "None") {
1557  if (fUseDecorr)
1558  varTrafo = GetTransformationHandler().AddTransformation( new VariableDecorrTransform(DataInfo()), -1 );
1559  } else if ( fVarTransformString == "Decorrelate" ) {
1560  varTrafo = GetTransformationHandler().AddTransformation( new VariableDecorrTransform(DataInfo()), -1 );
1561  } else if ( fVarTransformString == "PCA" ) {
1562  varTrafo = GetTransformationHandler().AddTransformation( new VariablePCATransform(DataInfo()), -1 );
1563  } else if ( fVarTransformString == "Uniform" ) {
1564  varTrafo = GetTransformationHandler().AddTransformation( new VariableGaussTransform(DataInfo(),"Uniform"), -1 );
1565  } else if ( fVarTransformString == "Gauss" ) {
1566  varTrafo = GetTransformationHandler().AddTransformation( new VariableGaussTransform(DataInfo()), -1 );
1567  } else if ( fVarTransformString == "GaussDecorr" ) {
1568  varTrafo = GetTransformationHandler().AddTransformation( new VariableGaussTransform(DataInfo()), -1 );
1569  varTrafo2 = GetTransformationHandler().AddTransformation( new VariableDecorrTransform(DataInfo()), -1 );
1570  } else {
1571  Log() << kFATAL << "<ProcessOptions> Variable transform '"
1572  << fVarTransformString << "' unknown." << Endl;
1573  }
1574  // Now read decorrelation matrix if available
1575  if (GetTransformationHandler().GetTransformationList().GetSize() > 0) {
1576  fin.getline(buf,512);
1577  while (!TString(buf).BeginsWith("#MAT")) fin.getline(buf,512);
1578  if (varTrafo) {
1579  TString trafo(fVariableTransformTypeString); trafo.ToLower();
1580  varTrafo->ReadTransformationFromStream(fin, trafo );
1581  }
1582  if (varTrafo2) {
1583  TString trafo(fVariableTransformTypeString); trafo.ToLower();
1584  varTrafo2->ReadTransformationFromStream(fin, trafo );
1585  }
1586  }
1587 
1588 
1589  if (HasMVAPdfs()) {
1590  // Now read the MVA PDFs
1591  fin.getline(buf,512);
1592  while (!TString(buf).BeginsWith("#MVAPDFS")) fin.getline(buf,512);
1593  if (fMVAPdfS != 0) { delete fMVAPdfS; fMVAPdfS = 0; }
1594  if (fMVAPdfB != 0) { delete fMVAPdfB; fMVAPdfB = 0; }
1595  fMVAPdfS = new PDF(TString(GetName()) + " MVA PDF Sig");
1596  fMVAPdfB = new PDF(TString(GetName()) + " MVA PDF Bkg");
1597  fMVAPdfS->SetReadingVersion( GetTrainingTMVAVersionCode() );
1598  fMVAPdfB->SetReadingVersion( GetTrainingTMVAVersionCode() );
1599 
1600  fin >> *fMVAPdfS;
1601  fin >> *fMVAPdfB;
1602  }
1603 
1604  // Now read weights
1605  fin.getline(buf,512);
1606  while (!TString(buf).BeginsWith("#WGT")) fin.getline(buf,512);
1607  fin.getline(buf,512);
1608  ReadWeightsFromStream( fin );;
1609 
1610  // update transformation handler
1611  if (GetTransformationHandler().GetCallerName() == "") GetTransformationHandler().SetCallerName( GetName() );
1612 
1613 }
1614 
1615 ////////////////////////////////////////////////////////////////////////////////
1616 /// write the list of variables (name, min, max) for a given data
1617 /// transformation method to the stream
1618 
1619 void TMVA::MethodBase::WriteVarsToStream( std::ostream& o, const TString& prefix ) const
1620 {
1621  o << prefix << "NVar " << DataInfo().GetNVariables() << std::endl;
1622  std::vector<VariableInfo>::const_iterator varIt = DataInfo().GetVariableInfos().begin();
1623  for (; varIt!=DataInfo().GetVariableInfos().end(); varIt++) { o << prefix; varIt->WriteToStream(o); }
1624  o << prefix << "NSpec " << DataInfo().GetNSpectators() << std::endl;
1625  varIt = DataInfo().GetSpectatorInfos().begin();
1626  for (; varIt!=DataInfo().GetSpectatorInfos().end(); varIt++) { o << prefix; varIt->WriteToStream(o); }
1627 }
1628 
1629 ////////////////////////////////////////////////////////////////////////////////
1630 /// Read the variables (name, min, max) for a given data
1631 /// transformation method from the stream. In the stream we only
1632 /// expect the limits which will be set
1633 
1634 void TMVA::MethodBase::ReadVarsFromStream( std::istream& istr )
1635 {
1636  TString dummy;
1637  UInt_t readNVar;
1638  istr >> dummy >> readNVar;
1639 
1640  if (readNVar!=DataInfo().GetNVariables()) {
1641  Log() << kFATAL << "You declared "<< DataInfo().GetNVariables() << " variables in the Reader"
1642  << " while there are " << readNVar << " variables declared in the file"
1643  << Endl;
1644  }
1645 
1646  // we want to make sure all variables are read in the order they are defined
1647  VariableInfo varInfo;
1648  std::vector<VariableInfo>::iterator varIt = DataInfo().GetVariableInfos().begin();
1649  int varIdx = 0;
1650  for (; varIt!=DataInfo().GetVariableInfos().end(); varIt++, varIdx++) {
1651  varInfo.ReadFromStream(istr);
1652  if (varIt->GetExpression() == varInfo.GetExpression()) {
1653  varInfo.SetExternalLink((*varIt).GetExternalLink());
1654  (*varIt) = varInfo;
1655  }
1656  else {
1657  Log() << kINFO << "ERROR in <ReadVarsFromStream>" << Endl;
1658  Log() << kINFO << "The definition (or the order) of the variables found in the input file is" << Endl;
1659  Log() << kINFO << "is not the same as the one declared in the Reader (which is necessary for" << Endl;
1660  Log() << kINFO << "the correct working of the method):" << Endl;
1661  Log() << kINFO << " var #" << varIdx <<" declared in Reader: " << varIt->GetExpression() << Endl;
1662  Log() << kINFO << " var #" << varIdx <<" declared in file : " << varInfo.GetExpression() << Endl;
1663  Log() << kFATAL << "The expression declared to the Reader needs to be checked (name or order are wrong)" << Endl;
1664  }
1665  }
1666 }
1667 
1668 ////////////////////////////////////////////////////////////////////////////////
1669 /// write variable info to XML
1670 
1671 void TMVA::MethodBase::AddVarsXMLTo( void* parent ) const
1672 {
1673  void* vars = gTools().AddChild(parent, "Variables");
1674  gTools().AddAttr( vars, "NVar", gTools().StringFromInt(DataInfo().GetNVariables()) );
1675 
1676  for (UInt_t idx=0; idx<DataInfo().GetVariableInfos().size(); idx++) {
1677  VariableInfo& vi = DataInfo().GetVariableInfos()[idx];
1678  void* var = gTools().AddChild( vars, "Variable" );
1679  gTools().AddAttr( var, "VarIndex", idx );
1680  vi.AddToXML( var );
1681  }
1682 }
1683 
1684 ////////////////////////////////////////////////////////////////////////////////
1685 /// write spectator info to XML
1686 
1687 void TMVA::MethodBase::AddSpectatorsXMLTo( void* parent ) const
1688 {
1689  void* specs = gTools().AddChild(parent, "Spectators");
1690 
1691  UInt_t writeIdx=0;
1692  for (UInt_t idx=0; idx<DataInfo().GetSpectatorInfos().size(); idx++) {
1693 
1694  VariableInfo& vi = DataInfo().GetSpectatorInfos()[idx];
1695 
1696  // we do not want to write spectators that are category-cuts,
1697  // except if the method is the category method and the spectators belong to it
1698  if (vi.GetVarType()=='C') continue;
1699 
1700  void* spec = gTools().AddChild( specs, "Spectator" );
1701  gTools().AddAttr( spec, "SpecIndex", writeIdx++ );
1702  vi.AddToXML( spec );
1703  }
1704  gTools().AddAttr( specs, "NSpec", gTools().StringFromInt(writeIdx) );
1705 }
1706 
1707 ////////////////////////////////////////////////////////////////////////////////
1708 /// write class info to XML
1709 
1710 void TMVA::MethodBase::AddClassesXMLTo( void* parent ) const
1711 {
1712  UInt_t nClasses=DataInfo().GetNClasses();
1713 
1714  void* classes = gTools().AddChild(parent, "Classes");
1715  gTools().AddAttr( classes, "NClass", nClasses );
1716 
1717  for (UInt_t iCls=0; iCls<nClasses; ++iCls) {
1718  ClassInfo *classInfo=DataInfo().GetClassInfo (iCls);
1719  TString className =classInfo->GetName();
1720  UInt_t classNumber=classInfo->GetNumber();
1721 
1722  void* classNode=gTools().AddChild(classes, "Class");
1723  gTools().AddAttr( classNode, "Name", className );
1724  gTools().AddAttr( classNode, "Index", classNumber );
1725  }
1726 }
1727 ////////////////////////////////////////////////////////////////////////////////
1728 /// write target info to XML
1729 
1730 void TMVA::MethodBase::AddTargetsXMLTo( void* parent ) const
1731 {
1732  void* targets = gTools().AddChild(parent, "Targets");
1733  gTools().AddAttr( targets, "NTrgt", gTools().StringFromInt(DataInfo().GetNTargets()) );
1734 
1735  for (UInt_t idx=0; idx<DataInfo().GetTargetInfos().size(); idx++) {
1736  VariableInfo& vi = DataInfo().GetTargetInfos()[idx];
1737  void* tar = gTools().AddChild( targets, "Target" );
1738  gTools().AddAttr( tar, "TargetIndex", idx );
1739  vi.AddToXML( tar );
1740  }
1741 }
1742 
1743 ////////////////////////////////////////////////////////////////////////////////
1744 /// read variable info from XML
1745 
1747 {
1748  UInt_t readNVar;
1749  gTools().ReadAttr( varnode, "NVar", readNVar);
1750 
1751  if (readNVar!=DataInfo().GetNVariables()) {
1752  Log() << kFATAL << "You declared "<< DataInfo().GetNVariables() << " variables in the Reader"
1753  << " while there are " << readNVar << " variables declared in the file"
1754  << Endl;
1755  }
1756 
1757  // we want to make sure all variables are read in the order they are defined
1758  VariableInfo readVarInfo, existingVarInfo;
1759  int varIdx = 0;
1760  void* ch = gTools().GetChild(varnode);
1761  while (ch) {
1762  gTools().ReadAttr( ch, "VarIndex", varIdx);
1763  existingVarInfo = DataInfo().GetVariableInfos()[varIdx];
1764  readVarInfo.ReadFromXML(ch);
1765 
1766  if (existingVarInfo.GetExpression() == readVarInfo.GetExpression()) {
1767  readVarInfo.SetExternalLink(existingVarInfo.GetExternalLink());
1768  existingVarInfo = readVarInfo;
1769  }
1770  else {
1771  Log() << kINFO << "ERROR in <ReadVariablesFromXML>" << Endl;
1772  Log() << kINFO << "The definition (or the order) of the variables found in the input file is" << Endl;
1773  Log() << kINFO << "not the same as the one declared in the Reader (which is necessary for the" << Endl;
1774  Log() << kINFO << "correct working of the method):" << Endl;
1775  Log() << kINFO << " var #" << varIdx <<" declared in Reader: " << existingVarInfo.GetExpression() << Endl;
1776  Log() << kINFO << " var #" << varIdx <<" declared in file : " << readVarInfo.GetExpression() << Endl;
1777  Log() << kFATAL << "The expression declared to the Reader needs to be checked (name or order are wrong)" << Endl;
1778  }
1779  ch = gTools().GetNextChild(ch);
1780  }
1781 }
1782 
1783 ////////////////////////////////////////////////////////////////////////////////
1784 /// read spectator info from XML
1785 
1787 {
1788  UInt_t readNSpec;
1789  gTools().ReadAttr( specnode, "NSpec", readNSpec);
1790 
1791  if (readNSpec!=DataInfo().GetNSpectators(kFALSE)) {
1792  Log() << kFATAL << "You declared "<< DataInfo().GetNSpectators(kFALSE) << " spectators in the Reader"
1793  << " while there are " << readNSpec << " spectators declared in the file"
1794  << Endl;
1795  }
1796 
1797  // we want to make sure all variables are read in the order they are defined
1798  VariableInfo readSpecInfo, existingSpecInfo;
1799  int specIdx = 0;
1800  void* ch = gTools().GetChild(specnode);
1801  while (ch) {
1802  gTools().ReadAttr( ch, "SpecIndex", specIdx);
1803  existingSpecInfo = DataInfo().GetSpectatorInfos()[specIdx];
1804  readSpecInfo.ReadFromXML(ch);
1805 
1806  if (existingSpecInfo.GetExpression() == readSpecInfo.GetExpression()) {
1807  readSpecInfo.SetExternalLink(existingSpecInfo.GetExternalLink());
1808  existingSpecInfo = readSpecInfo;
1809  }
1810  else {
1811  Log() << kINFO << "ERROR in <ReadSpectatorsFromXML>" << Endl;
1812  Log() << kINFO << "The definition (or the order) of the spectators found in the input file is" << Endl;
1813  Log() << kINFO << "not the same as the one declared in the Reader (which is necessary for the" << Endl;
1814  Log() << kINFO << "correct working of the method):" << Endl;
1815  Log() << kINFO << " spec #" << specIdx <<" declared in Reader: " << existingSpecInfo.GetExpression() << Endl;
1816  Log() << kINFO << " spec #" << specIdx <<" declared in file : " << readSpecInfo.GetExpression() << Endl;
1817  Log() << kFATAL << "The expression declared to the Reader needs to be checked (name or order are wrong)" << Endl;
1818  }
1819  ch = gTools().GetNextChild(ch);
1820  }
1821 }
1822 
1823 ////////////////////////////////////////////////////////////////////////////////
1824 /// read number of classes from XML
1825 
1827 {
1828  UInt_t readNCls;
1829  // coverity[tainted_data_argument]
1830  gTools().ReadAttr( clsnode, "NClass", readNCls);
1831 
1832  TString className="";
1833  UInt_t classIndex=0;
1834  void* ch = gTools().GetChild(clsnode);
1835  if (!ch) {
1836  for (UInt_t icls = 0; icls<readNCls;++icls) {
1837  TString classname = Form("class%i",icls);
1838  DataInfo().AddClass(classname);
1839 
1840  }
1841  }
1842  else{
1843  while (ch) {
1844  gTools().ReadAttr( ch, "Index", classIndex);
1845  gTools().ReadAttr( ch, "Name", className );
1846  DataInfo().AddClass(className);
1847 
1848  ch = gTools().GetNextChild(ch);
1849  }
1850  }
1851 
1852  // retrieve signal and background class index
1853  if (DataInfo().GetClassInfo("Signal") != 0) {
1854  fSignalClass = DataInfo().GetClassInfo("Signal")->GetNumber();
1855  }
1856  else
1857  fSignalClass=0;
1858  if (DataInfo().GetClassInfo("Background") != 0) {
1859  fBackgroundClass = DataInfo().GetClassInfo("Background")->GetNumber();
1860  }
1861  else
1862  fBackgroundClass=1;
1863 }
1864 
1865 ////////////////////////////////////////////////////////////////////////////////
1866 /// read target info from XML
1867 
1869 {
1870  UInt_t readNTar;
1871  gTools().ReadAttr( tarnode, "NTrgt", readNTar);
1872 
1873  int tarIdx = 0;
1874  TString expression;
1875  void* ch = gTools().GetChild(tarnode);
1876  while (ch) {
1877  gTools().ReadAttr( ch, "TargetIndex", tarIdx);
1878  gTools().ReadAttr( ch, "Expression", expression);
1879  DataInfo().AddTarget(expression,"","",0,0);
1880 
1881  ch = gTools().GetNextChild(ch);
1882  }
1883 }
1884 
1885 ////////////////////////////////////////////////////////////////////////////////
1886 /// returns the ROOT directory where info/histograms etc of the
1887 /// corresponding MVA method instance are stored
1888 
1890 {
1891  if (fBaseDir != 0) return fBaseDir;
1892  Log()<<kDEBUG<<" Base Directory for " << GetMethodTypeName() << " not set yet --> check if already there.." <<Endl;
1893 
1894  TDirectory* methodDir = MethodBaseDir();
1895  if (methodDir==0)
1896  Log() << kFATAL << "MethodBase::BaseDir() - MethodBaseDir() return a NULL pointer!" << Endl;
1897 
1898  TDirectory* dir = 0;
1899 
1900  TString defaultDir = GetMethodName();
1901 
1902  TObject* o = methodDir->FindObject(defaultDir);
1903  if (o!=0 && o->InheritsFrom(TDirectory::Class())) dir = (TDirectory*)o;
1904 
1905  if (dir != 0) {
1906  Log()<<kDEBUG<<" Base Directory for " << GetMethodName() << " existed, return it.." <<Endl;
1907  return dir;
1908  }
1909 
1910  Log()<<kDEBUG<<" Base Directory for " << GetMethodName() << " does not exist yet--> created it" <<Endl;
1911  TDirectory *sdir = methodDir->mkdir(defaultDir);
1912 
1913  // write weight file name into target file
1914  sdir->cd();
1915  TObjString wfilePath( gSystem->WorkingDirectory() );
1916  TObjString wfileName( GetWeightFileName() );
1917  wfilePath.Write( "TrainingPath" );
1918  wfileName.Write( "WeightFileName" );
1919 
1920  return sdir;
1921 }
1922 
1923 ////////////////////////////////////////////////////////////////////////////////
1924 /// returns the ROOT directory where all instances of the
1925 /// corresponding MVA method are stored
1926 
1928 {
1929  if (fMethodBaseDir != 0) return fMethodBaseDir;
1930 
1931  Log()<<kDEBUG<<" Base Directory for " << GetMethodTypeName() << " not set yet --> check if already there.." <<Endl;
1932 
1933  const TString dirName(Form("Method_%s",GetMethodTypeName().Data()));
1934 
1936  if (dir != 0) {
1937  Log()<<kDEBUG<<" Base Directory for " << GetMethodTypeName() << " existed, return it.." <<Endl;
1938  return dir;
1939  }
1940 
1941  Log()<<kDEBUG<<" Base Directory for " << GetMethodTypeName() << " does not exist yet--> created it" <<Endl;
1942  fMethodBaseDir = Factory::RootBaseDir()->mkdir(dirName,Form("Directory for all %s methods", GetMethodTypeName().Data()));
1943 
1944  Log()<<kDEBUG<<"Return from MethodBaseDir() after creating base directory "<<Endl;
1945  return fMethodBaseDir;
1946 }
1947 
1948 ////////////////////////////////////////////////////////////////////////////////
1949 /// set directory of weight file
1950 
1952 {
1953  fFileDir = fileDir;
1954  gSystem->MakeDirectory( fFileDir );
1955 }
1956 
1957 ////////////////////////////////////////////////////////////////////////////////
1958 /// set the weight file name (depreciated)
1959 
1961 {
1962  fWeightFile = theWeightFile;
1963 }
1964 
1965 ////////////////////////////////////////////////////////////////////////////////
1966 /// retrieve weight file name
1967 
1969 {
1970  if (fWeightFile!="") return fWeightFile;
1971 
1972  // the default consists of
1973  // directory/jobname_methodname_suffix.extension.{root/txt}
1974  TString suffix = "";
1975  TString wFileDir(GetWeightFileDir());
1976  return ( wFileDir + (wFileDir[wFileDir.Length()-1]=='/' ? "" : "/")
1977  + GetJobName() + "_" + GetMethodName() +
1978  suffix + "." + gConfig().GetIONames().fWeightFileExtension + ".xml" );
1979 }
1980 
1981 ////////////////////////////////////////////////////////////////////////////////
1982 /// writes all MVA evaluation histograms to file
1983 
1985 {
1986  BaseDir()->cd();
1987 
1988  // write MVA PDFs to file - if exist
1989  if (0 != fMVAPdfS) {
1990  fMVAPdfS->GetOriginalHist()->Write();
1991  fMVAPdfS->GetSmoothedHist()->Write();
1992  fMVAPdfS->GetPDFHist()->Write();
1993  }
1994  if (0 != fMVAPdfB) {
1995  fMVAPdfB->GetOriginalHist()->Write();
1996  fMVAPdfB->GetSmoothedHist()->Write();
1997  fMVAPdfB->GetPDFHist()->Write();
1998  }
1999 
2000  // write result-histograms
2001  Results* results = Data()->GetResults( GetMethodName(), treetype, Types::kMaxAnalysisType );
2002  if (!results)
2003  Log() << kFATAL << "<WriteEvaluationHistosToFile> Unknown result: "
2004  << GetMethodName() << (treetype==Types::kTraining?"/kTraining":"/kTesting")
2005  << "/kMaxAnalysisType" << Endl;
2006  results->GetStorage()->Write();
2007  if (treetype==Types::kTesting) {
2008  GetTransformationHandler().PlotVariables (GetEventCollection( Types::kTesting ), BaseDir() );
2009  }
2010 }
2011 
2012 ////////////////////////////////////////////////////////////////////////////////
2013 /// write special monitoring histograms to file
2014 /// dummy implementation here -----------------
2015 
2017 {
2018 }
2019 
2020 ////////////////////////////////////////////////////////////////////////////////
2021 /// reads one line from the input stream
2022 /// checks for certain keywords and interprets
2023 /// the line if keywords are found
2024 
2025 Bool_t TMVA::MethodBase::GetLine(std::istream& fin, char* buf )
2026 {
2027  fin.getline(buf,512);
2028  TString line(buf);
2029  if (line.BeginsWith("TMVA Release")) {
2030  Ssiz_t start = line.First('[')+1;
2031  Ssiz_t length = line.Index("]",start)-start;
2032  TString code = line(start,length);
2033  std::stringstream s(code.Data());
2034  s >> fTMVATrainingVersion;
2035  Log() << kINFO << "MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() << Endl;
2036  }
2037  if (line.BeginsWith("ROOT Release")) {
2038  Ssiz_t start = line.First('[')+1;
2039  Ssiz_t length = line.Index("]",start)-start;
2040  TString code = line(start,length);
2041  std::stringstream s(code.Data());
2042  s >> fROOTTrainingVersion;
2043  Log() << kINFO << "MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() << Endl;
2044  }
2045  if (line.BeginsWith("Analysis type")) {
2046  Ssiz_t start = line.First('[')+1;
2047  Ssiz_t length = line.Index("]",start)-start;
2048  TString code = line(start,length);
2049  std::stringstream s(code.Data());
2050  std::string analysisType;
2051  s >> analysisType;
2052  if (analysisType == "regression" || analysisType == "Regression") SetAnalysisType( Types::kRegression );
2053  else if (analysisType == "classification" || analysisType == "Classification") SetAnalysisType( Types::kClassification );
2054  else if (analysisType == "multiclass" || analysisType == "Multiclass") SetAnalysisType( Types::kMulticlass );
2055  else Log() << kFATAL << "Analysis type " << analysisType << " from weight-file not known!" << std::endl;
2056 
2057  Log() << kINFO << "Method was trained for "
2058  << (GetAnalysisType() == Types::kRegression ? "Regression" :
2059  (GetAnalysisType() == Types::kMulticlass ? "Multiclass" : "Classification")) << Endl;
2060  }
2061 
2062  return true;
2063 }
2064 
2065 ////////////////////////////////////////////////////////////////////////////////
2066 /// Create PDFs of the MVA output variables
2067 
2069 {
2070  Data()->SetCurrentType(Types::kTraining);
2071 
2072  // the PDF's are stored as results ONLY if the corresponding "results" are booked,
2073  // otherwise they will be only used 'online'
2074  ResultsClassification * mvaRes = dynamic_cast<ResultsClassification*>
2076 
2077  if (mvaRes==0 || mvaRes->GetSize()==0) {
2078  Log() << kERROR<< "<CreateMVAPdfs> No result of classifier testing available" << Endl;
2079  }
2080 
2081  Double_t minVal = *std::min_element(mvaRes->GetValueVector()->begin(),mvaRes->GetValueVector()->end());
2082  Double_t maxVal = *std::max_element(mvaRes->GetValueVector()->begin(),mvaRes->GetValueVector()->end());
2083 
2084  // create histograms that serve as basis to create the MVA Pdfs
2085  TH1* histMVAPdfS = new TH1D( GetMethodTypeName() + "_tr_S", GetMethodTypeName() + "_tr_S",
2086  fMVAPdfS->GetHistNBins( mvaRes->GetSize() ), minVal, maxVal );
2087  TH1* histMVAPdfB = new TH1D( GetMethodTypeName() + "_tr_B", GetMethodTypeName() + "_tr_B",
2088  fMVAPdfB->GetHistNBins( mvaRes->GetSize() ), minVal, maxVal );
2089 
2090 
2091  // compute sum of weights properly
2092  histMVAPdfS->Sumw2();
2093  histMVAPdfB->Sumw2();
2094 
2095  // fill histograms
2096  for (UInt_t ievt=0; ievt<mvaRes->GetSize(); ievt++) {
2097  Double_t theVal = mvaRes->GetValueVector()->at(ievt);
2098  Double_t theWeight = Data()->GetEvent(ievt)->GetWeight();
2099 
2100  if (DataInfo().IsSignal(Data()->GetEvent(ievt))) histMVAPdfS->Fill( theVal, theWeight );
2101  else histMVAPdfB->Fill( theVal, theWeight );
2102  }
2103 
2104  gTools().NormHist( histMVAPdfS );
2105  gTools().NormHist( histMVAPdfB );
2106 
2107  // momentary hack for ROOT problem
2108  histMVAPdfS->Write();
2109  histMVAPdfB->Write();
2110 
2111  // create PDFs
2112  fMVAPdfS->BuildPDF ( histMVAPdfS );
2113  fMVAPdfB->BuildPDF ( histMVAPdfB );
2114  fMVAPdfS->ValidatePDF( histMVAPdfS );
2115  fMVAPdfB->ValidatePDF( histMVAPdfB );
2116 
2117  if (DataInfo().GetNClasses() == 2) { // TODO: this is an ugly hack.. adapt this to new framework
2118  Log() << kINFO
2119  << Form( "<CreateMVAPdfs> Separation from histogram (PDF): %1.3f (%1.3f)",
2120  GetSeparation( histMVAPdfS, histMVAPdfB ), GetSeparation( fMVAPdfS, fMVAPdfB ) )
2121  << Endl;
2122  }
2123 
2124  delete histMVAPdfS;
2125  delete histMVAPdfB;
2126 }
2127 
2129  // the simple one, automatically calcualtes the mvaVal and uses the
2130  // SAME sig/bkg ratio as given in the training sample (typically 50/50
2131  // .. (NormMode=EqualNumEvents) but can be different)
2132  if (!fMVAPdfS || !fMVAPdfB) {
2133  Log() << kINFO << "<GetProba> MVA PDFs for Signal and Background don't exist yet, we'll create them on demand" << Endl;
2134  CreateMVAPdfs();
2135  }
2136  Double_t sigFraction = DataInfo().GetTrainingSumSignalWeights() / (DataInfo().GetTrainingSumSignalWeights() + DataInfo().GetTrainingSumBackgrWeights() );
2137  Double_t mvaVal = GetMvaValue(ev);
2138 
2139  return GetProba(mvaVal,sigFraction);
2140 
2141 }
2142 ////////////////////////////////////////////////////////////////////////////////
2143 /// compute likelihood ratio
2144 
2146 {
2147  if (!fMVAPdfS || !fMVAPdfB) {
2148  Log() << kWARNING << "<GetProba> MVA PDFs for Signal and Background don't exist" << Endl;
2149  return -1.0;
2150  }
2151  Double_t p_s = fMVAPdfS->GetVal( mvaVal );
2152  Double_t p_b = fMVAPdfB->GetVal( mvaVal );
2153 
2154  Double_t denom = p_s*ap_sig + p_b*(1 - ap_sig);
2155 
2156  return (denom > 0) ? (p_s*ap_sig) / denom : -1;
2157 }
2158 
2159 ////////////////////////////////////////////////////////////////////////////////
2160 /// compute rarity:
2161 /// R(x) = Integrate_[-oo..x] { PDF(x') dx' }
2162 /// where PDF(x) is the PDF of the classifier's signal or background distribution
2163 
2165 {
2166  if ((reftype == Types::kSignal && !fMVAPdfS) || (reftype == Types::kBackground && !fMVAPdfB)) {
2167  Log() << kWARNING << "<GetRarity> Required MVA PDF for Signal or Backgroud does not exist: "
2168  << "select option \"CreateMVAPdfs\"" << Endl;
2169  return 0.0;
2170  }
2171 
2172  PDF* thePdf = ((reftype == Types::kSignal) ? fMVAPdfS : fMVAPdfB);
2173 
2174  return thePdf->GetIntegral( thePdf->GetXmin(), mvaVal );
2175 }
2176 
2177 ////////////////////////////////////////////////////////////////////////////////
2178 /// fill background efficiency (resp. rejection) versus signal efficiency plots
2179 /// returns signal efficiency at background efficiency indicated in theString
2180 
2182 {
2183  Data()->SetCurrentType(type);
2184  Results* results = Data()->GetResults( GetMethodName(), type, Types::kClassification );
2185  std::vector<Float_t>* mvaRes = dynamic_cast<ResultsClassification*>(results)->GetValueVector();
2186 
2187  // parse input string for required background efficiency
2188  TList* list = gTools().ParseFormatLine( theString );
2189 
2190  // sanity check
2191  Bool_t computeArea = kFALSE;
2192  if (!list || list->GetSize() < 2) computeArea = kTRUE; // the area is computed
2193  else if (list->GetSize() > 2) {
2194  Log() << kFATAL << "<GetEfficiency> Wrong number of arguments"
2195  << " in string: " << theString
2196  << " | required format, e.g., Efficiency:0.05, or empty string" << Endl;
2197  delete list;
2198  return -1;
2199  }
2200 
2201  // sanity check
2202  if ( results->GetHist("MVA_S")->GetNbinsX() != results->GetHist("MVA_B")->GetNbinsX() ||
2203  results->GetHist("MVA_HIGHBIN_S")->GetNbinsX() != results->GetHist("MVA_HIGHBIN_B")->GetNbinsX() ) {
2204  Log() << kFATAL << "<GetEfficiency> Binning mismatch between signal and background histos" << Endl;
2205  delete list;
2206  return -1.0;
2207  }
2208 
2209  // create histograms
2210 
2211  // first, get efficiency histograms for signal and background
2212  TH1 * effhist = results->GetHist("MVA_HIGHBIN_S");
2213  Double_t xmin = effhist->GetXaxis()->GetXmin();
2214  Double_t xmax = effhist->GetXaxis()->GetXmax();
2215 
2216  TTHREAD_TLS(Double_t) nevtS;
2217 
2218  // first round ? --> create histograms
2219  if (results->DoesExist("MVA_EFF_S")==0) {
2220 
2221  // for efficiency plot
2222  TH1* eff_s = new TH1D( GetTestvarName() + "_effS", GetTestvarName() + " (signal)", fNbinsH, xmin, xmax );
2223  TH1* eff_b = new TH1D( GetTestvarName() + "_effB", GetTestvarName() + " (background)", fNbinsH, xmin, xmax );
2224  results->Store(eff_s, "MVA_EFF_S");
2225  results->Store(eff_b, "MVA_EFF_B");
2226 
2227  // sign if cut
2228  Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2229 
2230  // this method is unbinned
2231  nevtS = 0;
2232  for (UInt_t ievt=0; ievt<Data()->GetNEvents(); ievt++) {
2233 
2234  // read the tree
2235  Bool_t isSignal = DataInfo().IsSignal(GetEvent(ievt));
2236  Float_t theWeight = GetEvent(ievt)->GetWeight();
2237  Float_t theVal = (*mvaRes)[ievt];
2238 
2239  // select histogram depending on if sig or bgd
2240  TH1* theHist = isSignal ? eff_s : eff_b;
2241 
2242  // count signal and background events in tree
2243  if (isSignal) nevtS+=theWeight;
2244 
2245  TAxis* axis = theHist->GetXaxis();
2246  Int_t maxbin = Int_t((theVal - axis->GetXmin())/(axis->GetXmax() - axis->GetXmin())*fNbinsH) + 1;
2247  if (sign > 0 && maxbin > fNbinsH) continue; // can happen... event doesn't count
2248  if (sign < 0 && maxbin < 1 ) continue; // can happen... event doesn't count
2249  if (sign > 0 && maxbin < 1 ) maxbin = 1;
2250  if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2251 
2252  if (sign > 0)
2253  for (Int_t ibin=1; ibin<=maxbin; ibin++) theHist->AddBinContent( ibin , theWeight);
2254  else if (sign < 0)
2255  for (Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theHist->AddBinContent( ibin , theWeight );
2256  else
2257  Log() << kFATAL << "<GetEfficiency> Mismatch in sign" << Endl;
2258  }
2259 
2260  // renormalise maximum to <=1
2261  // eff_s->Scale( 1.0/TMath::Max(1.,eff_s->GetMaximum()) );
2262  // eff_b->Scale( 1.0/TMath::Max(1.,eff_b->GetMaximum()) );
2263 
2266 
2267  // background efficiency versus signal efficiency
2268  TH1* eff_BvsS = new TH1D( GetTestvarName() + "_effBvsS", GetTestvarName() + "", fNbins, 0, 1 );
2269  results->Store(eff_BvsS, "MVA_EFF_BvsS");
2270  eff_BvsS->SetXTitle( "Signal eff" );
2271  eff_BvsS->SetYTitle( "Backgr eff" );
2272 
2273  // background rejection (=1-eff.) versus signal efficiency
2274  TH1* rej_BvsS = new TH1D( GetTestvarName() + "_rejBvsS", GetTestvarName() + "", fNbins, 0, 1 );
2275  results->Store(rej_BvsS);
2276  rej_BvsS->SetXTitle( "Signal eff" );
2277  rej_BvsS->SetYTitle( "Backgr rejection (1-eff)" );
2278 
2279  // inverse background eff (1/eff.) versus signal efficiency
2280  TH1* inveff_BvsS = new TH1D( GetTestvarName() + "_invBeffvsSeff",
2281  GetTestvarName(), fNbins, 0, 1 );
2282  results->Store(inveff_BvsS);
2283  inveff_BvsS->SetXTitle( "Signal eff" );
2284  inveff_BvsS->SetYTitle( "Inverse backgr. eff (1/eff)" );
2285 
2286  // use root finder
2287  // spline background efficiency plot
2288  // note that there is a bin shift when going from a TH1D object to a TGraph :-(
2289  if (Use_Splines_for_Eff_) {
2290  fSplRefS = new TSpline1( "spline2_signal", new TGraph( eff_s ) );
2291  fSplRefB = new TSpline1( "spline2_background", new TGraph( eff_b ) );
2292 
2293  // verify spline sanity
2294  gTools().CheckSplines( eff_s, fSplRefS );
2295  gTools().CheckSplines( eff_b, fSplRefB );
2296  }
2297 
2298  // make the background-vs-signal efficiency plot
2299 
2300  // create root finder
2301  // reset static "this" pointer before calling external function
2302  ResetThisBase();
2303  RootFinder rootFinder( &IGetEffForRoot, fXmin, fXmax );
2304 
2305  Double_t effB = 0;
2306  fEffS = eff_s; // to be set for the root finder
2307  for (Int_t bini=1; bini<=fNbins; bini++) {
2308 
2309  // find cut value corresponding to a given signal efficiency
2310  Double_t effS = eff_BvsS->GetBinCenter( bini );
2311  Double_t cut = rootFinder.Root( effS );
2312 
2313  // retrieve background efficiency for given cut
2314  if (Use_Splines_for_Eff_) effB = fSplRefB->Eval( cut );
2315  else effB = eff_b->GetBinContent( eff_b->FindBin( cut ) );
2316 
2317  // and fill histograms
2318  eff_BvsS->SetBinContent( bini, effB );
2319  rej_BvsS->SetBinContent( bini, 1.0-effB );
2321  inveff_BvsS->SetBinContent( bini, 1.0/effB );
2322  }
2323 
2324  // create splines for histogram
2325  fSpleffBvsS = new TSpline1( "effBvsS", new TGraph( eff_BvsS ) );
2326 
2327  // search for overlap point where, when cutting on it,
2328  // one would obtain: eff_S = rej_B = 1 - eff_B
2329  Double_t effS = 0., rejB, effS_ = 0., rejB_ = 0.;
2330  Int_t nbins_ = 5000;
2331  for (Int_t bini=1; bini<=nbins_; bini++) {
2332 
2333  // get corresponding signal and background efficiencies
2334  effS = (bini - 0.5)/Float_t(nbins_);
2335  rejB = 1.0 - fSpleffBvsS->Eval( effS );
2336 
2337  // find signal efficiency that corresponds to required background efficiency
2338  if ((effS - rejB)*(effS_ - rejB_) < 0) break;
2339  effS_ = effS;
2340  rejB_ = rejB;
2341  }
2342 
2343  // find cut that corresponds to signal efficiency and update signal-like criterion
2344  Double_t cut = rootFinder.Root( 0.5*(effS + effS_) );
2345  SetSignalReferenceCut( cut );
2346  fEffS = 0;
2347  }
2348 
2349  // must exist...
2350  if (0 == fSpleffBvsS) {
2351  delete list;
2352  return 0.0;
2353  }
2354 
2355  // now find signal efficiency that corresponds to required background efficiency
2356  Double_t effS = 0, effB = 0, effS_ = 0, effB_ = 0;
2357  Int_t nbins_ = 1000;
2358 
2359  if (computeArea) {
2360 
2361  // compute area of rej-vs-eff plot
2362  Double_t integral = 0;
2363  for (Int_t bini=1; bini<=nbins_; bini++) {
2364 
2365  // get corresponding signal and background efficiencies
2366  effS = (bini - 0.5)/Float_t(nbins_);
2367  effB = fSpleffBvsS->Eval( effS );
2368  integral += (1.0 - effB);
2369  }
2370  integral /= nbins_;
2371 
2372  delete list;
2373  return integral;
2374  }
2375  else {
2376 
2377  // that will be the value of the efficiency retured (does not affect
2378  // the efficiency-vs-bkg plot which is done anyway.
2379  Float_t effBref = atof( ((TObjString*)list->At(1))->GetString() );
2380 
2381  // find precise efficiency value
2382  for (Int_t bini=1; bini<=nbins_; bini++) {
2383 
2384  // get corresponding signal and background efficiencies
2385  effS = (bini - 0.5)/Float_t(nbins_);
2386  effB = fSpleffBvsS->Eval( effS );
2387 
2388  // find signal efficiency that corresponds to required background efficiency
2389  if ((effB - effBref)*(effB_ - effBref) <= 0) break;
2390  effS_ = effS;
2391  effB_ = effB;
2392  }
2393 
2394  // take mean between bin above and bin below
2395  effS = 0.5*(effS + effS_);
2396 
2397  effSerr = 0;
2398  if (nevtS > 0) effSerr = TMath::Sqrt( effS*(1.0 - effS)/nevtS );
2399 
2400  delete list;
2401  return effS;
2402  }
2403 
2404  return -1;
2405 }
2406 
2407 ////////////////////////////////////////////////////////////////////////////////
2408 
2410 {
2411  Data()->SetCurrentType(Types::kTraining);
2412 
2413  Results* results = Data()->GetResults(GetMethodName(), Types::kTesting, Types::kNoAnalysisType);
2414 
2415  // fill background efficiency (resp. rejection) versus signal efficiency plots
2416  // returns signal efficiency at background efficiency indicated in theString
2417 
2418  // parse input string for required background efficiency
2419  TList* list = gTools().ParseFormatLine( theString );
2420  // sanity check
2421 
2422  if (list->GetSize() != 2) {
2423  Log() << kFATAL << "<GetTrainingEfficiency> Wrong number of arguments"
2424  << " in string: " << theString
2425  << " | required format, e.g., Efficiency:0.05" << Endl;
2426  delete list;
2427  return -1;
2428  }
2429  // that will be the value of the efficiency retured (does not affect
2430  // the efficiency-vs-bkg plot which is done anyway.
2431  Float_t effBref = atof( ((TObjString*)list->At(1))->GetString() );
2432 
2433  delete list;
2434 
2435  // sanity check
2436  if (results->GetHist("MVA_S")->GetNbinsX() != results->GetHist("MVA_B")->GetNbinsX() ||
2437  results->GetHist("MVA_HIGHBIN_S")->GetNbinsX() != results->GetHist("MVA_HIGHBIN_B")->GetNbinsX() ) {
2438  Log() << kFATAL << "<GetTrainingEfficiency> Binning mismatch between signal and background histos"
2439  << Endl;
2440  return -1.0;
2441  }
2442 
2443  // create histogram
2444 
2445  // first, get efficiency histograms for signal and background
2446  TH1 * effhist = results->GetHist("MVA_HIGHBIN_S");
2447  Double_t xmin = effhist->GetXaxis()->GetXmin();
2448  Double_t xmax = effhist->GetXaxis()->GetXmax();
2449 
2450  // first round ? --> create and fill histograms
2451  if (results->DoesExist("MVA_TRAIN_S")==0) {
2452 
2453  // classifier response distributions for test sample
2454  Double_t sxmax = fXmax+0.00001;
2455 
2456  // MVA plots on the training sample (check for overtraining)
2457  TH1* mva_s_tr = new TH1D( GetTestvarName() + "_Train_S",GetTestvarName() + "_Train_S", fNbinsMVAoutput, fXmin, sxmax );
2458  TH1* mva_b_tr = new TH1D( GetTestvarName() + "_Train_B",GetTestvarName() + "_Train_B", fNbinsMVAoutput, fXmin, sxmax );
2459  results->Store(mva_s_tr, "MVA_TRAIN_S");
2460  results->Store(mva_b_tr, "MVA_TRAIN_B");
2461  mva_s_tr->Sumw2();
2462  mva_b_tr->Sumw2();
2463 
2464  // Training efficiency plots
2465  TH1* mva_eff_tr_s = new TH1D( GetTestvarName() + "_trainingEffS", GetTestvarName() + " (signal)",
2466  fNbinsH, xmin, xmax );
2467  TH1* mva_eff_tr_b = new TH1D( GetTestvarName() + "_trainingEffB", GetTestvarName() + " (background)",
2468  fNbinsH, xmin, xmax );
2469  results->Store(mva_eff_tr_s, "MVA_TRAINEFF_S");
2470  results->Store(mva_eff_tr_b, "MVA_TRAINEFF_B");
2471 
2472  // sign if cut
2473  Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2474 
2475  // this method is unbinned
2476  for (Int_t ievt=0; ievt<Data()->GetNEvents(); ievt++) {
2477 
2478  Data()->SetCurrentEvent(ievt);
2479  const Event* ev = GetEvent();
2480 
2481  Double_t theVal = GetMvaValue();
2482  Double_t theWeight = ev->GetWeight();
2483 
2484  TH1* theEffHist = DataInfo().IsSignal(ev) ? mva_eff_tr_s : mva_eff_tr_b;
2485  TH1* theClsHist = DataInfo().IsSignal(ev) ? mva_s_tr : mva_b_tr;
2486 
2487  theClsHist->Fill( theVal, theWeight );
2488 
2489  TAxis* axis = theEffHist->GetXaxis();
2490  Int_t maxbin = Int_t((theVal - axis->GetXmin())/(axis->GetXmax() - axis->GetXmin())*fNbinsH) + 1;
2491  if (sign > 0 && maxbin > fNbinsH) continue; // can happen... event doesn't count
2492  if (sign < 0 && maxbin < 1 ) continue; // can happen... event doesn't count
2493  if (sign > 0 && maxbin < 1 ) maxbin = 1;
2494  if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2495 
2496  if (sign > 0) for (Int_t ibin=1; ibin<=maxbin; ibin++) theEffHist->AddBinContent( ibin , theWeight );
2497  else for (Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theEffHist->AddBinContent( ibin , theWeight );
2498  }
2499 
2500  // normalise output distributions
2501  // uncomment those (and several others if you want unnormalized output
2502  gTools().NormHist( mva_s_tr );
2503  gTools().NormHist( mva_b_tr );
2504 
2505  // renormalise to maximum
2506  mva_eff_tr_s->Scale( 1.0/TMath::Max(std::numeric_limits<double>::epsilon(), mva_eff_tr_s->GetMaximum()) );
2507  mva_eff_tr_b->Scale( 1.0/TMath::Max(std::numeric_limits<double>::epsilon(), mva_eff_tr_b->GetMaximum()) );
2508 
2509  // Training background efficiency versus signal efficiency
2510  TH1* eff_bvss = new TH1D( GetTestvarName() + "_trainingEffBvsS", GetTestvarName() + "", fNbins, 0, 1 );
2511  // Training background rejection (=1-eff.) versus signal efficiency
2512  TH1* rej_bvss = new TH1D( GetTestvarName() + "_trainingRejBvsS", GetTestvarName() + "", fNbins, 0, 1 );
2513  results->Store(eff_bvss, "EFF_BVSS_TR");
2514  results->Store(rej_bvss, "REJ_BVSS_TR");
2515 
2516  // use root finder
2517  // spline background efficiency plot
2518  // note that there is a bin shift when going from a TH1D object to a TGraph :-(
2519  if (Use_Splines_for_Eff_) {
2520  if (fSplTrainRefS) delete fSplTrainRefS;
2521  if (fSplTrainRefB) delete fSplTrainRefB;
2522  fSplTrainRefS = new TSpline1( "spline2_signal", new TGraph( mva_eff_tr_s ) );
2523  fSplTrainRefB = new TSpline1( "spline2_background", new TGraph( mva_eff_tr_b ) );
2524 
2525  // verify spline sanity
2526  gTools().CheckSplines( mva_eff_tr_s, fSplTrainRefS );
2527  gTools().CheckSplines( mva_eff_tr_b, fSplTrainRefB );
2528  }
2529 
2530  // make the background-vs-signal efficiency plot
2531 
2532  // create root finder
2533  // reset static "this" pointer before calling external function
2534  ResetThisBase();
2535  RootFinder rootFinder(&IGetEffForRoot, fXmin, fXmax );
2536 
2537  Double_t effB = 0;
2538  fEffS = results->GetHist("MVA_TRAINEFF_S");
2539  for (Int_t bini=1; bini<=fNbins; bini++) {
2540 
2541  // find cut value corresponding to a given signal efficiency
2542  Double_t effS = eff_bvss->GetBinCenter( bini );
2543 
2544  Double_t cut = rootFinder.Root( effS );
2545 
2546  // retrieve background efficiency for given cut
2547  if (Use_Splines_for_Eff_) effB = fSplTrainRefB->Eval( cut );
2548  else effB = mva_eff_tr_b->GetBinContent( mva_eff_tr_b->FindBin( cut ) );
2549 
2550  // and fill histograms
2551  eff_bvss->SetBinContent( bini, effB );
2552  rej_bvss->SetBinContent( bini, 1.0-effB );
2553  }
2554  fEffS = 0;
2555 
2556  // create splines for histogram
2557  fSplTrainEffBvsS = new TSpline1( "effBvsS", new TGraph( eff_bvss ) );
2558  }
2559 
2560  // must exist...
2561  if (0 == fSplTrainEffBvsS) return 0.0;
2562 
2563  // now find signal efficiency that corresponds to required background efficiency
2564  Double_t effS = 0., effB, effS_ = 0., effB_ = 0.;
2565  Int_t nbins_ = 1000;
2566  for (Int_t bini=1; bini<=nbins_; bini++) {
2567 
2568  // get corresponding signal and background efficiencies
2569  effS = (bini - 0.5)/Float_t(nbins_);
2570  effB = fSplTrainEffBvsS->Eval( effS );
2571 
2572  // find signal efficiency that corresponds to required background efficiency
2573  if ((effB - effBref)*(effB_ - effBref) <= 0) break;
2574  effS_ = effS;
2575  effB_ = effB;
2576  }
2577 
2578  return 0.5*(effS + effS_); // the mean between bin above and bin below
2579 }
2580 
2581 //_______________________________________________________________________
2582 
2583 
2584 std::vector<Float_t> TMVA::MethodBase::GetMulticlassEfficiency(std::vector<std::vector<Float_t> >& purity)
2585 {
2586  Data()->SetCurrentType(Types::kTesting);
2587  ResultsMulticlass* resMulticlass = dynamic_cast<ResultsMulticlass*>(Data()->GetResults(GetMethodName(), Types::kTesting, Types::kMulticlass));
2588  if (!resMulticlass) Log() << kFATAL<< "unable to create pointer in GetMulticlassEfficiency, exiting."<<Endl;
2589 
2590  purity.push_back(resMulticlass->GetAchievablePur());
2591  return resMulticlass->GetAchievableEff();
2592 }
2593 
2594 //_______________________________________________________________________
2595 
2596 std::vector<Float_t> TMVA::MethodBase::GetMulticlassTrainingEfficiency(std::vector<std::vector<Float_t> >& purity)
2597 {
2598  Data()->SetCurrentType(Types::kTraining);
2599  ResultsMulticlass* resMulticlass = dynamic_cast<ResultsMulticlass*>(Data()->GetResults(GetMethodName(), Types::kTraining, Types::kMulticlass));
2600  if (!resMulticlass) Log() << kFATAL<< "unable to create pointer in GetMulticlassTrainingEfficiency, exiting."<<Endl;
2601 
2602  Log() << kINFO << "Determine optimal multiclass cuts for training data..." << Endl;
2603  for (UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
2604  resMulticlass->GetBestMultiClassCuts(icls);
2605  }
2606 
2607  purity.push_back(resMulticlass->GetAchievablePur());
2608  return resMulticlass->GetAchievableEff();
2609 }
2610 
2611 
2612 ////////////////////////////////////////////////////////////////////////////////
2613 /// compute significance of mean difference
2614 /// significance = |<S> - <B>|/Sqrt(RMS_S2 + RMS_B2)
2615 
2617 {
2618  Double_t rms = sqrt( fRmsS*fRmsS + fRmsB*fRmsB );
2619 
2620  return (rms > 0) ? TMath::Abs(fMeanS - fMeanB)/rms : 0;
2621 }
2622 
2623 ////////////////////////////////////////////////////////////////////////////////
2624 /// compute "separation" defined as
2625 /// <s2> = (1/2) Int_-oo..+oo { (S(x) - B(x))^2/(S(x) + B(x)) dx }
2626 
2628 {
2629  return gTools().GetSeparation( histoS, histoB );
2630 }
2631 
2632 ////////////////////////////////////////////////////////////////////////////////
2633 /// compute "separation" defined as
2634 /// <s2> = (1/2) Int_-oo..+oo { (S(x) - B(x))^2/(S(x) + B(x)) dx }
2635 
2637 {
2638  // note, if zero pointers given, use internal pdf
2639  // sanity check first
2640  if ((!pdfS && pdfB) || (pdfS && !pdfB))
2641  Log() << kFATAL << "<GetSeparation> Mismatch in pdfs" << Endl;
2642  if (!pdfS) pdfS = fSplS;
2643  if (!pdfB) pdfB = fSplB;
2644 
2645  if (!fSplS || !fSplB) {
2646  Log()<<kWARNING<< "could not calculate the separation, distributions"
2647  << " fSplS or fSplB are not yet filled" << Endl;
2648  return 0;
2649  }else{
2650  return gTools().GetSeparation( *pdfS, *pdfB );
2651  }
2652 }
2653 
2654 ////////////////////////////////////////////////////////////////////////////////
2655 /// calculate the area (integral) under the ROC curve as a
2656 /// overall quality measure of the classification
2657 
2659 {
2660  // note, if zero pointers given, use internal pdf
2661  // sanity check first
2662  if ((!histS && histB) || (histS && !histB))
2663  Log() << kFATAL << "<GetROCIntegral(TH1D*, TH1D*)> Mismatch in hists" << Endl;
2664 
2665  if (histS==0 || histB==0) return 0.;
2666 
2667  TMVA::PDF *pdfS = new TMVA::PDF( " PDF Sig", histS, TMVA::PDF::kSpline3 );
2668  TMVA::PDF *pdfB = new TMVA::PDF( " PDF Bkg", histB, TMVA::PDF::kSpline3 );
2669 
2670 
2671  Double_t xmin = TMath::Min(pdfS->GetXmin(), pdfB->GetXmin());
2672  Double_t xmax = TMath::Max(pdfS->GetXmax(), pdfB->GetXmax());
2673 
2674  Double_t integral = 0;
2675  UInt_t nsteps = 1000;
2676  Double_t step = (xmax-xmin)/Double_t(nsteps);
2677  Double_t cut = xmin;
2678  for (UInt_t i=0; i<nsteps; i++) {
2679  integral += (1-pdfB->GetIntegral(cut,xmax)) * pdfS->GetVal(cut);
2680  cut+=step;
2681  }
2682  return integral*step;
2683 }
2684 
2685 
2686 ////////////////////////////////////////////////////////////////////////////////
2687 /// calculate the area (integral) under the ROC curve as a
2688 /// overall quality measure of the classification
2689 
2691 {
2692  // note, if zero pointers given, use internal pdf
2693  // sanity check first
2694  if ((!pdfS && pdfB) || (pdfS && !pdfB))
2695  Log() << kFATAL << "<GetSeparation> Mismatch in pdfs" << Endl;
2696  if (!pdfS) pdfS = fSplS;
2697  if (!pdfB) pdfB = fSplB;
2698 
2699  if (pdfS==0 || pdfB==0) return 0.;
2700 
2701  Double_t xmin = TMath::Min(pdfS->GetXmin(), pdfB->GetXmin());
2702  Double_t xmax = TMath::Max(pdfS->GetXmax(), pdfB->GetXmax());
2703 
2704  Double_t integral = 0;
2705  UInt_t nsteps = 1000;
2706  Double_t step = (xmax-xmin)/Double_t(nsteps);
2707  Double_t cut = xmin;
2708  for (UInt_t i=0; i<nsteps; i++) {
2709  integral += (1-pdfB->GetIntegral(cut,xmax)) * pdfS->GetVal(cut);
2710  cut+=step;
2711  }
2712  return integral*step;
2713 }
2714 
2715 ////////////////////////////////////////////////////////////////////////////////
2716 /// plot significance, S/Sqrt(S^2 + B^2), curve for given number
2717 /// of signal and background events; returns cut for maximum significance
2718 /// also returned via reference is the maximum significance
2719 
2721  Double_t BackgroundEvents,
2722  Double_t& max_significance_value ) const
2723 {
2724  Results* results = Data()->GetResults( GetMethodName(), Types::kTesting, Types::kMaxAnalysisType );
2725 
2726  Double_t max_significance(0);
2727  Double_t effS(0),effB(0),significance(0);
2728  TH1D *temp_histogram = new TH1D("temp", "temp", fNbinsH, fXmin, fXmax );
2729 
2730  if (SignalEvents <= 0 || BackgroundEvents <= 0) {
2731  Log() << kFATAL << "<GetMaximumSignificance> "
2732  << "Number of signal or background events is <= 0 ==> abort"
2733  << Endl;
2734  }
2735 
2736  Log() << kINFO << "Using ratio SignalEvents/BackgroundEvents = "
2737  << SignalEvents/BackgroundEvents << Endl;
2738 
2739  TH1* eff_s = results->GetHist("MVA_EFF_S");
2740  TH1* eff_b = results->GetHist("MVA_EFF_B");
2741 
2742  if ( (eff_s==0) || (eff_b==0) ) {
2743  Log() << kWARNING << "Efficiency histograms empty !" << Endl;
2744  Log() << kWARNING << "no maximum cut found, return 0" << Endl;
2745  return 0;
2746  }
2747 
2748  for (Int_t bin=1; bin<=fNbinsH; bin++) {
2749  effS = eff_s->GetBinContent( bin );
2750  effB = eff_b->GetBinContent( bin );
2751 
2752  // put significance into a histogram
2753  significance = sqrt(SignalEvents)*( effS )/sqrt( effS + ( BackgroundEvents / SignalEvents) * effB );
2754 
2755  temp_histogram->SetBinContent(bin,significance);
2756  }
2757 
2758  // find maximum in histogram
2759  max_significance = temp_histogram->GetBinCenter( temp_histogram->GetMaximumBin() );
2760  max_significance_value = temp_histogram->GetBinContent( temp_histogram->GetMaximumBin() );
2761 
2762  // delete
2763  delete temp_histogram;
2764 
2765  Log() << kINFO << "Optimal cut at : " << max_significance << Endl;
2766  Log() << kINFO << "Maximum significance: " << max_significance_value << Endl;
2767 
2768  return max_significance;
2769 }
2770 
2771 ////////////////////////////////////////////////////////////////////////////////
2772 /// calculates rms,mean, xmin, xmax of the event variable
2773 /// this can be either done for the variables as they are or for
2774 /// normalised variables (in the range of 0-1) if "norm" is set to kTRUE
2775 
2776 void TMVA::MethodBase::Statistics( Types::ETreeType treeType, const TString& theVarName,
2777  Double_t& meanS, Double_t& meanB,
2778  Double_t& rmsS, Double_t& rmsB,
2779  Double_t& xmin, Double_t& xmax )
2780 {
2781  Types::ETreeType previousTreeType = Data()->GetCurrentType();
2782  Data()->SetCurrentType(treeType);
2783 
2784  Long64_t entries = Data()->GetNEvents();
2785 
2786  // sanity check
2787  if (entries <=0)
2788  Log() << kFATAL << "<CalculateEstimator> Wrong tree type: " << treeType << Endl;
2789 
2790  // index of the wanted variable
2791  UInt_t varIndex = DataInfo().FindVarIndex( theVarName );
2792 
2793  // first fill signal and background in arrays before analysis
2794  xmin = +DBL_MAX;
2795  xmax = -DBL_MAX;
2796  Long64_t nEventsS = -1;
2797  Long64_t nEventsB = -1;
2798 
2799  // take into account event weights
2800  meanS = 0;
2801  meanB = 0;
2802  rmsS = 0;
2803  rmsB = 0;
2804  Double_t sumwS = 0, sumwB = 0;
2805 
2806  // loop over all training events
2807  for (Int_t ievt = 0; ievt < entries; ievt++) {
2808 
2809  const Event* ev = GetEvent(ievt);
2810 
2811  Double_t theVar = ev->GetValue(varIndex);
2812  Double_t weight = ev->GetWeight();
2813 
2814  if (DataInfo().IsSignal(ev)) {
2815  sumwS += weight;
2816  meanS += weight*theVar;
2817  rmsS += weight*theVar*theVar;
2818  }
2819  else {
2820  sumwB += weight;
2821  meanB += weight*theVar;
2822  rmsB += weight*theVar*theVar;
2823  }
2824  xmin = TMath::Min( xmin, theVar );
2825  xmax = TMath::Max( xmax, theVar );
2826  }
2827  ++nEventsS;
2828  ++nEventsB;
2829 
2830  meanS = meanS/sumwS;
2831  meanB = meanB/sumwB;
2832  rmsS = TMath::Sqrt( rmsS/sumwS - meanS*meanS );
2833  rmsB = TMath::Sqrt( rmsB/sumwB - meanB*meanB );
2834 
2835  Data()->SetCurrentType(previousTreeType);
2836 }
2837 
2838 ////////////////////////////////////////////////////////////////////////////////
2839 /// create reader class for method (classification only at present)
2840 
2841 void TMVA::MethodBase::MakeClass( const TString& theClassFileName ) const
2842 {
2843  // the default consists of
2844  TString classFileName = "";
2845  if (theClassFileName == "")
2846  classFileName = GetWeightFileDir() + "/" + GetJobName() + "_" + GetMethodName() + ".class.C";
2847  else
2848  classFileName = theClassFileName;
2849 
2850  TString className = TString("Read") + GetMethodName();
2851 
2852  TString tfname( classFileName );
2853  Log() << kINFO << "Creating standalone response class: "
2854  << gTools().Color("lightblue") << classFileName << gTools().Color("reset") << Endl;
2855 
2856  std::ofstream fout( classFileName );
2857  if (!fout.good()) { // file could not be opened --> Error
2858  Log() << kFATAL << "<MakeClass> Unable to open file: " << classFileName << Endl;
2859  }
2860 
2861  // now create the class
2862  // preamble
2863  fout << "// Class: " << className << std::endl;
2864  fout << "// Automatically generated by MethodBase::MakeClass" << std::endl << "//" << std::endl;
2865 
2866  // print general information and configuration state
2867  fout << std::endl;
2868  fout << "/* configuration options =====================================================" << std::endl << std::endl;
2869  WriteStateToStream( fout );
2870  fout << std::endl;
2871  fout << "============================================================================ */" << std::endl;
2872 
2873  // generate the class
2874  fout << "" << std::endl;
2875  fout << "#include <vector>" << std::endl;
2876  fout << "#include <cmath>" << std::endl;
2877  fout << "#include <string>" << std::endl;
2878  fout << "#include <iostream>" << std::endl;
2879  fout << "" << std::endl;
2880  // now if the classifier needs to write some addicional classes for its response implementation
2881  // this code goes here: (at least the header declarations need to come before the main class
2882  this->MakeClassSpecificHeader( fout, className );
2883 
2884  fout << "#ifndef IClassifierReader__def" << std::endl;
2885  fout << "#define IClassifierReader__def" << std::endl;
2886  fout << std::endl;
2887  fout << "class IClassifierReader {" << std::endl;
2888  fout << std::endl;
2889  fout << " public:" << std::endl;
2890  fout << std::endl;
2891  fout << " // constructor" << std::endl;
2892  fout << " IClassifierReader() : fStatusIsClean( true ) {}" << std::endl;
2893  fout << " virtual ~IClassifierReader() {}" << std::endl;
2894  fout << std::endl;
2895  fout << " // return classifier response" << std::endl;
2896  fout << " virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;" << std::endl;
2897  fout << std::endl;
2898  fout << " // returns classifier status" << std::endl;
2899  fout << " bool IsStatusClean() const { return fStatusIsClean; }" << std::endl;
2900  fout << std::endl;
2901  fout << " protected:" << std::endl;
2902  fout << std::endl;
2903  fout << " bool fStatusIsClean;" << std::endl;
2904  fout << "};" << std::endl;
2905  fout << std::endl;
2906  fout << "#endif" << std::endl;
2907  fout << std::endl;
2908  fout << "class " << className << " : public IClassifierReader {" << std::endl;
2909  fout << std::endl;
2910  fout << " public:" << std::endl;
2911  fout << std::endl;
2912  fout << " // constructor" << std::endl;
2913  fout << " " << className << "( std::vector<std::string>& theInputVars ) " << std::endl;
2914  fout << " : IClassifierReader()," << std::endl;
2915  fout << " fClassName( \"" << className << "\" )," << std::endl;
2916  fout << " fNvars( " << GetNvar() << " )," << std::endl;
2917  fout << " fIsNormalised( " << (IsNormalised() ? "true" : "false") << " )" << std::endl;
2918  fout << " { " << std::endl;
2919  fout << " // the training input variables" << std::endl;
2920  fout << " const char* inputVars[] = { ";
2921  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
2922  fout << "\"" << GetOriginalVarName(ivar) << "\"";
2923  if (ivar<GetNvar()-1) fout << ", ";
2924  }
2925  fout << " };" << std::endl;
2926  fout << std::endl;
2927  fout << " // sanity checks" << std::endl;
2928  fout << " if (theInputVars.size() <= 0) {" << std::endl;
2929  fout << " std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": empty input vector\" << std::endl;" << std::endl;
2930  fout << " fStatusIsClean = false;" << std::endl;
2931  fout << " }" << std::endl;
2932  fout << std::endl;
2933  fout << " if (theInputVars.size() != fNvars) {" << std::endl;
2934  fout << " std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in number of input values: \"" << std::endl;
2935  fout << " << theInputVars.size() << \" != \" << fNvars << std::endl;" << std::endl;
2936  fout << " fStatusIsClean = false;" << std::endl;
2937  fout << " }" << std::endl;
2938  fout << std::endl;
2939  fout << " // validate input variables" << std::endl;
2940  fout << " for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {" << std::endl;
2941  fout << " if (theInputVars[ivar] != inputVars[ivar]) {" << std::endl;
2942  fout << " std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in input variable names\" << std::endl" << std::endl;
2943  fout << " << \" for variable [\" << ivar << \"]: \" << theInputVars[ivar].c_str() << \" != \" << inputVars[ivar] << std::endl;" << std::endl;
2944  fout << " fStatusIsClean = false;" << std::endl;
2945  fout << " }" << std::endl;
2946  fout << " }" << std::endl;
2947  fout << std::endl;
2948  fout << " // initialize min and max vectors (for normalisation)" << std::endl;
2949  for (UInt_t ivar = 0; ivar < GetNvar(); ivar++) {
2950  fout << " fVmin[" << ivar << "] = " << std::setprecision(15) << GetXmin( ivar ) << ";" << std::endl;
2951  fout << " fVmax[" << ivar << "] = " << std::setprecision(15) << GetXmax( ivar ) << ";" << std::endl;
2952  }
2953  fout << std::endl;
2954  fout << " // initialize input variable types" << std::endl;
2955  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
2956  fout << " fType[" << ivar << "] = \'" << DataInfo().GetVariableInfo(ivar).GetVarType() << "\';" << std::endl;
2957  }
2958  fout << std::endl;
2959  fout << " // initialize constants" << std::endl;
2960  fout << " Initialize();" << std::endl;
2961  fout << std::endl;
2962  if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
2963  fout << " // initialize transformation" << std::endl;
2964  fout << " InitTransform();" << std::endl;
2965  }
2966  fout << " }" << std::endl;
2967  fout << std::endl;
2968  fout << " // destructor" << std::endl;
2969  fout << " virtual ~" << className << "() {" << std::endl;
2970  fout << " Clear(); // method-specific" << std::endl;
2971  fout << " }" << std::endl;
2972  fout << std::endl;
2973  fout << " // the classifier response" << std::endl;
2974  fout << " // \"inputValues\" is a vector of input values in the same order as the " << std::endl;
2975  fout << " // variables given to the constructor" << std::endl;
2976  fout << " double GetMvaValue( const std::vector<double>& inputValues ) const;" << std::endl;
2977  fout << std::endl;
2978  fout << " private:" << std::endl;
2979  fout << std::endl;
2980  fout << " // method-specific destructor" << std::endl;
2981  fout << " void Clear();" << std::endl;
2982  fout << std::endl;
2983  if (GetTransformationHandler().GetTransformationList().GetSize()!=0) {
2984  fout << " // input variable transformation" << std::endl;
2985  GetTransformationHandler().MakeFunction(fout, className,1);
2986  fout << " void InitTransform();" << std::endl;
2987  fout << " void Transform( std::vector<double> & iv, int sigOrBgd ) const;" << std::endl;
2988  fout << std::endl;
2989  }
2990  fout << " // common member variables" << std::endl;
2991  fout << " const char* fClassName;" << std::endl;
2992  fout << std::endl;
2993  fout << " const size_t fNvars;" << std::endl;
2994  fout << " size_t GetNvar() const { return fNvars; }" << std::endl;
2995  fout << " char GetType( int ivar ) const { return fType[ivar]; }" << std::endl;
2996  fout << std::endl;
2997  fout << " // normalisation of input variables" << std::endl;
2998  fout << " const bool fIsNormalised;" << std::endl;
2999  fout << " bool IsNormalised() const { return fIsNormalised; }" << std::endl;
3000  fout << " double fVmin[" << GetNvar() << "];" << std::endl;
3001  fout << " double fVmax[" << GetNvar() << "];" << std::endl;
3002  fout << " double NormVariable( double x, double xmin, double xmax ) const {" << std::endl;
3003  fout << " // normalise to output range: [-1, 1]" << std::endl;
3004  fout << " return 2*(x - xmin)/(xmax - xmin) - 1.0;" << std::endl;
3005  fout << " }" << std::endl;
3006  fout << std::endl;
3007  fout << " // type of input variable: 'F' or 'I'" << std::endl;
3008  fout << " char fType[" << GetNvar() << "];" << std::endl;
3009  fout << std::endl;
3010  fout << " // initialize internal variables" << std::endl;
3011  fout << " void Initialize();" << std::endl;
3012  fout << " double GetMvaValue__( const std::vector<double>& inputValues ) const;" << std::endl;
3013  fout << "" << std::endl;
3014  fout << " // private members (method specific)" << std::endl;
3015 
3016  // call the classifier specific output (the classifier must close the class !)
3017  MakeClassSpecific( fout, className );
3018 
3019  fout << " inline double " << className << "::GetMvaValue( const std::vector<double>& inputValues ) const" << std::endl;
3020  fout << " {" << std::endl;
3021  fout << " // classifier response value" << std::endl;
3022  fout << " double retval = 0;" << std::endl;
3023  fout << std::endl;
3024  fout << " // classifier response, sanity check first" << std::endl;
3025  fout << " if (!IsStatusClean()) {" << std::endl;
3026  fout << " std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": cannot return classifier response\"" << std::endl;
3027  fout << " << \" because status is dirty\" << std::endl;" << std::endl;
3028  fout << " retval = 0;" << std::endl;
3029  fout << " }" << std::endl;
3030  fout << " else {" << std::endl;
3031  fout << " if (IsNormalised()) {" << std::endl;
3032  fout << " // normalise variables" << std::endl;
3033  fout << " std::vector<double> iV;" << std::endl;
3034  fout << " iV.reserve(inputValues.size());" << std::endl;
3035  fout << " int ivar = 0;" << std::endl;
3036  fout << " for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3037  fout << " varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3038  fout << " iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));" << std::endl;
3039  fout << " }" << std::endl;
3040  if (GetTransformationHandler().GetTransformationList().GetSize()!=0 &&
3041  GetMethodType() != Types::kLikelihood &&
3042  GetMethodType() != Types::kHMatrix) {
3043  fout << " Transform( iV, -1 );" << std::endl;
3044  }
3045  fout << " retval = GetMvaValue__( iV );" << std::endl;
3046  fout << " }" << std::endl;
3047  fout << " else {" << std::endl;
3048  if (GetTransformationHandler().GetTransformationList().GetSize()!=0 &&
3049  GetMethodType() != Types::kLikelihood &&
3050  GetMethodType() != Types::kHMatrix) {
3051  fout << " std::vector<double> iV;" << std::endl;
3052  fout << " int ivar = 0;" << std::endl;
3053  fout << " for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3054  fout << " varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3055  fout << " iV.push_back(*varIt);" << std::endl;
3056  fout << " }" << std::endl;
3057  fout << " Transform( iV, -1 );" << std::endl;
3058  fout << " retval = GetMvaValue__( iV );" << std::endl;
3059  }
3060  else {
3061  fout << " retval = GetMvaValue__( inputValues );" << std::endl;
3062  }
3063  fout << " }" << std::endl;
3064  fout << " }" << std::endl;
3065  fout << std::endl;
3066  fout << " return retval;" << std::endl;
3067  fout << " }" << std::endl;
3068 
3069  // create output for transformation - if any
3070  if (GetTransformationHandler().GetTransformationList().GetSize()!=0)
3071  GetTransformationHandler().MakeFunction(fout, className,2);
3072 
3073  // close the file
3074  fout.close();
3075 }
3076 
3077 ////////////////////////////////////////////////////////////////////////////////
3078 /// prints out method-specific help method
3079 
3081 {
3082  // if options are written to reference file, also append help info
3083  std::streambuf* cout_sbuf = std::cout.rdbuf(); // save original sbuf
3084  std::ofstream* o = 0;
3085  if (gConfig().WriteOptionsReference()) {
3086  Log() << kINFO << "Print Help message for class " << GetName() << " into file: " << GetReferenceFile() << Endl;
3087  o = new std::ofstream( GetReferenceFile(), std::ios::app );
3088  if (!o->good()) { // file could not be opened --> Error
3089  Log() << kFATAL << "<PrintHelpMessage> Unable to append to output file: " << GetReferenceFile() << Endl;
3090  }
3091  std::cout.rdbuf( o->rdbuf() ); // redirect 'std::cout' to file
3092  }
3093 
3094  // "|--------------------------------------------------------------|"
3095  if (!o) {
3096  Log() << kINFO << Endl;
3097  Log() << gTools().Color("bold")
3098  << "================================================================"
3099  << gTools().Color( "reset" )
3100  << Endl;
3101  Log() << gTools().Color("bold")
3102  << "H e l p f o r M V A m e t h o d [ " << GetName() << " ] :"
3103  << gTools().Color( "reset" )
3104  << Endl;
3105  }
3106  else {
3107  Log() << "Help for MVA method [ " << GetName() << " ] :" << Endl;
3108  }
3109 
3110  // print method-specific help message
3111  GetHelpMessage();
3112 
3113  if (!o) {
3114  Log() << Endl;
3115  Log() << "<Suppress this message by specifying \"!H\" in the booking option>" << Endl;
3116  Log() << gTools().Color("bold")
3117  << "================================================================"
3118  << gTools().Color( "reset" )
3119  << Endl;
3120  Log() << Endl;
3121  }
3122  else {
3123  // indicate END
3124  Log() << "# End of Message___" << Endl;
3125  }
3126 
3127  std::cout.rdbuf( cout_sbuf ); // restore the original stream buffer
3128  if (o) o->close();
3129 }
3130 
3131 // ----------------------- r o o t f i n d i n g ----------------------------
3132 
3133 ////////////////////////////////////////////////////////////////////////////////
3134 /// interface for RootFinder
3135 
3137 {
3138  return MethodBase::GetThisBase()->GetEffForRoot( theCut );
3139 }
3140 
3141 ////////////////////////////////////////////////////////////////////////////////
3142 /// returns efficiency as function of cut
3143 
3145 {
3146  Double_t retval=0;
3147 
3148  // retrieve the class object
3149  if (Use_Splines_for_Eff_) {
3150  retval = fSplRefS->Eval( theCut );
3151  }
3152  else retval = fEffS->GetBinContent( fEffS->FindBin( theCut ) );
3153 
3154  // caution: here we take some "forbidden" action to hide a problem:
3155  // in some cases, in particular for likelihood, the binned efficiency distributions
3156  // do not equal 1, at xmin, and 0 at xmax; of course, in principle we have the
3157  // unbinned information available in the trees, but the unbinned minimization is
3158  // too slow, and we don't need to do a precision measurement here. Hence, we force
3159  // this property.
3160  Double_t eps = 1.0e-5;
3161  if (theCut-fXmin < eps) retval = (GetCutOrientation() == kPositive) ? 1.0 : 0.0;
3162  else if (fXmax-theCut < eps) retval = (GetCutOrientation() == kPositive) ? 0.0 : 1.0;
3163 
3164  return retval;
3165 }
3166 
3167 ////////////////////////////////////////////////////////////////////////////////
3168 /// returns the event collection (i.e. the dataset) TRANSFORMED using the
3169 /// classifiers specific Variable Transformation (e.g. Decorr or Decorr:Gauss:Decorr)
3170 
3172 {
3173  // if there's no variable transformation for this classifier, just hand back the
3174  // event collection of the data set
3175  if (GetTransformationHandler().GetTransformationList().GetEntries() <= 0) {
3176  return (Data()->GetEventCollection(type));
3177  }
3178 
3179  // otherwise, transform ALL the events and hand back the vector of the pointers to the
3180  // transformed events. If the pointer is already != 0, i.e. the whole thing has been
3181  // done before, I don't need to do it again, but just "hand over" the pointer to those events.
3182  Int_t idx = Data()->TreeIndex(type); //index indicating Training,Testing,... events/datasets
3183  if (fEventCollections.at(idx) == 0) {
3184  fEventCollections.at(idx) = &(Data()->GetEventCollection(type));
3185  fEventCollections.at(idx) = GetTransformationHandler().CalcTransformations(*(fEventCollections.at(idx)),kTRUE);
3186  }
3187  return *(fEventCollections.at(idx));
3188 }
3189 
3190 ////////////////////////////////////////////////////////////////////////////////
3191 /// calculates the TMVA version string from the training version code on the fly
3192 
3194 {
3195  UInt_t a = GetTrainingTMVAVersionCode() & 0xff0000; a>>=16;
3196  UInt_t b = GetTrainingTMVAVersionCode() & 0x00ff00; b>>=8;
3197  UInt_t c = GetTrainingTMVAVersionCode() & 0x0000ff;
3198 
3199  return TString(Form("%i.%i.%i",a,b,c));
3200 }
3201 
3202 ////////////////////////////////////////////////////////////////////////////////
3203 /// calculates the ROOT version string from the training version code on the fly
3204 
3206 {
3207  UInt_t a = GetTrainingROOTVersionCode() & 0xff0000; a>>=16;
3208  UInt_t b = GetTrainingROOTVersionCode() & 0x00ff00; b>>=8;
3209  UInt_t c = GetTrainingROOTVersionCode() & 0x0000ff;
3210 
3211  return TString(Form("%i.%02i/%02i",a,b,c));
3212 }
3213 
3214 ////////////////////////////////////////////////////////////////////////////////
3215 /// return a pointer the base class of this method
3216 
3218 {
3219  return GetThisBaseThreadLocal();
3220 }
3221 
3222 ////////////////////////////////////////////////////////////////////////////////
3223 /// reset required for RootFinder
3224 
3226 {
3227  GetThisBaseThreadLocal() = this;
3228 }
3229 ////////////////////////////////////////////////////////////////////////////////
3230 
3232  ResultsClassification* mvaRes = dynamic_cast<ResultsClassification*>
3234 
3235  if (mvaRes != NULL) {
3236  TH1D *mva_s = dynamic_cast<TH1D*> (mvaRes->GetHist("MVA_S"));
3237  TH1D *mva_b = dynamic_cast<TH1D*> (mvaRes->GetHist("MVA_B"));
3238  TH1D *mva_s_tr = dynamic_cast<TH1D*> (mvaRes->GetHist("MVA_TRAIN_S"));
3239  TH1D *mva_b_tr = dynamic_cast<TH1D*> (mvaRes->GetHist("MVA_TRAIN_B"));
3240 
3241  if ( !mva_s || !mva_b || !mva_s_tr || !mva_b_tr) return -1;
3242 
3243  if (SorB == 's' || SorB == 'S')
3244  return mva_s->KolmogorovTest( mva_s_tr, opt.Data() );
3245  else
3246  return mva_b->KolmogorovTest( mva_b_tr, opt.Data() );
3247  }
3248  return -1;
3249 }
static void SetIgnoreNegWeightsInTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Definition: Event.cxx:395
virtual Int_t GetEntries() const
Definition: TCollection.h:92
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:823
virtual void AddClassifierOutputProb(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Definition: MethodBase.cxx:897
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition: TH1.cxx:3478
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:6174
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
set the tuning parameters accoding to the argument This is just a dummy .
Definition: MethodBase.cxx:654
TXMLEngine & xmlengine()
Definition: Tools.h:277
const TString & GetWeightFileDir() const
Definition: MethodBase.h:407
float xmin
Definition: THbookFile.cxx:93
static TDirectory * RootBaseDir()
Definition: Factory.h:228
void AddInfoItem(void *gi, const TString &name, const TString &value) const
xml writing
#define TMVA_VERSION_CODE
Definition: Version.h:47
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
TH1 * GetHist(const TString &alias) const
Definition: Results.cxx:113
Bool_t GetLine(std::istream &fin, char *buf)
reads one line from the input stream checks for certain keywords and interprets the line if keywords ...
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Definition: Event.cxx:386
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4629
long long Long64_t
Definition: RtypesCore.h:69
TString GetTrainingROOTVersionString() const
calculates the ROOT version string from the training version code on the fly
void AddOutput(Types::ETreeType type, Types::EAnalysisType analysisType)
static void CreateVariableTransforms(const TString &trafoDefinition, TMVA::DataSetInfo &dataInfo, TMVA::TransformationHandler &transformationHandler, TMVA::MsgLogger &log)
create variable transformations
Definition: MethodBase.cxx:488
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
void ReadStateFromXML(void *parent)
Ssiz_t Length() const
Definition: TString.h:390
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
TLine * line
void variables(TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
Definition: variables.cxx:10
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
return c
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
Definition: TH1.cxx:7952
Double_t GetXmin() const
Definition: PDF.h:112
const TString & GetExpression() const
Definition: VariableInfo.h:62
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual void WriteEvaluationHistosToFile(Types::ETreeType treetype)
writes all MVA evaluation histograms to file
TString GetTrainingTMVAVersionString() const
calculates the TMVA version string from the training version code on the fly
virtual std::map< TString, Double_t > OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA")
call the Optimzier with the set of paremeters and ranges that are meant to be tuned.
Definition: MethodBase.cxx:633
Config & gConfig()
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
EAnalysisType
Definition: Types.h:124
virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0)
Compute Quantiles for this histogram Quantile x_q of a probability distribution Function F is defined...
Definition: TH1.cxx:4182
virtual int MakeDirectory(const char *name)
Make a directory.
Definition: TSystem.cxx:821
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual Double_t GetMaximumSignificance(Double_t SignalEvents, Double_t BackgroundEvents, Double_t &optimal_significance_value) const
plot significance, S/Sqrt(S^2 + B^2), curve for given number of signal and background events; returns...
Basic string class.
Definition: TString.h:137
static Bool_t AddDirectoryStatus()
static function: cannot be inlined on Windows/NT
Definition: TH1.cxx:709
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
Double_t GetMutualInformation(const TH2F &)
Mutual Information method for non-linear correlations estimates in 2D histogram Author: Moritz Backes...
Definition: Tools.cxx:598
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1075
virtual Double_t GetKSTrainingVsTest(Char_t SorB, TString opt="X")
int Int_t
Definition: RtypesCore.h:41
virtual void SetYTitle(const char *title)
Definition: TH1.h:409
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
Definition: TDirectory.cxx:955
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="", TDirectory *theBaseDir=0)
standard constructur
Definition: MethodBase.cxx:139
virtual void TestMulticlass()
test multiclass classification
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
Definition: Event.cxx:376
virtual Int_t GetNbinsX() const
Definition: TH1.h:296
#define ROOT_VERSION_CODE
Definition: RVersion.h:21
void ReadTargetsFromXML(void *tarnode)
read target info from XML
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
Definition: Tools.h:308
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition: Tools.cxx:1134
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:311
Iterator of linked list.
Definition: TList.h:187
virtual Bool_t IsSignalLike()
uses a pre-set cut on the MVA output (SetSignalReferenceCut and SetSignalReferenceCutOrientation) for...
Definition: MethodBase.cxx:845
void CreateMVAPdfs()
Create PDFs of the MVA output variables.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1231
TString GetWeightFileName() const
retrieve weight file name
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:625
void ReadVariablesFromXML(void *varnode)
read variable info from XML
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3851
TSocket * s1
Definition: hserv2.C:36
const char * Data() const
Definition: TString.h:349
double sqrt(double)
Tools & gTools()
Definition: Tools.cxx:79
TStopwatch timer
Definition: pirndm.C:37
void WriteStateToStream(std::ostream &tf) const
general method used in writing the header of the weight files where the used variables, variable transformation type etc.
virtual ~MethodBase()
destructor
Definition: MethodBase.cxx:261
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
void Class()
Definition: Class.C:29
void WriteVarsToStream(std::ostream &tf, const TString &prefix="") const
write the list of variables (name, min, max) for a given data transformation method to the stream ...
int d
Definition: tornado.py:11
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:118
Bool_t CheckSplines(const TH1 *, const TSpline *)
Definition: Tools.cxx:487
void * GetChild(void *parent, const char *childname=0)
get child node
Definition: Tools.cxx:1158
void ReadStateFromFile()
Function to write options and weights to file.
virtual void MakeClass(const TString &classFileName=TString("")) const
create reader class for method (classification only at present)
std::vector< Float_t > * GetValueVector()
bool BeginsWith(const std::string &theString, const std::string &theSubstring)
virtual void AddClassifierOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Definition: MethodBase.cxx:859
void ReadClassesFromXML(void *clsnode)
read number of classes from XML
void ResetThisBase()
reset required for RootFinder
std::vector< std::vector< double > > Data
IONames & GetIONames()
Definition: Config.h:78
Double_t NormHist(TH1 *theHist, Double_t norm=1.0)
normalises histogram
Definition: Tools.cxx:395
void SetupMethod()
setup of methods
Definition: MethodBase.cxx:302
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1511
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
TH2D * h2
Definition: fit2dHist.C:45
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1951
virtual Double_t GetProba(const Event *ev)
Definition: PDF.h:71
TH1F * h1
Definition: legend1.C:5
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH1.cxx:1204
Double_t GetXmin() const
Definition: TAxis.h:137
virtual Double_t GetEfficiency(const TString &, Types::ETreeType, Double_t &err)
fill background efficiency (resp.
virtual std::vector< Float_t > GetMulticlassEfficiency(std::vector< std::vector< Float_t > > &purity)
Double_t GetEffForRoot(Double_t)
returns efficiency as function of cut
Double_t Root(Double_t refValue)
Root finding using Brents algorithm; taken from CERNLIB function RZERO.
Definition: RootFinder.cxx:65
A doubly linked list.
Definition: TList.h:47
TString GetElapsedTime(Bool_t Scientific=kTRUE)
Definition: Timer.cxx:131
void ReadStateFromXMLString(const char *xmlstr)
for reading from memory
void AddClassesXMLTo(void *parent) const
write class info to XML
const int nEvents
Definition: testRooFit.cxx:42
void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout=1)
store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
TString fWeightFileExtension
Definition: Config.h:101
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
Definition: TH1.cxx:8470
TThread * t[5]
Definition: threadsh1.C:13
TString fUser
Definition: TSystem.h:152
char GetVarType() const
Definition: VariableInfo.h:67
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition: TH1.cxx:7014
std::string GetMethodName(TCppMethod_t)
Definition: Cppyy.cxx:706
ROOT::R::TRInterface & r
Definition: Object.C:4
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2207
TString dirName
Definition: demos.C:9
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
Class to manage histogram axis.
Definition: TAxis.h:36
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual const char * GetBuildNode() const
Return the build node name.
Definition: TSystem.cxx:3662
SVector< double, 2 > v
Definition: Dict.h:5
Bool_t DoesExist(const TString &alias) const
Definition: Results.cxx:104
void ReadVarsFromStream(std::istream &istr)
Read the variables (name, min, max) for a given data transformation method from the stream...
virtual void WriteMonitoringHistosToFile() const
write special monitoring histograms to file dummy implementation here --------------— ...
virtual void ReadTransformationFromStream(std::istream &istr, const TString &classname="")=0
const Int_t NBIN_HIST_HIGH
Definition: MethodBase.cxx:129
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
class TMVA::Config::VariablePlotting fVariablePlotting
ClassInfo * GetClassInfo(Int_t clNum) const
void Statistics(Types::ETreeType treeType, const TString &theVarName, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &)
calculates rms,mean, xmin, xmax of the event variable this can be either done for the variables as th...
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition: TH1.cxx:8543
Float_t GetAchievablePur(UInt_t cls)
void SetValue(Float_t value, Int_t ievt)
set MVA response
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test...
Definition: TH1.cxx:7610
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t ElapsedSeconds(void)
computes elapsed tim in seconds
Definition: Timer.cxx:124
char * Form(const char *fmt,...)
Double_t GetSeparation(TH1 *S, TH1 *B) const
compute "separation" defined as <s2> = (1/2) Int_-oo..+oo { (S(x) - B(x))^2/(S(x) + B(x)) dx } ...
Definition: Tools.cxx:136
void ReadFromXML(void *varnode)
read VariableInfo from stream
tuple w
Definition: qtexample.py:51
const TString & GetName() const
Definition: ClassInfo.h:72
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1056
virtual Double_t GetSignificance() const
compute significance of mean difference significance = |<S> - |/Sqrt(RMS_S2 + RMS_B2) ...
void ReadAttr(void *node, const char *, T &value)
Definition: Tools.h:295
float xmax
Definition: THbookFile.cxx:93
void DeclareBaseOptions()
define the options (their key words) that can be set in the option string here the options valid for ...
Definition: MethodBase.cxx:403
void BuildTransformationFromVarInfo(const std::vector< TMVA::VariableInfo > &var)
this method is only used when building a normalization transformation from old text files in this cas...
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
REAL epsilon
Definition: triangle.c:617
void ProcessBaseOptions()
the option string is decoded, for availabel options see "DeclareOptions"
Definition: MethodBase.cxx:434
void WriteStateToFile() const
write options and weights to file note that each one text file for the main configuration information...
void AddTargetsXMLTo(void *parent) const
write target info to XML
virtual TObject * FindObject(const char *name) const
Find object by name in the list of memory objects.
Definition: TDirectory.cxx:645
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: PDFInterpol[i...
Definition: PDF.cxx:815
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
void AddVarsXMLTo(void *parent) const
write variable info to XML
TList * GetStorage() const
Definition: Results.h:78
int Ssiz_t
Definition: RtypesCore.h:63
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
const std::vector< TMVA::Event * > & GetEventCollection(Types::ETreeType type)
returns the event collection (i.e.
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
Definition: MethodBase.cxx:327
TH1F * s2
Definition: threadsh2.C:15
#define ClassImp(name)
Definition: Rtypes.h:279
virtual void AddRegressionOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Definition: MethodBase.cxx:747
Double_t GetVal(Double_t x) const
returns value PDF(x)
Definition: PDF.cxx:698
double Double_t
Definition: RtypesCore.h:55
std::vector< Double_t > GetBestMultiClassCuts(UInt_t targetClass)
void SetWeightFileName(TString)
set the weight file name (depreciated)
Describe directory structure in memory.
Definition: TDirectory.h:44
virtual Double_t GetROCIntegral(TH1D *histS, TH1D *histB) const
calculate the area (integral) under the ROC curve as a overall quality measure of the classification ...
int type
Definition: TGX11.cxx:120
void dir(char *path=0)
Definition: rootalias.C:30
TDirectory * BaseDir() const
returns the ROOT directory where info/histograms etc of the corresponding MVA method instance are sto...
Double_t GetXmax() const
Definition: TAxis.h:138
static RooMathCoreReg dummy
void * GetNextChild(void *prevchild, const char *childname=0)
XML helpers.
Definition: Tools.cxx:1170
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition: Event.cxx:231
The TH1 histogram class.
Definition: TH1.h:80
const Bool_t Use_Splines_for_Eff_
Definition: MethodBase.cxx:126
virtual void GetRegressionDeviation(UInt_t tgtNum, Types::ETreeType type, Double_t &stddev, Double_t &stddev90Percent) const
Definition: MethodBase.cxx:727
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
Definition: MethodBase.cxx:317
virtual void AddMulticlassOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Definition: MethodBase.cxx:786
#define name(a, b)
Definition: linkTestLib0.cpp:5
const TString & Color(const TString &)
human readable color strings
Definition: Tools.cxx:837
Mother of all ROOT objects.
Definition: TObject.h:58
Float_t GetTarget(UInt_t itgt) const
Definition: Event.h:101
void * GetExternalLink() const
Definition: VariableInfo.h:85
Float_t GetAchievableEff(UInt_t cls)
char Char_t
Definition: RtypesCore.h:29
virtual Double_t GetSeparation(TH1 *, TH1 *) const
compute "separation" defined as <s2> = (1/2) Int_-oo..+oo { (S(x) - B(x))^2/(S(x) + B(x)) dx } ...
virtual std::vector< Float_t > GetMulticlassTrainingEfficiency(std::vector< std::vector< Float_t > > &purity)
Bool_t axis
Definition: geodemo.C:37
virtual void SetXTitle(const char *title)
Definition: TH1.h:408
virtual void TestRegression(Double_t &bias, Double_t &biasT, Double_t &dev, Double_t &devT, Double_t &rms, Double_t &rmsT, Double_t &mInf, Double_t &mInfT, Double_t &corr, Types::ETreeType type)
calculate <sum-of-deviation-squared> of regression output versus "true" value from test sample ...
Definition: MethodBase.cxx:938
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:433
void ReadFromStream(std::istream &istr)
void PrintHelpMessage() const
prints out method-specific help method
static MethodBase * GetThisBase()
return a pointer the base class of this method
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Definition: MethodBase.cxx:606
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
void AddToXML(void *varnode)
write class to XML
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
TDirectory * MethodBaseDir() const
returns the ROOT directory where all instances of the corresponding MVA method are stored ...
void SetWeightFileDir(TString fileDir)
set directory of weight file
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
void AddSpectatorsXMLTo(void *parent) const
write spectator info to XML
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8350
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
Definition: TDirectory.cxx:336
TList * ParseFormatLine(TString theString, const char *sep=":")
Parse the string and cut into labels separated by ":".
Definition: Tools.cxx:413
#define NULL
Definition: Rtypes.h:82
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
Definition: TString.cxx:1284
virtual Double_t GetTrainingEfficiency(const TString &)
Double_t GetIntegral(Double_t xmin, Double_t xmax)
computes PDF integral within given ranges
Definition: PDF.cxx:651
void ReadSpectatorsFromXML(void *specnode)
read spectator info from XML
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
Definition: Timer.cxx:183
virtual void SelectInput(const TString &inputVariables, Bool_t putIntoVariables=kFALSE)
select the variables/targets/spectators which serve as input to the transformation ...
void InitBase()
default initialization called by all constructors
Definition: MethodBase.cxx:335
Int_t sign(Double_t x)
Definition: CsgOps.cxx:89
void Store(TObject *obj, const char *alias=0)
Definition: Results.cxx:69
virtual Double_t GetRarity(Double_t mvaVal, Types::ESBType reftype=Types::kBackground) const
compute rarity: R(x) = Integrate_[-oo..x] { PDF(x') dx' } where PDF(x) is the PDF of the classifier's...
static Double_t IGetEffForRoot(Double_t)
interface for RootFinder
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition: TDatime.cxx:99
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:7921
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:287
void SetTestvarName(const TString &v="")
Definition: MethodBase.h:306
UInt_t GetNumber() const
Definition: ClassInfo.h:75
float value
Definition: math.cpp:443
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables, variable transformation type etc.
void ComputeStat(const std::vector< TMVA::Event * > &, std::vector< Float_t > *, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Int_t signalClass, Bool_t norm=kFALSE)
sanity check
Definition: Tools.cxx:215
Double_t GetXmax() const
Definition: PDF.h:113
virtual void TestClassification()
initialization
void ReadStateFromStream(std::istream &tf)
read the header from the weight files of the different MVA methods
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
void SetExternalLink(void *p)
Definition: VariableInfo.h:78
Definition: math.cpp:60
double log(double)
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:453
TAxis * GetXaxis()
Definition: TH1.h:319
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
Definition: MethodBase.cxx:827
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39
VariableTransformBase * AddTransformation(VariableTransformBase *, Int_t cls)
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:898