ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <list>
24 #include <vector>
25 #include <stack>
26 
27 class RooAbsReal ;
28 class RooAbsRealLValue ;
29 class RooAbsPdf ;
30 class RooWorkspace ;
31 class RooRealVar ;
32 class RooCategory ;
33 class RooAddPdf ;
34 class RooProdPdf ;
35 class RooSimultaneous ;
36 class RooDataHist ;
37 class RooDataSet ;
38 class RooAbsData ;
39 class RooFactoryWSToolSpec ;
41 class RooAbsCategory ;
42 class RooResolutionModel ;
43 class RooAddition ;
44 class RooProduct ;
45 class RooRealSumPdf ;
46 
47 class RooFactoryWSTool : public TNamed, public RooPrintable {
48 
49 public:
50 
51  // Constructors, assignment etc
53  virtual ~RooFactoryWSTool() ;
54 
55  // --- low level factory interface ---
56 
57  // Create variables
59  RooCategory* createCategory(const char* name, const char* stateNameList=0) ;
60 
61  // Create functions and p.d.f.s (any RooAbsArg)
62  RooAbsArg* createArg(const char* className, const char* objName, const char* varList) ;
63  std::vector<std::string> ctorArgs(const char* className) ;
64 
65  // Create operator p.d.f.s
66  RooAddPdf* add(const char *objName, const char* specList, Bool_t recursiveCoefs=kFALSE) ;
67  RooRealSumPdf* amplAdd(const char *objName, const char* specList) ;
68  RooProdPdf* prod(const char *objName, const char* pdfList) ;
69  RooSimultaneous* simul(const char* objName, const char* indexCat, const char* pdfMap) ;
70 
71  // Create operator functions
72  RooAddition* addfunc(const char *objName, const char* specList) ;
73  RooProduct* prodfunc(const char *objName, const char* pdfList) ;
74 
75  RooWorkspace& ws() { return *_ws ; }
76 
77  // --- High level factory interface ---
78 
79  // Composite object construction language parser
80  RooAbsArg* process(const char* expr) ;
81  std::string processExpression(const char* expr) ;
82  std::vector<std::string> splitFunctionArgs(const char* funcExpr) ;
83 
84 
85  // --- Internal stuff that must be public so that CINT can access it ---
86 
87  // CINT constructor interface
88  static RooAbsArg& as_ARG(UInt_t idx) { checkIndex(idx) ; return of()->of()->asARG(of()->_args[idx].c_str()) ; }
89 
90  static RooAbsPdf& as_PDF(UInt_t idx) { checkIndex(idx) ; return of()->asPDF(of()->_args[idx].c_str()) ; }
91  static RooAbsReal& as_FUNC(UInt_t idx) { checkIndex(idx) ; return of()->asFUNC(of()->_args[idx].c_str()) ; }
92  static RooRealVar& as_VAR(UInt_t idx) { checkIndex(idx) ; return of()->asVAR(of()->_args[idx].c_str()) ; }
93  static RooAbsRealLValue& as_VARLV(UInt_t idx) { checkIndex(idx) ; return of()->asVARLV(of()->_args[idx].c_str()) ; }
94  static RooResolutionModel& as_RMODEL(UInt_t idx) { checkIndex(idx) ; return of()->asRMODEL(of()->_args[idx].c_str()) ; }
95 
96  static RooCategory& as_CAT(UInt_t idx) { checkIndex(idx) ; return of()->asCAT(of()->_args[idx].c_str()) ; }
97  static RooAbsCategoryLValue& as_CATLV(UInt_t idx) { checkIndex(idx) ; return of()->asCATLV(of()->_args[idx].c_str()) ; }
98  static RooAbsCategory& as_CATFUNC(UInt_t idx) { checkIndex(idx) ; return of()->asCATFUNC(of()->_args[idx].c_str()) ; }
99 
100  static RooArgSet as_SET(UInt_t idx) { checkIndex(idx) ; return of()->asSET(of()->_args[idx].c_str()) ; }
101  static RooArgList as_LIST(UInt_t idx) { checkIndex(idx) ; return of()->asLIST(of()->_args[idx].c_str()) ; }
102 
103  static RooAbsData& as_DATA(UInt_t idx) { checkIndex(idx) ; return of()->asDATA(of()->_args[idx].c_str()) ; }
104  static RooDataHist& as_DHIST(UInt_t idx) { checkIndex(idx) ; return of()->asDHIST(of()->_args[idx].c_str()) ; }
105  static RooDataSet& as_DSET(UInt_t idx) { checkIndex(idx) ; return of()->asDSET(of()->_args[idx].c_str()) ; }
106 
107  static TObject& as_OBJ(UInt_t idx) { checkIndex(idx) ; return of()->asOBJ(of()->_args[idx].c_str()) ; }
108 
109  static const char* as_STRING(UInt_t idx) { checkIndex(idx) ; return of()->asSTRING(of()->_args[idx].c_str()) ; }
110  static Int_t as_INT(UInt_t idx) { checkIndex(idx) ; return of()->asINT(of()->_args[idx].c_str()) ; }
111  static Double_t as_DOUBLE(UInt_t idx) { checkIndex(idx) ; return of()->asDOUBLE(of()->_args[idx].c_str()) ; }
112  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()) ; }
113  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()) ; }
114 
115  RooAbsArg& asARG(const char*) ;
116 
117  RooAbsPdf& asPDF(const char*) ;
118  RooAbsReal& asFUNC(const char*) ;
119  RooRealVar& asVAR(const char*) ;
120  RooAbsRealLValue& asVARLV(const char*) ;
121  RooResolutionModel& asRMODEL(const char*) ;
122 
123  RooCategory& asCAT(const char*) ;
124  RooAbsCategoryLValue& asCATLV(const char*) ;
125  RooAbsCategory& asCATFUNC(const char*) ;
126 
127  RooArgSet asSET(const char*) ;
128  RooArgList asLIST(const char*) ;
129 
130  RooAbsData& asDATA(const char*) ;
131  RooDataHist& asDHIST(const char*) ;
132  RooDataSet& asDSET(const char*) ;
133 
134  TObject& asOBJ(const char*) ;
135 
136  const char* asSTRING(const char*) ;
137  Int_t asINT(const char*) ;
138  Double_t asDOUBLE(const char*) ;
139 
140  class IFace {
141  public:
142  virtual ~IFace() {} ;
143  virtual std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) = 0 ;
144  } ;
145 
146  class SpecialsIFace : public IFace {
147  public:
148  virtual ~SpecialsIFace() {} ;
149  std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) ;
150  } ;
151 
152  static void registerSpecial(const char* typeName, RooFactoryWSTool::IFace* iface) ;
153 
154  void logError() { _errorCount++ ; }
155 
156  const char* autoClassNamePostFix() const { return _autoClassPostFix.c_str() ; }
157  void setAutoClassNamePostFix(const char* pfix) { _autoClassPostFix = pfix ; }
158 
159 protected:
160 
161  Bool_t checkSyntax(const char* arg) ;
162 
163  std::string varTag(std::string& func, std::vector<std::string>& args) ;
164 
165  std::stack<std::string> _autoNamePrefix ;
166  std::map<std::string,std::string> _typeAliases ;
167 
168  static void checkIndex(UInt_t index) ;
169 
170 
171  std::string processCompositeExpression(const char* arg) ;
172  std::string processSingleExpression(const char* arg) ;
173  std::string processListExpression(const char* arg) ;
174  std::string processAliasExpression(const char* arg) ;
175 
176  std::string processCreateVar(std::string& func, std::vector<std::string>& args) ;
177  std::string processCreateArg(std::string& func, std::vector<std::string>& args) ;
178  std::string processMetaArg(std::string& func, std::vector<std::string>& args) ;
179 
180  TClass* resolveClassName(const char* className) ;
181 
182  // CINT constructor interface back end
183  static RooFactoryWSTool* of() ;
185  std::vector<std::string> _args ;
186 
187  // Hooks for other tools
188  static std::map<std::string,IFace*>& hooks() ;
189  static std::map<std::string,IFace*>* _hooks ;
190 
191  RooWorkspace* _ws ; //! Associated workspace
192 
193  void clearError() { _errorCount = 0 ; }
194  Int_t errorCount() { return _errorCount ; }
195 
196  Int_t _errorCount ; // Error counter for a given expression processing
197 
198  std::string _autoClassPostFix ;
199 
201 
202  ClassDef(RooFactoryWSTool,0) // RooFit class code and instance factory
203 } ;
204 
205 
206 
207 #endif
std::string _autoClassPostFix
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...
std::string processSingleExpression(const char *arg)
Process a single high-level expression.
static RooResolutionModel & as_RMODEL(UInt_t idx)
float xmin
Definition: THbookFile.cxx:93
RooProduct * prodfunc(const char *objName, const char *pdfList)
void setAutoClassNamePostFix(const char *pfix)
TObject & asOBJ(const char *)
std::vector< std::string > splitFunctionArgs(const char *funcExpr)
Allocate and fill work buffer.
RooArgList asLIST(const char *)
CINT constructor interface, return constructor string argument #idx as RooArgList of objects found in...
static RooRealVar & as_VAR(UInt_t idx)
RooAddPdf * add(const char *objName, const char *specList, Bool_t recursiveCoefs=kFALSE)
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
static Int_t as_INT(UInt_t idx, Int_t defVal)
RooWorkspace & ws()
static RooFactoryWSTool * _of
RooFactoryWSTool is a clase like TTree::MakeClass() that generates skeleton code for RooAbsPdf and Ro...
RooSimultaneous * simul(const char *objName, const char *indexCat, const char *pdfMap)
static std::map< std::string, IFace * > & hooks()
static RooAbsCategoryLValue & as_CATLV(UInt_t idx)
static Double_t as_DOUBLE(UInt_t idx)
RooAbsCategory & asCATFUNC(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsCategory reference found...
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
RooRealSumPdf * amplAdd(const char *objName, const char *specList)
static RooAbsData & as_DATA(UInt_t idx)
static RooArgSet as_SET(UInt_t idx)
static Double_t as_DOUBLE(UInt_t idx, Double_t defVal)
static void checkIndex(UInt_t index)
std::map< std::string, std::string > _typeAliases
std::vector< std::string > _args
RooAbsArg * process(const char *expr)
Process high-level object creation syntax Accepted forms of syntax are.
static RooAbsRealLValue & as_VARLV(UInt_t idx)
const char * asSTRING(const char *)
CINT constructor interface, return constructor string argument #idx as const char*.
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
#define ClassDef(name, id)
Definition: Rtypes.h:254
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods...
Definition: RooPrintable.h:26
std::string varTag(std::string &func, std::vector< std::string > &args)
static RooAbsPdf & as_PDF(UInt_t idx)
RooResolutionModel & asRMODEL(const char *)
CINT constructor interface, return constructor string argument #idx as RooResolutionModel reference f...
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
static RooDataSet & as_DSET(UInt_t idx)
std::string processExpression(const char *expr)
Process a single high-level expression or list of expressions.
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
std::string processAliasExpression(const char *arg)
Parse token.
static RooArgList as_LIST(UInt_t idx)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooAbsArg & asARG(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsArg reference found in w...
RooAbsCategoryLValue & asCATLV(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsCategoryLValue reference...
static const char * as_STRING(UInt_t idx)
RooRealVar & asVAR(const char *)
CINT constructor interface, return constructor string argument #idx as RooRealVar reference found in ...
Int_t asINT(const char *)
CINT constructor interface, return constructor string argument #idx as Int_t.
RooAbsReal & asFUNC(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsReal reference found in ...
std::stack< std::string > _autoNamePrefix
unsigned int UInt_t
Definition: RtypesCore.h:42
static RooDataHist & as_DHIST(UInt_t idx)
RooArgSet asSET(const char *)
CINT constructor interface, return constructor string argument #idx as RooArgSet of objects found in ...
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
float xmax
Definition: THbookFile.cxx:93
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...
RooDataHist & asDHIST(const char *)
CINT constructor interface, return constructor string argument #idx as RooDataHist object found in wo...
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:25
static Int_t as_INT(UInt_t idx)
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
Definition: RooProduct.h:32
RooProdPdf * prod(const char *objName, const char *pdfList)
RooFactoryWSTool(RooWorkspace &ws)
static RooFactoryWSTool * of()
RooAbsRealLValue & asVARLV(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsRealLValue reference fou...
RooAbsData & asDATA(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsData object found in wor...
Double_t asDOUBLE(const char *)
CINT constructor interface, return constructor string argument #idx as Double_t.
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooAddition * addfunc(const char *objName, const char *specList)
std::vector< std::string > ctorArgs(const char *className)
double func(double *x, double *p)
Definition: stressTF1.cxx:213
static RooAbsCategory & as_CATFUNC(UInt_t idx)
RooDataSet & asDSET(const char *)
CINT constructor interface, return constructor string argument #idx as RooDataSet object found in wor...
TClass * resolveClassName(const char *className)
static std::map< std::string, IFace * > * _hooks
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)
Concatenate list of args into comma separated string.
void clearError()
Associated workspace.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooCategory & asCAT(const char *)
CINT constructor interface, return constructor string argument #idx as RooCategory reference found in...
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
std::string processCompositeExpression(const char *arg)
Process a single composite expression.
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...
std::string processListExpression(const char *arg)
Process a list of high-level expression.
static void registerSpecial(const char *typeName, RooFactoryWSTool::IFace *iface)
Register foreign special objects in factory.
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets...
Definition: RooAddition.h:26
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooCategory * createCategory(const char *name, const char *stateNameList=0)
Low-level factory interface for creating a RooCategory with a given list of state names...
std::string processMetaArg(std::string &func, std::vector< std::string > &args)
Concatenate list of args into comma separated string.
RooWorkspace * _ws
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...
const char * autoClassNamePostFix() const
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset...
RooAbsPdf & asPDF(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsPdf reference found in w...
Bool_t checkSyntax(const char *arg)
Perform basic syntax on given factory expression.
static TObject & as_OBJ(UInt_t idx)
static RooCategory & as_CAT(UInt_t idx)
static RooAbsArg & as_ARG(UInt_t idx)
static RooAbsReal & as_FUNC(UInt_t idx)
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42
virtual std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)=0
virtual ~RooFactoryWSTool()
Destructor.