ROOT logo
// @(#)root/tmva $Id$
// Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Kai Voss, Eckhard von Toerne, Jan Therhaag

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : MethodBase                                                            *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Virtual base class for all MVA method                                     *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
 *      Peter Speckmayer <peter.speckmayer@cern.ch>  - CERN, Switzerland          *
 *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
 *      Jan Therhaag          <Jan.Therhaag@cern.ch>   - U of Bonn, Germany       *
 *      Eckhard v. Toerne     <evt@uni-bonn.de>        - U of Bonn, Germany       *
 *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
 *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
 *                                                                                *
 * Copyright (c) 2005-2011:                                                       *
 *      CERN, Switzerland                                                         *
 *      U. of Victoria, Canada                                                    *
 *      MPI-K Heidelberg, Germany                                                 *
 *      U. of Bonn, Germany                                                       *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_MethodBase
#define ROOT_TMVA_MethodBase

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MethodBase                                                           //
//                                                                      //
// Virtual base class for all TMVA method                               //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <iosfwd>
#include <vector>
#include <map>
#include "assert.h"

#ifndef ROOT_TString
#include "TString.h"
#endif

#ifndef ROOT_TMVA_IMethod
#include "TMVA/IMethod.h"
#endif
#ifndef ROOT_TMVA_Configurable
#include "TMVA/Configurable.h"
#endif
#ifndef ROOT_TMVA_Types
#include "TMVA/Types.h"
#endif
#ifndef ROOT_TMVA_DataSet
#include "TMVA/DataSet.h"
#endif
#ifndef ROOT_TMVA_Event
#include "TMVA/Event.h"
#endif
#ifndef ROOT_TMVA_TransformationHandler
#include "TMVA/TransformationHandler.h"
#endif
#ifndef ROOT_TMVA_OptimizeConfigParameters
#include "TMVA/OptimizeConfigParameters.h"
#endif

class TGraph;
class TTree;
class TDirectory;
class TSpline;
class TH1F;
class TH1D;

namespace TMVA {

   class Ranking;
   class PDF;
   class TSpline1;
   class MethodCuts;
   class MethodBoost;
   class DataSetInfo;

   class MethodBase : virtual public IMethod, public Configurable {

      friend class Factory;

   public:

      enum EWeightFileType { kROOT=0, kTEXT };

      // default constructur
      MethodBase( const TString& jobName,
                  Types::EMVA methodType,
                  const TString& methodTitle,
                  DataSetInfo& dsi,
                  const TString& theOption = "",
                  TDirectory* theBaseDir = 0 );

      // constructor used for Testing + Application of the MVA, only (no training),
      // using given weight file
      MethodBase( Types::EMVA methodType,
                  DataSetInfo& dsi,
                  const TString& weightFile,
                  TDirectory* theBaseDir = 0 );

      // default destructur
      virtual ~MethodBase();

      // declaration, processing and checking of configuration options
      void             SetupMethod();
      void             ProcessSetup();
      virtual void     CheckSetup(); // may be overwritten by derived classes

      // ---------- main training and testing methods ------------------------------

      // prepare tree branch with the method's discriminating variable
      void             AddOutput( Types::ETreeType type, Types::EAnalysisType analysisType );

      // performs classifier training
      // calls methods Train() implemented by derived classes
      void             TrainMethod();

      // optimize tuning parameters
      virtual std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA");
      virtual void SetTuneParameters(std::map<TString,Double_t> tuneParameters);

      virtual void     Train() = 0;

      // store and retrieve time used for training
      void             SetTrainTime( Double_t trainTime ) { fTrainTime = trainTime; }
      Double_t         GetTrainTime() const { return fTrainTime; }

      // store and retrieve time used for testing
      void             SetTestTime ( Double_t testTime ) { fTestTime = testTime; }
      Double_t         GetTestTime () const { return fTestTime; }

      // performs classifier testing
      virtual void     TestClassification();
      virtual Double_t GetKSTrainingVsTest(Char_t SorB, TString opt="X");

      // performs multiclass classifier testing
      virtual void     TestMulticlass();

      // performs regression testing
      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, // mutual information
                                       Double_t& corr,
                                       Types::ETreeType type );

      // options treatment
      virtual void     Init()           = 0;
      virtual void     DeclareOptions() = 0;
      virtual void     ProcessOptions() = 0;
      virtual void     DeclareCompatibilityOptions(); // declaration of past options

      // reset the Method --> As if it was not yet trained, just instantiated
      //      virtual void     Reset()          = 0;
      //for the moment, I provide a dummy (that would not work) default, just to make
      // compilation/running w/o parameter optimisation still possible
      virtual void     Reset(){return;}

      // classifier response:
      // some methods may return a per-event error estimate
      // error calculation is skipped if err==0
      virtual Double_t GetMvaValue( Double_t* errLower = 0, Double_t* errUpper = 0) = 0;

      // signal/background classification response
      Double_t GetMvaValue( const TMVA::Event* const ev, Double_t* err = 0, Double_t* errUpper = 0 );

   protected:
      // helper function to set errors to -1
      void NoErrorCalc(Double_t* const err, Double_t* const errUpper);

   public:
      // regression response
      const std::vector<Float_t>& GetRegressionValues(const TMVA::Event* const ev){
         fTmpEvent = ev;
         const std::vector<Float_t>* ptr = &GetRegressionValues();
         fTmpEvent = 0;
         return (*ptr);
      }

      virtual const std::vector<Float_t>& GetRegressionValues() {
         std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
         return (*ptr);
      }

      // multiclass classification response
      virtual const std::vector<Float_t>& GetMulticlassValues() {
         std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
         return (*ptr);
      }

      // probability of classifier response (mvaval) to be signal (requires "CreateMvaPdf" option set)
      virtual Double_t GetProba( const Event *ev); // the simple one, automatically calcualtes the mvaVal and uses the SAME sig/bkg ratio as given in the training sample (typically 50/50 .. (NormMode=EqualNumEvents) but can be different) 
      virtual Double_t GetProba( Double_t mvaVal, Double_t ap_sig );

      // Rarity of classifier response (signal or background (default) is uniform in [0,1])
      virtual Double_t GetRarity( Double_t mvaVal, Types::ESBType reftype = Types::kBackground ) const;

      // create ranking
      virtual const Ranking* CreateRanking() = 0;

      // make ROOT-independent C++ class
      virtual void     MakeClass( const TString& classFileName = TString("") ) const;

      // print help message
      void             PrintHelpMessage() const;

      //
      // streamer methods for training information (creates "weight" files) --------
      //
   public:
      void WriteStateToFile     () const;
      void ReadStateFromFile    ();

   protected:
      // the actual "weights"
      virtual void AddWeightsXMLTo      ( void* parent ) const = 0;
      virtual void ReadWeightsFromXML   ( void* wghtnode ) = 0;
      virtual void ReadWeightsFromStream( std::istream& ) = 0;       // backward compatibility
      virtual void ReadWeightsFromStream( TFile& ) {}                // backward compatibility

   private:
      friend class MethodCategory;
      friend class MethodCompositeBase;
      void WriteStateToXML      ( void* parent ) const;
      void ReadStateFromXML     ( void* parent );
      void WriteStateToStream   ( std::ostream& tf ) const;   // needed for MakeClass
      void WriteVarsToStream    ( std::ostream& tf, const TString& prefix = "" ) const;  // needed for MakeClass


   public: // these two need to be public, they are used to read in-memory weight-files
      void ReadStateFromStream  ( std::istream& tf );         // backward compatibility
      void ReadStateFromStream  ( TFile&        rf );         // backward compatibility
      void ReadStateFromXMLString( const char* xmlstr );      // for reading from memory

   private:
      // the variable information
      void AddVarsXMLTo         ( void* parent  ) const;
      void AddSpectatorsXMLTo   ( void* parent  ) const;
      void AddTargetsXMLTo      ( void* parent  ) const;
      void AddClassesXMLTo      ( void* parent  ) const;
      void ReadVariablesFromXML ( void* varnode );
      void ReadSpectatorsFromXML( void* specnode);
      void ReadTargetsFromXML   ( void* tarnode );
      void ReadClassesFromXML   ( void* clsnode );
      void ReadVarsFromStream   ( std::istream& istr );       // backward compatibility

   public:
      // ---------------------------------------------------------------------------

      // write evaluation histograms into target file
      virtual void     WriteEvaluationHistosToFile(Types::ETreeType treetype);

      // write classifier-specific monitoring information to target file
      virtual void     WriteMonitoringHistosToFile() const;

      // ---------- public evaluation methods --------------------------------------

      // individual initialistion for testing of each method
      // overload this one for individual initialisation of the testing,
      // it is then called automatically within the global "TestInit"

      // variables (and private menber functions) for the Evaluation:
      // get the effiency. It fills a histogram for efficiency/vs/bkg
      // and returns the one value fo the efficiency demanded for 
      // in the TString argument. (Watch the string format)
      virtual Double_t GetEfficiency( const TString&, Types::ETreeType, Double_t& err );
      virtual Double_t GetTrainingEfficiency(const TString& );
      virtual std::vector<Float_t> GetMulticlassEfficiency( std::vector<std::vector<Float_t> >& purity );
      virtual std::vector<Float_t> GetMulticlassTrainingEfficiency(std::vector<std::vector<Float_t> >& purity );
      virtual Double_t GetSignificance() const;
      virtual Double_t GetROCIntegral(TH1D *histS, TH1D *histB) const;
      virtual Double_t GetROCIntegral(PDF *pdfS=0, PDF *pdfB=0) const;
      virtual Double_t GetMaximumSignificance( Double_t SignalEvents, Double_t BackgroundEvents, 
                                               Double_t& optimal_significance_value  ) const;
      virtual Double_t GetSeparation( TH1*, TH1* ) const;
      virtual Double_t GetSeparation( PDF* pdfS = 0, PDF* pdfB = 0 ) const;

      virtual void GetRegressionDeviation(UInt_t tgtNum, Types::ETreeType type, Double_t& stddev,Double_t& stddev90Percent ) const;
      // ---------- public accessors -----------------------------------------------

      // classifier naming (a lot of names ... aren't they ;-)
      const TString&   GetJobName       () const { return fJobName; }
      const TString&   GetMethodName    () const { return fMethodName; }
      TString          GetMethodTypeName() const { return Types::Instance().GetMethodName(fMethodType); }
      Types::EMVA      GetMethodType    () const { return fMethodType; }
      const char*      GetName          () const { return fMethodName.Data(); }
      const TString&   GetTestvarName   () const { return fTestvar; }
      const TString    GetProbaName     () const { return fTestvar + "_Proba"; }
      TString          GetWeightFileName() const;

      // build classifier name in Test tree
      // MVA prefix (e.g., "TMVA_")
      void             SetTestvarName  ( const TString & v="" ) { fTestvar = (v=="") ? ("MVA_" + GetMethodName()) : v; }

      // number of input variable used by classifier
      UInt_t           GetNvar()       const { return DataInfo().GetNVariables(); }
      UInt_t           GetNVariables() const { return DataInfo().GetNVariables(); }
      UInt_t           GetNTargets()   const { return DataInfo().GetNTargets(); };

      // internal names and expressions of input variables
      const TString&   GetInputVar  ( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetInternalName(); }
      const TString&   GetInputLabel( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetLabel(); }
      const TString&   GetInputTitle( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetTitle(); }

      // normalisation and limit accessors
      Double_t         GetMean( Int_t ivar ) const { return GetTransformationHandler().GetMean(ivar); }
      Double_t         GetRMS ( Int_t ivar ) const { return GetTransformationHandler().GetRMS(ivar); }
      Double_t         GetXmin( Int_t ivar ) const { return GetTransformationHandler().GetMin(ivar); }
      Double_t         GetXmax( Int_t ivar ) const { return GetTransformationHandler().GetMax(ivar); }

      // sets the minimum requirement on the MVA output to declare an event signal-like
      Double_t         GetSignalReferenceCut() const { return fSignalReferenceCut; }
      Double_t         GetSignalReferenceCutOrientation() const { return fSignalReferenceCutOrientation; }

      // sets the minimum requirement on the MVA output to declare an event signal-like
      void             SetSignalReferenceCut( Double_t cut ) { fSignalReferenceCut = cut; }
      void             SetSignalReferenceCutOrientation( Double_t cutOrientation ) { fSignalReferenceCutOrientation = cutOrientation; }

      // pointers to ROOT directories
      TDirectory*      BaseDir()       const;
      TDirectory*      MethodBaseDir() const;
      void             SetMethodDir ( TDirectory* methodDir ) { fBaseDir = fMethodBaseDir  = methodDir; }
      void             SetBaseDir( TDirectory* methodDir ){ fBaseDir = methodDir; }
      void             SetMethodBaseDir( TDirectory* methodDir ){ fMethodBaseDir = methodDir; }

      // the TMVA version can be obtained and checked using
      //    if (GetTrainingTMVAVersionCode()>TMVA_VERSION(3,7,2)) {...}
      // or
      //    if (GetTrainingROOTVersionCode()>ROOT_VERSION(5,15,5)) {...}
      UInt_t           GetTrainingTMVAVersionCode()   const { return fTMVATrainingVersion; }
      UInt_t           GetTrainingROOTVersionCode()   const { return fROOTTrainingVersion; }
      TString          GetTrainingTMVAVersionString() const;
      TString          GetTrainingROOTVersionString() const;

      TransformationHandler&        GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
      {
         if(fTransformationPointer && takeReroutedIfAvailable) return *fTransformationPointer; else return fTransformation;
      }
      const TransformationHandler&  GetTransformationHandler(Bool_t takeReroutedIfAvailable=true) const
      {
         if(fTransformationPointer && takeReroutedIfAvailable) return *fTransformationPointer; else return fTransformation;
      }

      void             RerouteTransformationHandler (TransformationHandler* fTargetTransformation) { fTransformationPointer=fTargetTransformation; }

      // ---------- event accessors ------------------------------------------------

      // returns reference to data set
      // NOTE: this DataSet is the "original" dataset, i.e. the one seen by ALL Classifiers WITHOUT transformation
      DataSet* Data() const { return DataInfo().GetDataSet(); }
      DataSetInfo&     DataInfo() const { return fDataSetInfo; }

      mutable const Event*   fTmpEvent; //! temporary event when testing on a different DataSet than the own one

      // event reference and update
      // NOTE: these Event accessors make sure that you get the events transformed according to the 
      //        particular clasifiers transformation chosen
      UInt_t           GetNEvents      () const { return Data()->GetNEvents(); }
      const Event*     GetEvent        () const;
      const Event*     GetEvent        ( const TMVA::Event* ev ) const;
      const Event*     GetEvent        ( Long64_t ievt ) const;
      const Event*     GetEvent        ( Long64_t ievt , Types::ETreeType type ) const;
      const Event*     GetTrainingEvent( Long64_t ievt ) const;
      const Event*     GetTestingEvent ( Long64_t ievt ) const;
      const std::vector<TMVA::Event*>& GetEventCollection( Types::ETreeType type );

      // ---------- public auxiliary methods ---------------------------------------

      // this method is used to decide whether an event is signal- or background-like
      // the reference cut "xC" is taken to be where
      // Int_[-oo,xC] { PDF_S(x) dx } = Int_[xC,+oo] { PDF_B(x) dx }
      virtual Bool_t        IsSignalLike();
      virtual Bool_t        IsSignalLike(Double_t mvaVal);


      Bool_t                HasMVAPdfs() const { return fHasMVAPdfs; }
      virtual void          SetAnalysisType( Types::EAnalysisType type ) { fAnalysisType = type; }
      Types::EAnalysisType  GetAnalysisType() const { return fAnalysisType; }
      Bool_t                DoRegression() const { return fAnalysisType == Types::kRegression; }
      Bool_t                DoMulticlass() const { return fAnalysisType == Types::kMulticlass; }

      // setter method for suppressing writing to XML and writing of standalone classes
      void                  DisableWriting(Bool_t setter){ fDisableWriting = setter; }

   protected:

      // ---------- protected acccessors -------------------------------------------

      //TDirectory*  LocalTDir() const { return Data().LocalRootDir(); }

      // weight file name and directory (given by global config variable)
      void             SetWeightFileName( TString );

      const TString&   GetWeightFileDir() const { return fFileDir; }
      void             SetWeightFileDir( TString fileDir );

      // are input variables normalised ?
      Bool_t           IsNormalised() const { return fNormalise; }
      void             SetNormalised( Bool_t norm ) { fNormalise = norm; }

      // set number of input variables (only used by MethodCuts, could perhaps be removed)
      //      void SetNvar( Int_t n ) { fNvar = n; }

      // verbose and help flags
      Bool_t           Verbose() const { return fVerbose; }
      Bool_t           Help   () const { return fHelp; }

      // ---------- protected event and tree accessors -----------------------------

      // names of input variables (if the original names are expressions, they are
      // transformed into regexps)
      const TString&   GetInternalVarName( Int_t ivar ) const { return (*fInputVars)[ivar]; }
      const TString&   GetOriginalVarName( Int_t ivar ) const { return DataInfo().GetVariableInfo(ivar).GetExpression(); }

      Bool_t           HasTrainingTree() const { return Data()->GetNTrainingEvents() != 0; }

      // ---------- protected auxiliary methods ------------------------------------

   protected:

      // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
      virtual void     MakeClassSpecific( std::ostream&, const TString& = "" ) const {}

      // header and auxiliary classes
      virtual void     MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const {}

      // static pointer to this object - required for ROOT finder (to be solved differently)
      static MethodBase* GetThisBase();

      // some basic statistical analysis
      void Statistics( Types::ETreeType treeType, const TString& theVarName,
                       Double_t&, Double_t&, Double_t&,
                       Double_t&, Double_t&, Double_t& );

      // if TRUE, write weights only to text files
      Bool_t           TxtWeightsOnly() const { return kTRUE; }

   protected:

      // access to event information that needs method-specific information

      Bool_t           IsConstructedFromWeightFile() const { return fConstructedFromWeightFile; }


   private:

      // ---------- private definitions --------------------------------------------
      // Initialisation
      void             InitBase();
      void             DeclareBaseOptions();
      void             ProcessBaseOptions();

      // used in efficiency computation
      enum ECutOrientation { kNegative = -1, kPositive = +1 };
      ECutOrientation  GetCutOrientation() const { return fCutOrientation; }

      // ---------- private acccessors ---------------------------------------------

      // reset required for RootFinder
      void             ResetThisBase();

      // ---------- private auxiliary methods --------------------------------------

      // PDFs for classifier response (required to compute signal probability and Rarity)
      void             CreateMVAPdfs();

      // for root finder
      static Double_t  IGetEffForRoot( Double_t );  // interface
      Double_t         GetEffForRoot ( Double_t );  // implementation

      // used for file parsing
      Bool_t           GetLine( std::istream& fin, char * buf );

      // fill test tree with classification or regression results
      virtual void     AddClassifierOutput    ( Types::ETreeType type );
      virtual void     AddClassifierOutputProb( Types::ETreeType type );
      virtual void     AddRegressionOutput    ( Types::ETreeType type );
      virtual void     AddMulticlassOutput    ( Types::ETreeType type );

   private:

      void             AddInfoItem( void* gi, const TString& name,
                                    const TString& value) const;

      static void      CreateVariableTransforms(const TString& trafoDefinition,
                                                TMVA::DataSetInfo& dataInfo,
                                                TMVA::TransformationHandler& transformationHandler,
                                                TMVA::MsgLogger& log );


      // ========== class members ==================================================

   protected:

      // direct accessors
      Ranking*              fRanking;              // pointer to ranking object (created by derived classifiers)
      std::vector<TString>* fInputVars;            // vector of input variables used in MVA

      // histogram binning
      Int_t                 fNbins;                // number of bins in input variable histograms
      Int_t                 fNbinsMVAoutput;       // number of bins in MVA output histograms
      Int_t                 fNbinsH;               // number of bins in evaluation histograms

      Types::EAnalysisType  fAnalysisType;         // method-mode : true --> regression, false --> classification

      std::vector<Float_t>* fRegressionReturnVal;  // holds the return-values for the regression
      std::vector<Float_t>* fMulticlassReturnVal;  // holds the return-values for the multiclass classification

   private:

      // MethodCuts redefines some of the evaluation variables and histograms -> must access private members
      friend class MethodCuts;

      Bool_t           fDisableWriting;       //! set to true in order to suppress writing to XML

      // data sets
      DataSetInfo&     fDataSetInfo;         //! the data set information (sometimes needed)

      Double_t         fSignalReferenceCut;  // minimum requirement on the MVA output to declare an event signal-like
      Double_t         fSignalReferenceCutOrientation;  // minimum requirement on the MVA output to declare an event signal-like
      Types::ESBType   fVariableTransformType;  // this is the event type (sig or bgd) assumed for variable transform

      // naming and versioning
      TString          fJobName;             // name of job -> user defined, appears in weight files
      TString          fMethodName;          // name of the method (set in derived class)
      Types::EMVA      fMethodType;          // type of method (set in derived class)
      TString          fTestvar;             // variable used in evaluation, etc (mostly the MVA)
      UInt_t           fTMVATrainingVersion; // TMVA version used for training
      UInt_t           fROOTTrainingVersion; // ROOT version used for training
      Bool_t           fConstructedFromWeightFile; // is it obtained from weight file?

      // Directory structure: fMethodBaseDir/fBaseDir
      // where the first directory name is defined by the method type
      // and the second is user supplied (the title given in Factory::BookMethod())
      TDirectory*      fBaseDir;             // base directory for the instance, needed to know where to jump back from localDir
      mutable TDirectory* fMethodBaseDir;    // base directory for the method

      TString          fParentDir;           // method parent name, like booster name

      TString          fFileDir;             // unix sub-directory for weight files (default: "weights")
      TString          fWeightFile;          // weight file name

   private:

      TH1*             fEffS;                // efficiency histogram for rootfinder

      PDF*             fDefaultPDF;          // default PDF definitions
      PDF*             fMVAPdfS;             // signal MVA PDF
      PDF*             fMVAPdfB;             // background MVA PDF

      //      TH1D*            fmvaS;                // PDFs of MVA distribution (signal)
      //      TH1D*            fmvaB;                // PDFs of MVA distribution (background)
      PDF*             fSplS;                // PDFs of MVA distribution (signal)
      PDF*             fSplB;                // PDFs of MVA distribution (background)
      TSpline*         fSpleffBvsS;          // splines for signal eff. versus background eff.

      PDF*             fSplTrainS;           // PDFs of training MVA distribution (signal)
      PDF*             fSplTrainB;           // PDFs of training MVA distribution (background)
      TSpline*         fSplTrainEffBvsS;     // splines for training signal eff. versus background eff.

   private:

      // basic statistics quantities of MVA
      Double_t         fMeanS;               // mean (signal)
      Double_t         fMeanB;               // mean (background)
      Double_t         fRmsS;                // RMS (signal)
      Double_t         fRmsB;                // RMS (background)
      Double_t         fXmin;                // minimum (signal and background)
      Double_t         fXmax;                // maximum (signal and background)

      // variable preprocessing
      TString          fVarTransformString;          // labels variable transform method

      TransformationHandler* fTransformationPointer;  // pointer to the rest of transformations
      TransformationHandler  fTransformation;         // the list of transformations


      // help and verbosity
      Bool_t           fVerbose;               // verbose flag
      TString          fVerbosityLevelString;  // verbosity level (user input string)
      EMsgType         fVerbosityLevel;        // verbosity level
      Bool_t           fHelp;                  // help flag
      Bool_t           fHasMVAPdfs;            // MVA Pdfs are created for this classifier

      Bool_t           fIgnoreNegWeightsInTraining;// If true, events with negative weights are not used in training

   protected:

      Bool_t           IgnoreEventsWithNegWeightsInTraining() const { return fIgnoreNegWeightsInTraining; }

      // for signal/background
      UInt_t           fSignalClass;           // index of the Signal-class
      UInt_t           fBackgroundClass;       // index of the Background-class

   private:

      // timing variables
      Double_t         fTrainTime;             // for timing measurements
      Double_t         fTestTime;              // for timing measurements

      // orientation of cut: depends on signal and background mean values
      ECutOrientation  fCutOrientation;      // +1 if Sig>Bkg, -1 otherwise

      // for root finder
      TSpline1*        fSplRefS;             // helper splines for RootFinder (signal)
      TSpline1*        fSplRefB;             // helper splines for RootFinder (background)

      TSpline1*        fSplTrainRefS;        // helper splines for RootFinder (signal)
      TSpline1*        fSplTrainRefB;        // helper splines for RootFinder (background)

      mutable std::vector<const std::vector<TMVA::Event*>*> fEventCollections; // if the method needs the complete event-collection, the transformed event coll. ist stored here.

   public:
      Bool_t           fSetupCompleted;      // is method setup

   private:

      // this carrier
      static MethodBase* fgThisBase;         // this pointer


      // ===== depreciated options, kept for backward compatibility  =====
   private:

      Bool_t           fNormalise;                   // normalise input variables
      Bool_t           fUseDecorr;                   // synonymous for decorrelation
      TString          fVariableTransformTypeString; // labels variable transform type
      Bool_t           fTxtWeightsOnly;              // if TRUE, write weights only to text files 
      Int_t            fNbinsMVAPdf;                 // number of bins used in histogram that creates PDF
      Int_t            fNsmoothMVAPdf;               // number of times a histogram is smoothed before creating the PDF

   protected:

      ClassDef(MethodBase,0)  // Virtual base class for all TMVA method

   };
} // namespace TMVA







// ========== INLINE FUNCTIONS =========================================================


//_______________________________________________________________________
inline const TMVA::Event* TMVA::MethodBase::GetEvent( const TMVA::Event* ev ) const 
{
   return GetTransformationHandler().Transform(ev);
}

inline const TMVA::Event* TMVA::MethodBase::GetEvent() const 
{
   if(fTmpEvent)
      return GetTransformationHandler().Transform(fTmpEvent);
   else
      return GetTransformationHandler().Transform(Data()->GetEvent());
}

inline const TMVA::Event* TMVA::MethodBase::GetEvent( Long64_t ievt ) const 
{
   assert(fTmpEvent==0);
   return GetTransformationHandler().Transform(Data()->GetEvent(ievt));
}

inline const TMVA::Event* TMVA::MethodBase::GetEvent( Long64_t ievt, Types::ETreeType type ) const 
{
   assert(fTmpEvent==0);
   return GetTransformationHandler().Transform(Data()->GetEvent(ievt, type));
}

inline const TMVA::Event* TMVA::MethodBase::GetTrainingEvent( Long64_t ievt ) const 
{
   assert(fTmpEvent==0);
   return GetEvent(ievt, Types::kTraining);
}

inline const TMVA::Event* TMVA::MethodBase::GetTestingEvent( Long64_t ievt ) const 
{
   assert(fTmpEvent==0);
   return GetEvent(ievt, Types::kTesting);
}

#endif
 MethodBase.h:1
 MethodBase.h:2
 MethodBase.h:3
 MethodBase.h:4
 MethodBase.h:5
 MethodBase.h:6
 MethodBase.h:7
 MethodBase.h:8
 MethodBase.h:9
 MethodBase.h:10
 MethodBase.h:11
 MethodBase.h:12
 MethodBase.h:13
 MethodBase.h:14
 MethodBase.h:15
 MethodBase.h:16
 MethodBase.h:17
 MethodBase.h:18
 MethodBase.h:19
 MethodBase.h:20
 MethodBase.h:21
 MethodBase.h:22
 MethodBase.h:23
 MethodBase.h:24
 MethodBase.h:25
 MethodBase.h:26
 MethodBase.h:27
 MethodBase.h:28
 MethodBase.h:29
 MethodBase.h:30
 MethodBase.h:31
 MethodBase.h:32
 MethodBase.h:33
 MethodBase.h:34
 MethodBase.h:35
 MethodBase.h:36
 MethodBase.h:37
 MethodBase.h:38
 MethodBase.h:39
 MethodBase.h:40
 MethodBase.h:41
 MethodBase.h:42
 MethodBase.h:43
 MethodBase.h:44
 MethodBase.h:45
 MethodBase.h:46
 MethodBase.h:47
 MethodBase.h:48
 MethodBase.h:49
 MethodBase.h:50
 MethodBase.h:51
 MethodBase.h:52
 MethodBase.h:53
 MethodBase.h:54
 MethodBase.h:55
 MethodBase.h:56
 MethodBase.h:57
 MethodBase.h:58
 MethodBase.h:59
 MethodBase.h:60
 MethodBase.h:61
 MethodBase.h:62
 MethodBase.h:63
 MethodBase.h:64
 MethodBase.h:65
 MethodBase.h:66
 MethodBase.h:67
 MethodBase.h:68
 MethodBase.h:69
 MethodBase.h:70
 MethodBase.h:71
 MethodBase.h:72
 MethodBase.h:73
 MethodBase.h:74
 MethodBase.h:75
 MethodBase.h:76
 MethodBase.h:77
 MethodBase.h:78
 MethodBase.h:79
 MethodBase.h:80
 MethodBase.h:81
 MethodBase.h:82
 MethodBase.h:83
 MethodBase.h:84
 MethodBase.h:85
 MethodBase.h:86
 MethodBase.h:87
 MethodBase.h:88
 MethodBase.h:89
 MethodBase.h:90
 MethodBase.h:91
 MethodBase.h:92
 MethodBase.h:93
 MethodBase.h:94
 MethodBase.h:95
 MethodBase.h:96
 MethodBase.h:97
 MethodBase.h:98
 MethodBase.h:99
 MethodBase.h:100
 MethodBase.h:101
 MethodBase.h:102
 MethodBase.h:103
 MethodBase.h:104
 MethodBase.h:105
 MethodBase.h:106
 MethodBase.h:107
 MethodBase.h:108
 MethodBase.h:109
 MethodBase.h:110
 MethodBase.h:111
 MethodBase.h:112
 MethodBase.h:113
 MethodBase.h:114
 MethodBase.h:115
 MethodBase.h:116
 MethodBase.h:117
 MethodBase.h:118
 MethodBase.h:119
 MethodBase.h:120
 MethodBase.h:121
 MethodBase.h:122
 MethodBase.h:123
 MethodBase.h:124
 MethodBase.h:125
 MethodBase.h:126
 MethodBase.h:127
 MethodBase.h:128
 MethodBase.h:129
 MethodBase.h:130
 MethodBase.h:131
 MethodBase.h:132
 MethodBase.h:133
 MethodBase.h:134
 MethodBase.h:135
 MethodBase.h:136
 MethodBase.h:137
 MethodBase.h:138
 MethodBase.h:139
 MethodBase.h:140
 MethodBase.h:141
 MethodBase.h:142
 MethodBase.h:143
 MethodBase.h:144
 MethodBase.h:145
 MethodBase.h:146
 MethodBase.h:147
 MethodBase.h:148
 MethodBase.h:149
 MethodBase.h:150
 MethodBase.h:151
 MethodBase.h:152
 MethodBase.h:153
 MethodBase.h:154
 MethodBase.h:155
 MethodBase.h:156
 MethodBase.h:157
 MethodBase.h:158
 MethodBase.h:159
 MethodBase.h:160
 MethodBase.h:161
 MethodBase.h:162
 MethodBase.h:163
 MethodBase.h:164
 MethodBase.h:165
 MethodBase.h:166
 MethodBase.h:167
 MethodBase.h:168
 MethodBase.h:169
 MethodBase.h:170
 MethodBase.h:171
 MethodBase.h:172
 MethodBase.h:173
 MethodBase.h:174
 MethodBase.h:175
 MethodBase.h:176
 MethodBase.h:177
 MethodBase.h:178
 MethodBase.h:179
 MethodBase.h:180
 MethodBase.h:181
 MethodBase.h:182
 MethodBase.h:183
 MethodBase.h:184
 MethodBase.h:185
 MethodBase.h:186
 MethodBase.h:187
 MethodBase.h:188
 MethodBase.h:189
 MethodBase.h:190
 MethodBase.h:191
 MethodBase.h:192
 MethodBase.h:193
 MethodBase.h:194
 MethodBase.h:195
 MethodBase.h:196
 MethodBase.h:197
 MethodBase.h:198
 MethodBase.h:199
 MethodBase.h:200
 MethodBase.h:201
 MethodBase.h:202
 MethodBase.h:203
 MethodBase.h:204
 MethodBase.h:205
 MethodBase.h:206
 MethodBase.h:207
 MethodBase.h:208
 MethodBase.h:209
 MethodBase.h:210
 MethodBase.h:211
 MethodBase.h:212
 MethodBase.h:213
 MethodBase.h:214
 MethodBase.h:215
 MethodBase.h:216
 MethodBase.h:217
 MethodBase.h:218
 MethodBase.h:219
 MethodBase.h:220
 MethodBase.h:221
 MethodBase.h:222
 MethodBase.h:223
 MethodBase.h:224
 MethodBase.h:225
 MethodBase.h:226
 MethodBase.h:227
 MethodBase.h:228
 MethodBase.h:229
 MethodBase.h:230
 MethodBase.h:231
 MethodBase.h:232
 MethodBase.h:233
 MethodBase.h:234
 MethodBase.h:235
 MethodBase.h:236
 MethodBase.h:237
 MethodBase.h:238
 MethodBase.h:239
 MethodBase.h:240
 MethodBase.h:241
 MethodBase.h:242
 MethodBase.h:243
 MethodBase.h:244
 MethodBase.h:245
 MethodBase.h:246
 MethodBase.h:247
 MethodBase.h:248
 MethodBase.h:249
 MethodBase.h:250
 MethodBase.h:251
 MethodBase.h:252
 MethodBase.h:253
 MethodBase.h:254
 MethodBase.h:255
 MethodBase.h:256
 MethodBase.h:257
 MethodBase.h:258
 MethodBase.h:259
 MethodBase.h:260
 MethodBase.h:261
 MethodBase.h:262
 MethodBase.h:263
 MethodBase.h:264
 MethodBase.h:265
 MethodBase.h:266
 MethodBase.h:267
 MethodBase.h:268
 MethodBase.h:269
 MethodBase.h:270
 MethodBase.h:271
 MethodBase.h:272
 MethodBase.h:273
 MethodBase.h:274
 MethodBase.h:275
 MethodBase.h:276
 MethodBase.h:277
 MethodBase.h:278
 MethodBase.h:279
 MethodBase.h:280
 MethodBase.h:281
 MethodBase.h:282
 MethodBase.h:283
 MethodBase.h:284
 MethodBase.h:285
 MethodBase.h:286
 MethodBase.h:287
 MethodBase.h:288
 MethodBase.h:289
 MethodBase.h:290
 MethodBase.h:291
 MethodBase.h:292
 MethodBase.h:293
 MethodBase.h:294
 MethodBase.h:295
 MethodBase.h:296
 MethodBase.h:297
 MethodBase.h:298
 MethodBase.h:299
 MethodBase.h:300
 MethodBase.h:301
 MethodBase.h:302
 MethodBase.h:303
 MethodBase.h:304
 MethodBase.h:305
 MethodBase.h:306
 MethodBase.h:307
 MethodBase.h:308
 MethodBase.h:309
 MethodBase.h:310
 MethodBase.h:311
 MethodBase.h:312
 MethodBase.h:313
 MethodBase.h:314
 MethodBase.h:315
 MethodBase.h:316
 MethodBase.h:317
 MethodBase.h:318
 MethodBase.h:319
 MethodBase.h:320
 MethodBase.h:321
 MethodBase.h:322
 MethodBase.h:323
 MethodBase.h:324
 MethodBase.h:325
 MethodBase.h:326
 MethodBase.h:327
 MethodBase.h:328
 MethodBase.h:329
 MethodBase.h:330
 MethodBase.h:331
 MethodBase.h:332
 MethodBase.h:333
 MethodBase.h:334
 MethodBase.h:335
 MethodBase.h:336
 MethodBase.h:337
 MethodBase.h:338
 MethodBase.h:339
 MethodBase.h:340
 MethodBase.h:341
 MethodBase.h:342
 MethodBase.h:343
 MethodBase.h:344
 MethodBase.h:345
 MethodBase.h:346
 MethodBase.h:347
 MethodBase.h:348
 MethodBase.h:349
 MethodBase.h:350
 MethodBase.h:351
 MethodBase.h:352
 MethodBase.h:353
 MethodBase.h:354
 MethodBase.h:355
 MethodBase.h:356
 MethodBase.h:357
 MethodBase.h:358
 MethodBase.h:359
 MethodBase.h:360
 MethodBase.h:361
 MethodBase.h:362
 MethodBase.h:363
 MethodBase.h:364
 MethodBase.h:365
 MethodBase.h:366
 MethodBase.h:367
 MethodBase.h:368
 MethodBase.h:369
 MethodBase.h:370
 MethodBase.h:371
 MethodBase.h:372
 MethodBase.h:373
 MethodBase.h:374
 MethodBase.h:375
 MethodBase.h:376
 MethodBase.h:377
 MethodBase.h:378
 MethodBase.h:379
 MethodBase.h:380
 MethodBase.h:381
 MethodBase.h:382
 MethodBase.h:383
 MethodBase.h:384
 MethodBase.h:385
 MethodBase.h:386
 MethodBase.h:387
 MethodBase.h:388
 MethodBase.h:389
 MethodBase.h:390
 MethodBase.h:391
 MethodBase.h:392
 MethodBase.h:393
 MethodBase.h:394
 MethodBase.h:395
 MethodBase.h:396
 MethodBase.h:397
 MethodBase.h:398
 MethodBase.h:399
 MethodBase.h:400
 MethodBase.h:401
 MethodBase.h:402
 MethodBase.h:403
 MethodBase.h:404
 MethodBase.h:405
 MethodBase.h:406
 MethodBase.h:407
 MethodBase.h:408
 MethodBase.h:409
 MethodBase.h:410
 MethodBase.h:411
 MethodBase.h:412
 MethodBase.h:413
 MethodBase.h:414
 MethodBase.h:415
 MethodBase.h:416
 MethodBase.h:417
 MethodBase.h:418
 MethodBase.h:419
 MethodBase.h:420
 MethodBase.h:421
 MethodBase.h:422
 MethodBase.h:423
 MethodBase.h:424
 MethodBase.h:425
 MethodBase.h:426
 MethodBase.h:427
 MethodBase.h:428
 MethodBase.h:429
 MethodBase.h:430
 MethodBase.h:431
 MethodBase.h:432
 MethodBase.h:433
 MethodBase.h:434
 MethodBase.h:435
 MethodBase.h:436
 MethodBase.h:437
 MethodBase.h:438
 MethodBase.h:439
 MethodBase.h:440
 MethodBase.h:441
 MethodBase.h:442
 MethodBase.h:443
 MethodBase.h:444
 MethodBase.h:445
 MethodBase.h:446
 MethodBase.h:447
 MethodBase.h:448
 MethodBase.h:449
 MethodBase.h:450
 MethodBase.h:451
 MethodBase.h:452
 MethodBase.h:453
 MethodBase.h:454
 MethodBase.h:455
 MethodBase.h:456
 MethodBase.h:457
 MethodBase.h:458
 MethodBase.h:459
 MethodBase.h:460
 MethodBase.h:461
 MethodBase.h:462
 MethodBase.h:463
 MethodBase.h:464
 MethodBase.h:465
 MethodBase.h:466
 MethodBase.h:467
 MethodBase.h:468
 MethodBase.h:469
 MethodBase.h:470
 MethodBase.h:471
 MethodBase.h:472
 MethodBase.h:473
 MethodBase.h:474
 MethodBase.h:475
 MethodBase.h:476
 MethodBase.h:477
 MethodBase.h:478
 MethodBase.h:479
 MethodBase.h:480
 MethodBase.h:481
 MethodBase.h:482
 MethodBase.h:483
 MethodBase.h:484
 MethodBase.h:485
 MethodBase.h:486
 MethodBase.h:487
 MethodBase.h:488
 MethodBase.h:489
 MethodBase.h:490
 MethodBase.h:491
 MethodBase.h:492
 MethodBase.h:493
 MethodBase.h:494
 MethodBase.h:495
 MethodBase.h:496
 MethodBase.h:497
 MethodBase.h:498
 MethodBase.h:499
 MethodBase.h:500
 MethodBase.h:501
 MethodBase.h:502
 MethodBase.h:503
 MethodBase.h:504
 MethodBase.h:505
 MethodBase.h:506
 MethodBase.h:507
 MethodBase.h:508
 MethodBase.h:509
 MethodBase.h:510
 MethodBase.h:511
 MethodBase.h:512
 MethodBase.h:513
 MethodBase.h:514
 MethodBase.h:515
 MethodBase.h:516
 MethodBase.h:517
 MethodBase.h:518
 MethodBase.h:519
 MethodBase.h:520
 MethodBase.h:521
 MethodBase.h:522
 MethodBase.h:523
 MethodBase.h:524
 MethodBase.h:525
 MethodBase.h:526
 MethodBase.h:527
 MethodBase.h:528
 MethodBase.h:529
 MethodBase.h:530
 MethodBase.h:531
 MethodBase.h:532
 MethodBase.h:533
 MethodBase.h:534
 MethodBase.h:535
 MethodBase.h:536
 MethodBase.h:537
 MethodBase.h:538
 MethodBase.h:539
 MethodBase.h:540
 MethodBase.h:541
 MethodBase.h:542
 MethodBase.h:543
 MethodBase.h:544
 MethodBase.h:545
 MethodBase.h:546
 MethodBase.h:547
 MethodBase.h:548
 MethodBase.h:549
 MethodBase.h:550
 MethodBase.h:551
 MethodBase.h:552
 MethodBase.h:553
 MethodBase.h:554
 MethodBase.h:555
 MethodBase.h:556
 MethodBase.h:557
 MethodBase.h:558
 MethodBase.h:559
 MethodBase.h:560
 MethodBase.h:561
 MethodBase.h:562
 MethodBase.h:563
 MethodBase.h:564
 MethodBase.h:565
 MethodBase.h:566
 MethodBase.h:567
 MethodBase.h:568
 MethodBase.h:569
 MethodBase.h:570
 MethodBase.h:571
 MethodBase.h:572
 MethodBase.h:573
 MethodBase.h:574
 MethodBase.h:575
 MethodBase.h:576
 MethodBase.h:577
 MethodBase.h:578
 MethodBase.h:579
 MethodBase.h:580
 MethodBase.h:581
 MethodBase.h:582
 MethodBase.h:583
 MethodBase.h:584
 MethodBase.h:585
 MethodBase.h:586
 MethodBase.h:587
 MethodBase.h:588
 MethodBase.h:589
 MethodBase.h:590
 MethodBase.h:591
 MethodBase.h:592
 MethodBase.h:593
 MethodBase.h:594
 MethodBase.h:595
 MethodBase.h:596
 MethodBase.h:597
 MethodBase.h:598
 MethodBase.h:599
 MethodBase.h:600
 MethodBase.h:601
 MethodBase.h:602
 MethodBase.h:603
 MethodBase.h:604
 MethodBase.h:605
 MethodBase.h:606
 MethodBase.h:607
 MethodBase.h:608
 MethodBase.h:609
 MethodBase.h:610
 MethodBase.h:611
 MethodBase.h:612
 MethodBase.h:613
 MethodBase.h:614
 MethodBase.h:615
 MethodBase.h:616
 MethodBase.h:617
 MethodBase.h:618
 MethodBase.h:619
 MethodBase.h:620
 MethodBase.h:621
 MethodBase.h:622
 MethodBase.h:623
 MethodBase.h:624
 MethodBase.h:625
 MethodBase.h:626
 MethodBase.h:627
 MethodBase.h:628
 MethodBase.h:629
 MethodBase.h:630
 MethodBase.h:631
 MethodBase.h:632
 MethodBase.h:633
 MethodBase.h:634
 MethodBase.h:635
 MethodBase.h:636
 MethodBase.h:637
 MethodBase.h:638
 MethodBase.h:639
 MethodBase.h:640
 MethodBase.h:641
 MethodBase.h:642
 MethodBase.h:643
 MethodBase.h:644
 MethodBase.h:645
 MethodBase.h:646
 MethodBase.h:647
 MethodBase.h:648
 MethodBase.h:649
 MethodBase.h:650
 MethodBase.h:651
 MethodBase.h:652
 MethodBase.h:653
 MethodBase.h:654
 MethodBase.h:655
 MethodBase.h:656
 MethodBase.h:657
 MethodBase.h:658
 MethodBase.h:659
 MethodBase.h:660
 MethodBase.h:661
 MethodBase.h:662
 MethodBase.h:663
 MethodBase.h:664
 MethodBase.h:665
 MethodBase.h:666
 MethodBase.h:667
 MethodBase.h:668
 MethodBase.h:669
 MethodBase.h:670
 MethodBase.h:671
 MethodBase.h:672
 MethodBase.h:673
 MethodBase.h:674
 MethodBase.h:675
 MethodBase.h:676
 MethodBase.h:677
 MethodBase.h:678
 MethodBase.h:679
 MethodBase.h:680
 MethodBase.h:681
 MethodBase.h:682
 MethodBase.h:683
 MethodBase.h:684
 MethodBase.h:685
 MethodBase.h:686
 MethodBase.h:687
 MethodBase.h:688
 MethodBase.h:689
 MethodBase.h:690
 MethodBase.h:691
 MethodBase.h:692
 MethodBase.h:693
 MethodBase.h:694
 MethodBase.h:695
 MethodBase.h:696
 MethodBase.h:697
 MethodBase.h:698
 MethodBase.h:699