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