Logo ROOT   6.21/01
Reference Guide
Reader.h
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 : Reader *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Reader class to be used in the user application to interpret the trained *
12  * MVAs in an analysis context *
13  * *
14  * Authors (alphabetical order): *
15  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
16  * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland *
17  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
18  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
19  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
20  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
21  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
22  * *
23  * Copyright (c) 2005-2011: *
24  * CERN, Switzerland *
25  * U. of Victoria, Canada *
26  * MPI-K Heidelberg, Germany *
27  * U. of Bonn, Germany *
28  * *
29  * Redistribution and use in source and binary forms, with or without *
30  * modification, are permitted according to the terms listed in LICENSE *
31  * (http://tmva.sourceforge.net/LICENSE) *
32  **********************************************************************************/
33 
34 #ifndef ROOT_TMVA_Reader
35 #define ROOT_TMVA_Reader
36 
37 //////////////////////////////////////////////////////////////////////////
38 // //
39 // Reader //
40 // //
41 // Reader class to be used in the user application to interpret the //
42 // trained MVAs in an analysis context //
43 // //
44 //////////////////////////////////////////////////////////////////////////
45 
46 #include "TMVA/Configurable.h"
47 #include "TMVA/Types.h"
48 #include "TMVA/DataSetInfo.h"
49 #include "TMVA/DataInputHandler.h"
50 #include "TMVA/DataSetManager.h"
51 
52 #include <vector>
53 #include <map>
54 #include <stdexcept>
55 
56 namespace TMVA {
57 
58  class IMethod;
59  class MethodBase;
60  class DataSetInfo;
61  class MethodCuts;
62 
63  class Reader : public Configurable {
64 
65  public:
66 
67  // without prior specification of variables
68  Reader( const TString& theOption="", Bool_t verbose = 0 );
69 
70  // STL types
71  Reader( std::vector<std::string>& varNames, const TString& theOption = "", Bool_t verbose = 0 );
72  Reader( const std::string& varNames, const TString& theOption, Bool_t verbose = 0 ); // format: "var1:var2:..."
73 
74  // Root types
75  Reader( std::vector<TString>& varNames, const TString& theOption = "", Bool_t verbose = 0 );
76  Reader( const TString& varNames, const TString& theOption, Bool_t verbose = 0 ); // format: "var1:var2:..."
77 
78  virtual ~Reader( void );
79 
80  // book MVA method via weight file
81  IMethod* BookMVA( const TString& methodTag, const TString& weightfile );
82  IMethod* BookMVA( TMVA::Types::EMVA methodType, const char* xmlstr );
83  IMethod* FindMVA( const TString& methodTag );
84  // special function for Cuts to avoid dynamic_casts in ROOT macros,
85  // which are not properly handled by CINT
86  MethodCuts* FindCutsMVA( const TString& methodTag );
87 
88 
89  // returns the MVA response for given event
90  Double_t EvaluateMVA( const std::vector<Float_t> &, const TString& methodTag, Double_t aux = 0 );
91  Double_t EvaluateMVA( const std::vector<Double_t>&, const TString& methodTag, Double_t aux = 0 );
92  Double_t EvaluateMVA( MethodBase* method, Double_t aux = 0 );
93  Double_t EvaluateMVA( const TString& methodTag, Double_t aux = 0 );
94 
95  // returns error on MVA response for given event
96  // NOTE: must be called AFTER "EvaluateMVA(...)" call !
97  Double_t GetMVAError() const { return fMvaEventError; }
100 
101  // regression response
102  const std::vector< Float_t >& EvaluateRegression( const TString& methodTag, Double_t aux = 0 );
103  const std::vector< Float_t >& EvaluateRegression( MethodBase* method, Double_t aux = 0 );
104  Float_t EvaluateRegression( UInt_t tgtNumber, const TString& methodTag, Double_t aux = 0 );
105 
106  // multiclass response
107  const std::vector< Float_t >& EvaluateMulticlass( const TString& methodTag, Double_t aux = 0 );
108  const std::vector< Float_t >& EvaluateMulticlass( MethodBase* method, Double_t aux = 0 );
109  Float_t EvaluateMulticlass( UInt_t clsNumber, const TString& methodTag, Double_t aux = 0 );
110 
111  // probability and rarity accessors (see Users Guide for definition of Rarity)
112  Double_t GetProba ( const TString& methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999 );
113  Double_t GetRarity( const TString& methodTag, Double_t mvaVal=-9999999 );
114 
115  // accessors
116  virtual const char* GetName() const { return "Reader"; }
117  Bool_t Verbose( void ) const { return fVerbose; }
118  void SetVerbose( Bool_t v ) { fVerbose = v; }
119 
120  const DataSetInfo& DataInfo() const { return fDataSetInfo; }
122 
123  void AddVariable( const TString& expression, Float_t* );
124  void AddVariable( const TString& expression, Int_t* );
125 
126  void AddSpectator( const TString& expression, Float_t* );
127  void AddSpectator( const TString& expression, Int_t* );
128 
129  private:
130 
132 
133 
134  TString GetMethodTypeFromFile( const TString& filename );
135 
136  // this booking method is internal
137  IMethod* BookMVA( Types::EMVA method, const TString& weightfile );
138 
139  DataSetInfo fDataSetInfo; // the data set
140 
142 
143  // Init Reader class
144  void Init( void );
145 
146  // Decode Constructor string (or TString) and fill variable name std::vector
147  void DecodeVarNames( const std::string& varNames );
148  void DecodeVarNames( const TString& varNames );
149 
150  void DeclareOptions();
151 
152  Bool_t fVerbose; // verbosity
153  Bool_t fSilent; // silent mode
154  Bool_t fColor; // color mode
155  Bool_t fCalculateError; // error calculation mode
156 
157  Double_t fMvaEventError; // per-event error returned by MVA
158  Double_t fMvaEventErrorUpper; // per-event error returned by MVA
159 
160  std::map<TString, IMethod*> fMethodMap; // map of methods
161 
162  std::vector<Float_t> fTmpEvalVec; // temporary evaluation vector (if user input is v<double>)
163 
164  mutable MsgLogger* fLogger; // message logger
165  MsgLogger& Log() const { return *fLogger; }
166 
167  ClassDef(Reader,0); // Interpret the trained MVAs in an analysis context
168  };
169 
170 }
171 
172 #endif
void SetVerbose(Bool_t v)
Definition: Reader.h:118
MsgLogger * fLogger
Definition: Reader.h:164
std::map< TString, IMethod * > fMethodMap
Definition: Reader.h:160
virtual ~Reader(void)
destructor
Definition: Reader.cxx:282
float Float_t
Definition: RtypesCore.h:53
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
Definition: Reader.cxx:308
Bool_t fCalculateError
Definition: Reader.h:155
Double_t fMvaEventErrorUpper
Definition: Reader.h:158
const std::vector< Float_t > & EvaluateRegression(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
Definition: Reader.cxx:570
Virtual base Class for all MVA method.
Definition: MethodBase.h:111
virtual const char * GetName() const
Returns name of object.
Definition: Reader.h:116
Double_t GetRarity(const TString &methodTag, Double_t mvaVal=-9999999)
evaluates the MVA&#39;s rarity
Definition: Reader.cxx:751
Basic string class.
Definition: TString.h:131
DataSetInfo & DataInfo()
Definition: Reader.h:121
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t GetMVAError() const
Definition: Reader.h:97
Bool_t fSilent
Definition: Reader.h:153
void DecodeVarNames(const std::string &varNames)
decodes "name1:name2:..." form
Definition: Reader.cxx:786
TString GetMethodTypeFromFile(const TString &filename)
read the method type from the file
Definition: Reader.cxx:342
#define ClassDef(name, id)
Definition: Rtypes.h:326
DataInputHandler fDataInputHandler
Definition: Reader.h:141
Double_t GetMVAErrorUpper() const
Definition: Reader.h:99
void DeclareOptions()
declaration of configuration options
Definition: Reader.cxx:269
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
Definition: Reader.cxx:373
Double_t GetMVAErrorLower() const
Definition: Reader.h:98
Class that contains all the data information.
Definition: DataSetInfo.h:60
DataSetManager * fDataSetManager
Definition: Reader.h:131
std::vector< Float_t > fTmpEvalVec
Definition: Reader.h:162
Class that contains all the data information.
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t Verbose(void) const
Definition: Reader.h:117
Double_t fMvaEventError
Definition: Reader.h:157
Reader(const TString &theOption="", Bool_t verbose=0)
constructor
Definition: Reader.cxx:128
Bool_t fVerbose
Definition: Reader.h:152
Bool_t fColor
Definition: Reader.h:154
Multivariate optimisation of signal efficiency for given background efficiency, applying rectangular ...
Definition: MethodCuts.h:61
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
Definition: Reader.cxx:326
double Double_t
Definition: RtypesCore.h:55
Class that contains all the data information.
DataSetInfo fDataSetInfo
Definition: Reader.h:139
MsgLogger & Log() const
Definition: Reader.h:165
Double_t EvaluateMVA(const std::vector< Float_t > &, const TString &methodTag, Double_t aux=0)
Evaluate a std::vector<float> of input data for a given method The parameter aux is obligatory for th...
Definition: Reader.cxx:473
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
void Init(void)
default initialisation (no member variables)
Definition: Reader.cxx:297
Interface for all concrete MVA method implementations.
Definition: IMethod.h:54
The Reader class serves to use the MVAs in a specific analysis context.
Definition: Reader.h:63
create variable transformations
IMethod * FindMVA(const TString &methodTag)
return pointer to method with tag "methodTag"
Definition: Reader.cxx:700
const DataSetInfo & DataInfo() const
Definition: Reader.h:120
Double_t GetProba(const TString &methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999)
evaluates probability of MVA for given set of input variables
Definition: Reader.cxx:720
const std::vector< Float_t > & EvaluateMulticlass(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
Definition: Reader.cxx:635
MethodCuts * FindCutsMVA(const TString &methodTag)
special function for Cuts to avoid dynamic_casts in ROOT macros, which are not properly handled by CI...
Definition: Reader.cxx:712