Reader.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: Reader.h 36966 2010-11-26 09:50:13Z evt $
00002 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Kai Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : Reader                                                                *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Reader class to be used in the user application to interpret the trained  *
00012  *      MVAs in an analysis context                                               *
00013  *                                                                                *
00014  * Authors (alphabetical order):                                                  *
00015  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00016  *      Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland           *
00017  *      Joerg Stelzer <Joerg.Stelzer@cern.ch>    - CERN, Switzerland              *
00018  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00019  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00020  *                                                                                *
00021  * Copyright (c) 2005:                                                            *
00022  *      CERN, Switzerland                                                         *
00023  *      U. of Victoria, Canada                                                    *
00024  *      MPI-K Heidelberg, Germany                                                 *
00025  *                                                                                *
00026  * Redistribution and use in source and binary forms, with or without             *
00027  * modification, are permitted according to the terms listed in LICENSE           *
00028  * (http://ttmva.sourceforge.net/LICENSE)                                         *
00029  **********************************************************************************/
00030 
00031 #ifndef ROOT_TMVA_Reader
00032 #define ROOT_TMVA_Reader
00033 
00034 //////////////////////////////////////////////////////////////////////////
00035 //                                                                      //
00036 // Reader                                                               //
00037 //                                                                      //
00038 // Reader class to be used in the user application to interpret the     //
00039 // trained MVAs in an analysis context                                  //
00040 //                                                                      //
00041 //////////////////////////////////////////////////////////////////////////
00042 
00043 #ifndef ROOT_TMVA_Configurable
00044 #include "TMVA/Configurable.h"
00045 #endif
00046 #ifndef ROOT_TMVA_Types
00047 #include "TMVA/Types.h"
00048 #endif
00049 #ifndef ROOT_TMVA_DataSetInfo
00050 #include "TMVA/DataSetInfo.h"
00051 #endif
00052 #ifndef ROOT_TMVA_DataInputHandler
00053 #include "TMVA/DataInputHandler.h"
00054 #endif
00055 #ifndef ROOT_TMVA_DataSetManager
00056 #include "TMVA/DataSetManager.h"
00057 #endif
00058 
00059 #include <vector>
00060 #include <map>
00061 #include <stdexcept>
00062 
00063 namespace TMVA {
00064 
00065    class IMethod;
00066    class MethodBase;
00067    class DataSetInfo;
00068    class MethodCuts;
00069 
00070    class Reader : public Configurable {
00071 
00072    public:
00073 
00074       // without prior specification of variables
00075       Reader( const TString& theOption="", Bool_t verbose = 0 );
00076 
00077       // STL types
00078       Reader( std::vector<std::string>& varNames, const TString& theOption = "", Bool_t verbose = 0 );
00079       Reader( const std::string& varNames, const TString& theOption, Bool_t verbose = 0 );  // format: "var1:var2:..."
00080 
00081       // Root types
00082       Reader( std::vector<TString>& varNames, const TString& theOption = "", Bool_t verbose = 0 );
00083       Reader( const TString& varNames, const TString& theOption, Bool_t verbose = 0 );  // format: "var1:var2:..."
00084 
00085       virtual ~Reader( void );
00086 
00087       // book MVA method via weight file
00088       IMethod* BookMVA( const TString& methodTag, const TString& weightfile );
00089       IMethod* BookMVA( TMVA::Types::EMVA methodType, const char* xmlstr );
00090       IMethod* FindMVA( const TString& methodTag );
00091       // special function for Cuts to avoid dynamic_casts in ROOT macros,
00092       // which are not properly handled by CINT
00093       MethodCuts* FindCutsMVA( const TString& methodTag );
00094 
00095 
00096       // returns the MVA response for given event
00097       Double_t EvaluateMVA( const std::vector<Float_t> &, const TString& methodTag, Double_t aux = 0 );
00098       Double_t EvaluateMVA( const std::vector<Double_t>&, const TString& methodTag, Double_t aux = 0 );
00099       Double_t EvaluateMVA( MethodBase* method,           Double_t aux = 0 );
00100       Double_t EvaluateMVA( const TString& methodTag,     Double_t aux = 0 );
00101 
00102       // returns error on MVA response for given event
00103       // NOTE: must be called AFTER "EvaluateMVA(...)" call !
00104       Double_t GetMVAError() const { return fMvaEventError; }
00105       Double_t GetMVAErrorLower() const { return fMvaEventError; }
00106       Double_t GetMVAErrorUpper() const { return fMvaEventErrorUpper; }
00107 
00108       // regression response
00109       const std::vector< Float_t >& EvaluateRegression( const TString& methodTag, Double_t aux = 0 );
00110       const std::vector< Float_t >& EvaluateRegression( MethodBase* method, Double_t aux = 0 );
00111       Float_t  EvaluateRegression( UInt_t tgtNumber, const TString& methodTag, Double_t aux = 0 );
00112 
00113       // multiclass response
00114       const std::vector< Float_t >& EvaluateMulticlass( const TString& methodTag, Double_t aux = 0 );
00115       const std::vector< Float_t >& EvaluateMulticlass( MethodBase* method, Double_t aux = 0 );
00116       Float_t  EvaluateMulticlass( UInt_t clsNumber, const TString& methodTag, Double_t aux = 0 );
00117 
00118       // probability and rarity accessors (see Users Guide for definition of Rarity)
00119       Double_t GetProba ( const TString& methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999 );
00120       Double_t GetRarity( const TString& methodTag, Double_t mvaVal=-9999999 );
00121 
00122       // accessors
00123       virtual const char* GetName() const { return "Reader"; }
00124       Bool_t   Verbose( void ) const  { return fVerbose; }
00125       void     SetVerbose( Bool_t v ) { fVerbose = v; }
00126 
00127       const DataSetInfo& DataInfo() const { return fDataSetInfo; }
00128       DataSetInfo&       DataInfo()       { return fDataSetInfo; }
00129 
00130       void     AddVariable( const TString& expression, Float_t* );
00131       void     AddVariable( const TString& expression, Int_t* );
00132 
00133       void     AddSpectator( const TString& expression, Float_t* );
00134       void     AddSpectator( const TString& expression, Int_t* );
00135 
00136    private:
00137 
00138       DataSetManager* fDataSetManager; // DSMTEST
00139 
00140 
00141       TString GetMethodTypeFromFile( const TString& filename );
00142 
00143       // this booking method is internal
00144       IMethod* BookMVA( Types::EMVA method,  const TString& weightfile );
00145 
00146       DataSetInfo fDataSetInfo; // the data set
00147 
00148       DataInputHandler fDataInputHandler;
00149 
00150       // Init Reader class
00151       void Init( void );
00152 
00153       // Decode Constructor string (or TString) and fill variable name std::vector
00154       void DecodeVarNames( const std::string& varNames );
00155       void DecodeVarNames( const TString& varNames );
00156 
00157       void DeclareOptions();
00158 
00159       Bool_t    fVerbose;            // verbosity
00160       Bool_t    fSilent;             // silent mode
00161       Bool_t    fColor;              // color mode
00162       Bool_t    fCalculateError;     // error calculation mode
00163 
00164       Double_t  fMvaEventError;      // per-event error returned by MVA
00165       Double_t  fMvaEventErrorUpper; // per-event error returned by MVA
00166 
00167       std::map<TString, IMethod*> fMethodMap; // map of methods
00168 
00169       std::vector<Float_t> fTmpEvalVec; // temporary evaluation vector (if user input is v<double>)
00170 
00171       mutable MsgLogger* fLogger;   // message logger
00172       MsgLogger& Log() const { return *fLogger; }
00173 
00174       ClassDef(Reader,0) // Interpret the trained MVAs in an analysis context
00175    };
00176 
00177 }
00178 
00179 #endif

Generated on Tue Jul 5 14:27:33 2011 for ROOT_528-00b_version by  doxygen 1.5.1