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 * 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"
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 // special function for Cuts to avoid dynamic_casts in ROOT macros,
86 // which are not properly handled by CINT
87 MethodCuts* FindCutsMVA( const TString& methodTag );
88
89
90 // returns the MVA response for given event
91 Double_t EvaluateMVA( const std::vector<Float_t> &, const TString& methodTag, Double_t aux = 0 );
92 Double_t EvaluateMVA( const std::vector<Double_t>&, const TString& methodTag, Double_t aux = 0 );
93 Double_t EvaluateMVA( MethodBase* method, Double_t aux = 0 );
94 Double_t EvaluateMVA( const TString& methodTag, Double_t aux = 0 );
95
96 // returns error on MVA response for given event
97 // NOTE: must be called AFTER "EvaluateMVA(...)" call !
101
102 // regression response
103 const std::vector< Float_t >& EvaluateRegression( const TString& methodTag, Double_t aux = 0 );
104 const std::vector< Float_t >& EvaluateRegression( MethodBase* method, Double_t aux = 0 );
105 Float_t EvaluateRegression( UInt_t tgtNumber, const TString& methodTag, Double_t aux = 0 );
106
107 // multiclass response
108 const std::vector< Float_t >& EvaluateMulticlass( const TString& methodTag, Double_t aux = 0 );
109 const std::vector< Float_t >& EvaluateMulticlass( MethodBase* method, Double_t aux = 0 );
110 Float_t EvaluateMulticlass( UInt_t clsNumber, const TString& methodTag, Double_t aux = 0 );
111
112 // probability and rarity accessors (see Users Guide for definition of Rarity)
113 Double_t GetProba ( const TString& methodTag, Double_t ap_sig=0.5, Double_t mvaVal=-9999999 );
114 Double_t GetRarity( const TString& methodTag, Double_t mvaVal=-9999999 );
115
116 // accessors
117 virtual const char* GetName() const { return "Reader"; }
118 Bool_t Verbose( void ) const { return fVerbose; }
119 void SetVerbose( Bool_t v ) { fVerbose = v; }
120
121 const DataSetInfo& DataInfo() const { return fDataSetInfo; }
123
124 void AddVariable( const TString& expression, Float_t* );
125 void AddVariable( const TString& expression, Int_t* );
126
127 void AddSpectator( const TString& expression, Float_t* );
128 void AddSpectator( const TString& expression, Int_t* );
129
130 private:
131
133
134
135 TString GetMethodTypeFromFile( const TString& filename );
136
137 // this booking method is internal
138 IMethod* BookMVA( Types::EMVA method, const TString& weightfile );
139
140 DataSetInfo fDataSetInfo; // the data set
141
143
144 // Init Reader class
145 void Init( void );
146
147 // Decode Constructor string (or TString) and fill variable name std::vector
148 void DecodeVarNames( const std::string& varNames );
149 void DecodeVarNames( const TString& varNames );
150
151 void DeclareOptions();
152
153 Bool_t fVerbose; // verbosity
154 Bool_t fSilent; // silent mode
155 Bool_t fColor; // color mode
156 Bool_t fCalculateError; // error calculation mode
157
158 Double_t fMvaEventError; // per-event error returned by MVA
159 Double_t fMvaEventErrorUpper; // per-event error returned by MVA
160
161 std::map<TString, IMethod*> fMethodMap; // map of methods
162
163 std::vector<Float_t> fTmpEvalVec; // temporary evaluation vector (if user input is v<double>)
164
165 mutable MsgLogger* fLogger; // message logger
166 MsgLogger& Log() const { return *fLogger; }
167
168 ClassDef(Reader,0); // Interpret the trained MVAs in an analysis context
169 };
170
171}
172
173#endif
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
#define ClassDef(name, id)
Definition Rtypes.h:325
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
Multivariate optimisation of signal efficiency for given background efficiency, applying rectangular ...
Definition MethodCuts.h:61
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
Definition Reader.h:161
virtual const char * GetName() const
Returns name of object.
Definition Reader.h:117
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:746
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:715
Double_t fMvaEventErrorUpper
Definition Reader.h:159
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:707
void SetVerbose(Bool_t v)
Definition Reader.h:119
TString GetMethodTypeFromFile(const TString &filename)
read the method type from the file
Definition Reader.cxx:337
DataSetManager * fDataSetManager
Definition Reader.h:132
Bool_t fColor
Definition Reader.h:155
DataSetInfo fDataSetInfo
Definition Reader.h:140
Bool_t fVerbose
Definition Reader.h:153
Bool_t fCalculateError
Definition Reader.h:156
Bool_t Verbose(void) const
Definition Reader.h:118
Double_t fMvaEventError
Definition Reader.h:158
std::vector< Float_t > fTmpEvalVec
Definition Reader.h:163
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:100
MsgLogger & Log() const
Definition Reader.h:166
Double_t GetMVAErrorLower() const
Definition Reader.h:99
DataSetInfo & DataInfo()
Definition Reader.h:122
DataInputHandler fDataInputHandler
Definition Reader.h:142
void DecodeVarNames(const std::string &varNames)
decodes "name1:name2:..." form
Definition Reader.cxx:781
Bool_t fSilent
Definition Reader.h:154
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
Definition Reader.h:165
const DataSetInfo & DataInfo() const
Definition Reader.h:121
Double_t GetMVAError() const
Definition Reader.h:98
Basic string class.
Definition TString.h:136
create variable transformations