Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <map>
26
27class RooAbsReal ;
28class RooAbsRealLValue ;
29class RooAbsPdf ;
30class RooWorkspace ;
31class RooRealVar ;
32class RooCategory ;
33class RooAddPdf ;
34class RooProdPdf ;
35class RooSimultaneous ;
36class RooDataHist ;
37class RooDataSet ;
38class RooAbsData ;
39class RooFactoryWSToolSpec ;
41class RooAbsCategory ;
43class RooAddition ;
44class RooProduct ;
45class RooRealSumPdf ;
46
47class RooFactoryWSTool : public TNamed, public RooPrintable {
48
49public:
50
51 // Constructors, assignment etc
53
55
56 // --- low level factory interface ---
57
58 // Create variables
59 RooRealVar* createVariable(const char* name, double xmin, double xmax) ;
60 RooCategory* createCategory(const char* name, const char* stateNameList=nullptr) ;
61
62 // Create functions and p.d.f.s (any RooAbsArg)
63 RooAbsArg* createArg(const char* className, const char* objName, const char* varList) ;
64
65 // Create operator p.d.f.s
66 RooAddPdf* add(const char *objName, const char* specList, bool recursiveCoefs=false) ;
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 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 as_DOUBLE(UInt_t idx, double 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 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 std::string create(RooFactoryWSTool& ft, const char* typeName, const char* instanceName, std::vector<std::string> args) override ;
149 } ;
150
151 static void registerSpecial(const char* typeName, RooFactoryWSTool::IFace* iface) ;
152
153 void logError() { _errorCount++ ; }
154
155 const char* autoClassNamePostFix() const { return _autoClassPostFix.c_str() ; }
156 void setAutoClassNamePostFix(const char* pfix) { _autoClassPostFix = pfix ; }
157
158protected:
159
160 bool checkSyntax(const char* arg) ;
161
162 std::string varTag(std::string& func, std::vector<std::string>& args) ;
163
164 std::stack<std::string> _autoNamePrefix ;
165 std::map<std::string,std::string> _typeAliases ;
166
167 static void checkIndex(UInt_t index) ;
168
169
170 std::string processCompositeExpression(const char* arg) ;
171 std::string processSingleExpression(const char* arg) ;
172 std::string processListExpression(const char* arg) ;
173 std::string processAliasExpression(const char* arg) ;
174
175 std::string processCreateVar(std::string& func, std::vector<std::string>& args) ;
176 std::string processCreateArg(std::string& func, std::vector<std::string>& args) ;
177 std::string processMetaArg(std::string& func, std::vector<std::string>& args) ;
178
179 TClass* resolveClassName(const char* className) ;
180
181 // CINT constructor interface back end
182 static RooFactoryWSTool* of() ;
184 std::vector<std::string> _args ;
185
186 // Hooks for other tools
187 static std::map<std::string,IFace*>& hooks() ;
188 static std::map<std::string,IFace*>* _hooks ;
189
190 RooWorkspace* _ws ; //! Associated workspace
191
192 void clearError() { _errorCount = 0 ; }
194
195 Int_t _errorCount = 0; // Error counter for a given expression processing
196
197 std::string _autoClassPostFix;
198
199 ClassDefOverride(RooFactoryWSTool,0) // RooFit class code and instance factory
200
201} ;
202
203
204
205#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:33
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
Definition RooAddition.h:27
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Object to represent discrete states.
Definition RooCategory.h:28
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
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) override
Concatenate list of args into comma separated string.
Implementation detail of the RooWorkspace.
RooWorkspace & ws()
const char * autoClassNamePostFix() const
void setAutoClassNamePostFix(const char *pfix)
static RooAbsReal & as_FUNC(UInt_t idx)
RooWorkspace * _ws
RooAddPdf * add(const char *objName, const char *specList, bool recursiveCoefs=false)
RooAbsArg & asARG(const char *)
CINT constructor interface, return constructor string argument #idx as RooAbsArg reference found in w...
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)
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.
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 double as_DOUBLE(UInt_t idx, double defVal)
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)
RooCategory * createCategory(const char *name, const char *stateNameList=nullptr)
Low-level factory interface for creating a RooCategory with a given list of state names.
static RooDataSet & as_DSET(UInt_t idx)
RooRealVar * createVariable(const char *name, double xmin, double xmax)
Low-level factory interface for creating a RooRealVar with a given range and initial value.
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
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)
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...
static double as_DOUBLE(UInt_t idx)
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)
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...
RooFactoryWSTool(const RooFactoryWSTool &)=delete
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)
double asDOUBLE(const char *)
CINT constructor interface, return constructor string argument #idx as double.
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 ...
bool checkSyntax(const char *arg)
Perform basic syntax on given factory 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...
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
Efficient implementation of a product of PDFs of the form.
Definition RooProdPdf.h:33
Represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
Definition RooRealVar.h:37
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
Persistable container for RooFit projects.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41