Logo ROOT  
Reference Guide
RooFactoryWSTool.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROO_FACTORY_WS_TOOL
18#define ROO_FACTORY_WS_TOOL
19
20#include "RooArgSet.h"
21#include "RooArgList.h"
22#include <string>
23#include <vector>
24#include <stack>
25
26class RooAbsReal ;
27class RooAbsRealLValue ;
28class RooAbsPdf ;
29class RooWorkspace ;
30class RooRealVar ;
31class RooCategory ;
32class RooAddPdf ;
33class RooProdPdf ;
34class RooSimultaneous ;
35class RooDataHist ;
36class RooDataSet ;
37class RooAbsData ;
38class RooFactoryWSToolSpec ;
40class RooAbsCategory ;
42class RooAddition ;
43class RooProduct ;
44class RooRealSumPdf ;
45
46class RooFactoryWSTool : public TNamed, public RooPrintable {
47
48public:
49
50 // Constructors, assignment etc
52 virtual ~RooFactoryWSTool() ;
53
54 // --- low level factory interface ---
55
56 // Create variables
58 RooCategory* createCategory(const char* name, const char* stateNameList=0) ;
59
60 // Create functions and p.d.f.s (any RooAbsArg)
61 RooAbsArg* createArg(const char* className, const char* objName, const char* varList) ;
62
63 // Create operator p.d.f.s
64 RooAddPdf* add(const char *objName, const char* specList, Bool_t recursiveCoefs=kFALSE) ;
65 RooRealSumPdf* amplAdd(const char *objName, const char* specList) ;
66 RooProdPdf* prod(const char *objName, const char* pdfList) ;
67 RooSimultaneous* simul(const char* objName, const char* indexCat, const char* pdfMap) ;
68
69 // Create operator functions
70 RooAddition* addfunc(const char *objName, const char* specList) ;
71 RooProduct* prodfunc(const char *objName, const char* pdfList) ;
72
73 RooWorkspace& ws() { return *_ws ; }
74
75 // --- High level factory interface ---
76
77 // Composite object construction language parser
78 RooAbsArg* process(const char* expr) ;
79 std::string processExpression(const char* expr) ;
80 std::vector<std::string> splitFunctionArgs(const char* funcExpr) ;
81
82
83 // --- Internal stuff that must be public so that CINT can access it ---
84
85 // CINT constructor interface
86 static RooAbsArg& as_ARG(UInt_t idx) { checkIndex(idx) ; return of()->of()->asARG(of()->_args[idx].c_str()) ; }
87
88 static RooAbsPdf& as_PDF(UInt_t idx) { checkIndex(idx) ; return of()->asPDF(of()->_args[idx].c_str()) ; }
89 static RooAbsReal& as_FUNC(UInt_t idx) { checkIndex(idx) ; return of()->asFUNC(of()->_args[idx].c_str()) ; }
90 static RooRealVar& as_VAR(UInt_t idx) { checkIndex(idx) ; return of()->asVAR(of()->_args[idx].c_str()) ; }
91 static RooAbsRealLValue& as_VARLV(UInt_t idx) { checkIndex(idx) ; return of()->asVARLV(of()->_args[idx].c_str()) ; }
92 static RooResolutionModel& as_RMODEL(UInt_t idx) { checkIndex(idx) ; return of()->asRMODEL(of()->_args[idx].c_str()) ; }
93
94 static RooCategory& as_CAT(UInt_t idx) { checkIndex(idx) ; return of()->asCAT(of()->_args[idx].c_str()) ; }
95 static RooAbsCategoryLValue& as_CATLV(UInt_t idx) { checkIndex(idx) ; return of()->asCATLV(of()->_args[idx].c_str()) ; }
96 static RooAbsCategory& as_CATFUNC(UInt_t idx) { checkIndex(idx) ; return of()->asCATFUNC(of()->_args[idx].c_str()) ; }
97
98 static RooArgSet as_SET(UInt_t idx) { checkIndex(idx) ; return of()->asSET(of()->_args[idx].c_str()) ; }
99 static RooArgList as_LIST(UInt_t idx) { checkIndex(idx) ; return of()->asLIST(of()->_args[idx].c_str()) ; }
100
101 static RooAbsData& as_DATA(UInt_t idx) { checkIndex(idx) ; return of()->asDATA(of()->_args[idx].c_str()) ; }
102 static RooDataHist& as_DHIST(UInt_t idx) { checkIndex(idx) ; return of()->asDHIST(of()->_args[idx].c_str()) ; }
103 static RooDataSet& as_DSET(UInt_t idx) { checkIndex(idx) ; return of()->asDSET(of()->_args[idx].c_str()) ; }
104
105 static TObject& as_OBJ(UInt_t idx) { checkIndex(idx) ; return of()->asOBJ(of()->_args[idx].c_str()) ; }
106
107 static const char* as_STRING(UInt_t idx) { checkIndex(idx) ; return of()->asSTRING(of()->_args[idx].c_str()) ; }
108 static Int_t as_INT(UInt_t idx) { checkIndex(idx) ; return of()->asINT(of()->_args[idx].c_str()) ; }
109 static Double_t as_DOUBLE(UInt_t idx) { checkIndex(idx) ; return of()->asDOUBLE(of()->_args[idx].c_str()) ; }
110 static Int_t as_INT(UInt_t idx, Int_t defVal) { checkIndex(idx) ; if (idx>of()->_args.size()-1) return defVal ; return of()->asINT(of()->_args[idx].c_str()) ; }
111 static Double_t as_DOUBLE(UInt_t idx, Double_t defVal) { checkIndex(idx) ; if (idx>of()->_args.size()-1) return defVal ; return of()->asDOUBLE(of()->_args[idx].c_str()) ; }
112
113 RooAbsArg& asARG(const char*) ;
114
115 RooAbsPdf& asPDF(const char*) ;
116 RooAbsReal& asFUNC(const char*) ;
117 RooRealVar& asVAR(const char*) ;
118 RooAbsRealLValue& asVARLV(const char*) ;
119 RooResolutionModel& asRMODEL(const char*) ;
120
121 RooCategory& asCAT(const char*) ;
122 RooAbsCategoryLValue& asCATLV(const char*) ;
123 RooAbsCategory& asCATFUNC(const char*) ;
124
125 RooArgSet asSET(const char*) ;
126 RooArgList asLIST(const char*) ;
127
128 RooAbsData& asDATA(const char*) ;
129 RooDataHist& asDHIST(const char*) ;
130 RooDataSet& asDSET(const char*) ;
131
132 TObject& asOBJ(const char*) ;
133
134 const char* asSTRING(const char*) ;
135 Int_t asINT(const char*) ;
136 Double_t asDOUBLE(const char*) ;
137
138 class IFace {
139 public:
140 virtual ~IFace() {} ;
141 virtual std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) = 0 ;
142 } ;
143
144 class SpecialsIFace : public IFace {
145 public:
146 virtual ~SpecialsIFace() {} ;
147 std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) ;
148 } ;
149
150 static void registerSpecial(const char* typeName, RooFactoryWSTool::IFace* iface) ;
151
152 void logError() { _errorCount++ ; }
153
154 const char* autoClassNamePostFix() const { return _autoClassPostFix.c_str() ; }
155 void setAutoClassNamePostFix(const char* pfix) { _autoClassPostFix = pfix ; }
156
157protected:
158
159 Bool_t checkSyntax(const char* arg) ;
160
161 std::string varTag(std::string& func, std::vector<std::string>& args) ;
162
163 std::stack<std::string> _autoNamePrefix ;
164 std::map<std::string,std::string> _typeAliases ;
165
166 static void checkIndex(UInt_t index) ;
167
168
169 std::string processCompositeExpression(const char* arg) ;
170 std::string processSingleExpression(const char* arg) ;
171 std::string processListExpression(const char* arg) ;
172 std::string processAliasExpression(const char* arg) ;
173
174 std::string processCreateVar(std::string& func, std::vector<std::string>& args) ;
175 std::string processCreateArg(std::string& func, std::vector<std::string>& args) ;
176 std::string processMetaArg(std::string& func, std::vector<std::string>& args) ;
177
178 TClass* resolveClassName(const char* className) ;
179
180 // CINT constructor interface back end
181 static RooFactoryWSTool* of() ;
183 std::vector<std::string> _args ;
184
185 // Hooks for other tools
186 static std::map<std::string,IFace*>& hooks() ;
187 static std::map<std::string,IFace*>* _hooks ;
188
189 RooWorkspace* _ws ; //! Associated workspace
190
191 void clearError() { _errorCount = 0 ; }
193
194 Int_t _errorCount ; // Error counter for a given expression processing
195
196 std::string _autoClassPostFix ;
197
199
200 ClassDef(RooFactoryWSTool,0) // RooFit class code and instance factory
201
202} ;
203
204
205
206#endif
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
#define ClassDef(name, id)
Definition: Rtypes.h:322
char name[80]
Definition: TGX11.cxx:109
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:44
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
Definition: RooAddition.h:26
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:23
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
virtual std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)=0
std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)
Concatenate list of args into comma separated string.
RooFactoryWSTool is a class similar to TTree::MakeClass() that generates skeleton code for RooAbsPdf ...
RooWorkspace & ws()
const char * autoClassNamePostFix() const
void setAutoClassNamePostFix(const char *pfix)
static RooAbsReal & as_FUNC(UInt_t idx)
RooWorkspace * _ws
RooAbsArg & asARG(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsArg reference found in w...
RooFactoryWSTool(const RooFactoryWSTool &)
std::string _autoClassPostFix
RooAbsArg * process(const char *expr)
Create a RooFit object from the given expression.
RooCategory & asCAT(const char *)
CINT constructor interface, return constructor string argument #idx as RooCategory reference found in...
static void checkIndex(UInt_t index)
static RooFactoryWSTool * of()
static RooAbsArg & as_ARG(UInt_t idx)
static RooAbsRealLValue & as_VARLV(UInt_t idx)
RooRealVar * createVariable(const char *name, Double_t xmin, Double_t xmax)
Low-level factory interface for creating a RooRealVar with a given range and initial value.
RooAbsPdf & asPDF(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsPdf reference found in w...
RooDataSet & asDSET(const char *)
CINT constructor interface, return constructor string argument #idx as RooDataSet object found in wor...
std::string processListExpression(const char *arg)
Process a list of high-level expression.
RooRealVar & asVAR(const char *)
CINT constructor interface, return constructor string argument #idx as RooRealVar reference found in ...
static void registerSpecial(const char *typeName, RooFactoryWSTool::IFace *iface)
Register foreign special objects in factory.
std::string processExpression(const char *expr)
Process a single high-level expression or list of expressions.
Double_t asDOUBLE(const char *)
CINT constructor interface, return constructor string argument #idx as Double_t.
static Int_t as_INT(UInt_t idx, Int_t defVal)
static RooFactoryWSTool * _of
static TObject & as_OBJ(UInt_t idx)
std::string processAliasExpression(const char *arg)
Parse token.
RooAbsRealLValue & asVARLV(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsRealLValue reference fou...
static RooAbsCategoryLValue & as_CATLV(UInt_t idx)
Int_t asINT(const char *)
CINT constructor interface, return constructor string argument #idx as Int_t.
RooAddition * addfunc(const char *objName, const char *specList)
static RooDataHist & as_DHIST(UInt_t idx)
RooAbsData & asDATA(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsData object found in wor...
RooAbsArg * createArg(const char *className, const char *objName, const char *varList)
Low-level factory interface for creating a RooAbsPdf of a given class with a given list of input vari...
std::string processCreateArg(std::string &func, std::vector< std::string > &args)
Glue function between high-level syntax and low-level factory call to createArg: Process a parsed cal...
static RooResolutionModel & as_RMODEL(UInt_t idx)
static const char * as_STRING(UInt_t idx)
RooFactoryWSTool(RooWorkspace &ws)
static RooAbsData & as_DATA(UInt_t idx)
static std::map< std::string, IFace * > & hooks()
void clearError()
Associated workspace.
std::string varTag(std::string &func, std::vector< std::string > &args)
static RooArgList as_LIST(UInt_t idx)
static RooDataSet & as_DSET(UInt_t idx)
RooResolutionModel & asRMODEL(const char *)
CINT constructor interface, return constructor string argument #idx as RooResolutionModel reference f...
std::string processMetaArg(std::string &func, std::vector< std::string > &args)
Concatenate list of args into comma separated string.
static std::map< std::string, IFace * > * _hooks
static Double_t as_DOUBLE(UInt_t idx, Double_t defVal)
TObject & asOBJ(const char *)
RooArgList asLIST(const char *)
CINT constructor interface, return constructor string argument #idx as RooArgList of objects found in...
RooSimultaneous * simul(const char *objName, const char *indexCat, const char *pdfMap)
static RooArgSet as_SET(UInt_t idx)
RooAddPdf * add(const char *objName, const char *specList, Bool_t recursiveCoefs=kFALSE)
static RooAbsCategory & as_CATFUNC(UInt_t idx)
std::string processCompositeExpression(const char *arg)
Process a single composite expression.
TClass * resolveClassName(const char *className)
RooAbsCategory & asCATFUNC(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsCategory reference found...
RooCategory * createCategory(const char *name, const char *stateNameList=0)
Low-level factory interface for creating a RooCategory with a given list of state names.
const char * asSTRING(const char *)
CINT constructor interface, return constructor string argument #idx as const char*.
static RooAbsPdf & as_PDF(UInt_t idx)
RooProdPdf * prod(const char *objName, const char *pdfList)
std::vector< std::string > _args
RooRealSumPdf * amplAdd(const char *objName, const char *specList)
virtual ~RooFactoryWSTool()
Destructor.
Bool_t checkSyntax(const char *arg)
Perform basic syntax on given factory expression.
std::stack< std::string > _autoNamePrefix
RooDataHist & asDHIST(const char *)
CINT constructor interface, return constructor string argument #idx as RooDataHist object found in wo...
RooProduct * prodfunc(const char *objName, const char *pdfList)
RooAbsReal & asFUNC(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsReal reference found in ...
RooAbsCategoryLValue & asCATLV(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsCategoryLValue reference...
static RooCategory & as_CAT(UInt_t idx)
static Int_t as_INT(UInt_t idx)
std::string processSingleExpression(const char *arg)
Process a single high-level expression.
std::vector< std::string > splitFunctionArgs(const char *funcExpr)
Allocate and fill work buffer.
static RooRealVar & as_VAR(UInt_t idx)
static Double_t as_DOUBLE(UInt_t idx)
std::map< std::string, std::string > _typeAliases
RooArgSet asSET(const char *)
CINT constructor interface, return constructor string argument #idx as RooArgSet of objects found in ...
std::string processCreateVar(std::string &func, std::vector< std::string > &args)
Glue function between high-level syntax and low-level factory call to createVariable: Process a parse...
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:30
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
Definition: RooRealSumPdf.h:24
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37