Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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"
50#include "TMVA/DataSetManager.h"
51
52#include <vector>
53#include <map>
54#include <stdexcept>
55#include <string>
56
57namespace TMVA {
58
59 class IMethod;
60 class MethodBase;
61 class DataSetInfo;
62 class MethodCuts;
63
64 class Reader : public Configurable {
65
66 public:
67
68 // without prior specification of variables
69 Reader( const TString& theOption="", Bool_t verbose = 0 );
70
71 // STL types
72 Reader( std::vector<std::string>& varNames, const TString& theOption = "", Bool_t verbose = 0 );
73 Reader( const std::string& varNames, const TString& theOption, Bool_t verbose = 0 ); // format: "var1:var2:..."
74
75 // Root types
76 Reader( std::vector<TString>& varNames, const TString& theOption = "", Bool_t verbose = 0 );
77 Reader( const TString& varNames, const TString& theOption, Bool_t verbose = 0 ); // format: "var1:var2:..."
78
79 virtual ~Reader( void );
80
81 // book MVA method via weight file
82 IMethod* BookMVA( const TString& methodTag, const TString& weightfile );
83 IMethod* BookMVA( TMVA::Types::EMVA methodType, const char* xmlstr );
84 IMethod* FindMVA( const TString& methodTag );
85
86 // returns the MVA response for given event
87 Double_t EvaluateMVA( const std::vector<Float_t> &, const TString& methodTag, Double_t aux = 0 );
88 Double_t EvaluateMVA( const std::vector<Double_t>&, const TString& methodTag, Double_t aux = 0 );
89 Double_t EvaluateMVA( MethodBase* method, Double_t aux = 0 );
90 Double_t EvaluateMVA( const TString& methodTag, Double_t aux = 0 );
91
92 // returns error on MVA response for given event
93 // NOTE: must be called AFTER "EvaluateMVA(...)" call !
97
98 // regression response
99 const std::vector< Float_t >& EvaluateRegression( const TString& methodTag, Double_t aux = 0 );
100 const std::vector< Float_t >& EvaluateRegression( MethodBase* method, Double_t aux = 0 );
101 Float_t EvaluateRegression( UInt_t tgtNumber, const TString& methodTag, Double_t aux = 0 );
102
103 // multiclass response
104 const std::vector< Float_t >& EvaluateMulticlass( const TString& methodTag, Double_t aux = 0 );
105 const std::vector< Float_t >& EvaluateMulticlass( MethodBase* method, Double_t aux = 0 );
106 Float_t EvaluateMulticlass( UInt_t clsNumber, const TString& methodTag, Double_t aux = 0 );
107
108 // probability and rarity accessors (see Users Guide for definition of Rarity)
109 Double_t GetProba ( const TString& methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999 );
110 Double_t GetRarity( const TString& methodTag, Double_t mvaVal=-9999999 );
111
112 // accessors
113 virtual const char* GetName() const { return "Reader"; }
114 Bool_t Verbose( void ) const { return fVerbose; }
115 void SetVerbose( Bool_t v ) { fVerbose = v; }
116
117 const DataSetInfo& DataInfo() const { return fDataSetInfo; }
119
120 void AddVariable( const TString& expression, Float_t* );
121 void AddVariable( const TString& expression, Int_t* );
122
123 void AddSpectator( const TString& expression, Float_t* );
124 void AddSpectator( const TString& expression, Int_t* );
125
126 private:
127
129
130
132
133 // this booking method is internal
134 IMethod* BookMVA( Types::EMVA method, const TString& weightfile );
135
136 DataSetInfo fDataSetInfo; // the data set
137
139
140 // Init Reader class
141 void Init( void );
142
143 // Decode Constructor string (or TString) and fill variable name std::vector
144 void DecodeVarNames( const std::string& varNames );
145 void DecodeVarNames( const TString& varNames );
146
147 void DeclareOptions();
148
149 Bool_t fVerbose; ///< verbosity
150 Bool_t fSilent; ///< silent mode
151 Bool_t fColor; ///< color mode
152 Bool_t fCalculateError; ///< error calculation mode
153
154 Double_t fMvaEventError; ///< per-event error returned by MVA
155 Double_t fMvaEventErrorUpper; ///< per-event error returned by MVA
156
157 std::map<TString, IMethod*> fMethodMap; ///< map of methods
158
159 std::vector<Float_t> fTmpEvalVec; ///< temporary evaluation vector (if user input is v<double>)
160
161 mutable MsgLogger* fLogger; ///< message logger
162 MsgLogger& Log() const { return *fLogger; }
163
164 ClassDef(Reader,0); // Interpret the trained MVAs in an analysis context
165 };
166
167}
168
169#endif
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:337
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Class that contains all the data information.
Class that contains all the data information.
Definition DataSetInfo.h:62
Class that contains all the data information.
Interface for all concrete MVA method implementations.
Definition IMethod.h:53
Virtual base Class for all MVA method.
Definition MethodBase.h:111
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
The Reader class serves to use the MVAs in a specific analysis context.
Definition Reader.h:64
const std::vector< Float_t > & EvaluateRegression(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
Definition Reader.cxx:565
std::map< TString, IMethod * > fMethodMap
map of methods
Definition Reader.h:157
virtual const char * GetName() const
Returns name of object.
Definition Reader.h:113
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:468
Double_t GetRarity(const TString &methodTag, Double_t mvaVal=-9999999)
evaluates the MVA's rarity
Definition Reader.cxx:737
IMethod * FindMVA(const TString &methodTag)
return pointer to method with tag "methodTag"
Definition Reader.cxx:695
void Init(void)
default initialisation (no member variables)
Definition Reader.cxx:292
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:706
Double_t fMvaEventErrorUpper
per-event error returned by MVA
Definition Reader.h:155
void SetVerbose(Bool_t v)
Definition Reader.h:115
TString GetMethodTypeFromFile(const TString &filename)
read the method type from the file
Definition Reader.cxx:337
DataSetManager * fDataSetManager
Definition Reader.h:128
Bool_t fColor
color mode
Definition Reader.h:151
DataSetInfo fDataSetInfo
Definition Reader.h:136
Bool_t fVerbose
verbosity
Definition Reader.h:149
Bool_t fCalculateError
error calculation mode
Definition Reader.h:152
Bool_t Verbose(void) const
Definition Reader.h:114
Double_t fMvaEventError
per-event error returned by MVA
Definition Reader.h:154
std::vector< Float_t > fTmpEvalVec
temporary evaluation vector (if user input is v<double>)
Definition Reader.h:159
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
Definition Reader.cxx:368
const std::vector< Float_t > & EvaluateMulticlass(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
Definition Reader.cxx:630
Double_t GetMVAErrorUpper() const
Definition Reader.h:96
MsgLogger & Log() const
Definition Reader.h:162
Double_t GetMVAErrorLower() const
Definition Reader.h:95
DataSetInfo & DataInfo()
Definition Reader.h:118
DataInputHandler fDataInputHandler
Definition Reader.h:138
void DecodeVarNames(const std::string &varNames)
decodes "name1:name2:..." form
Definition Reader.cxx:772
Bool_t fSilent
silent mode
Definition Reader.h:150
void DeclareOptions()
declaration of configuration options
Definition Reader.cxx:264
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
Definition Reader.cxx:321
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
Definition Reader.cxx:303
virtual ~Reader(void)
destructor
Definition Reader.cxx:277
MsgLogger * fLogger
message logger
Definition Reader.h:161
const DataSetInfo & DataInfo() const
Definition Reader.h:117
Double_t GetMVAError() const
Definition Reader.h:94
Basic string class.
Definition TString.h:139
create variable transformations