Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooCFunction2Binding.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id$
5 * Authors: *
6 * WV, Wouter Verkerke, NIKHEF, verkerke@nikhef.nl *
7 * *
8 * Copyright (c) 2000-2008, NIKHEF, Regents of the University of California *
9 * and Stanford University. All rights reserved. *
10 * *
11 *****************************************************************************/
12
13#ifndef ROOCFUNCTION2BINDING
14#define ROOCFUNCTION2BINDING
15
16#include "RooAbsReal.h"
17#include "RooAbsPdf.h"
18#include "RooRealProxy.h"
20
21namespace RooFit {
22
28
29
35RooAbsPdf* bindPdf(const char* name,CFUNCD2DD func,RooAbsReal& x, RooAbsReal& y) ;
36RooAbsPdf* bindPdf(const char* name,CFUNCD2ID func,RooAbsReal& x, RooAbsReal& y) ;
37RooAbsPdf* bindPdf(const char* name,CFUNCD2UD func,RooAbsReal& x, RooAbsReal& y) ;
38RooAbsPdf* bindPdf(const char* name,CFUNCD2DI func,RooAbsReal& x, RooAbsReal& y) ;
39RooAbsPdf* bindPdf(const char* name,CFUNCD2II func,RooAbsReal& x, RooAbsReal& y) ;
40
41}
42
43template <class VO, class VI1, class VI2>
45
46
47
48template<class VO, class VI1, class VI2>
49class RooCFunction2Ref : public TObject {
50 public:
51 RooCFunction2Ref(VO (*ptr)(VI1,VI2)=nullptr) : _ptr(ptr) {
52 // Constructor of persistable function reference
53 } ;
54
55 VO operator()(VI1 x,VI2 y) const {
56 // Evaluate embedded function
57 return (*_ptr)(x,y) ;
58 }
59
60 const char* name() const {
61 // Return registered name of embedded function. If function
62 // is not registered return string with hex presentation
63 // of function pointer value
64 return fmap().nameOrAddress(_ptr);
65 }
66
67 const char* argName(Int_t iarg) {
68 // Return suggested name for i-th argument
69 return fmap().lookupArgName(_ptr,iarg) ;
70 }
71
73 // Return reference to function pointer-to-name mapping service
74 if (!_fmap) {
76 }
77 return *_fmap ;
78 }
79
80 private:
81
82 static VO dummyFunction(VI1,VI2) {
83 // Dummy function used when registered function was not
84 // found in un-persisting object
85 return 0 ;
86 }
87
88 typedef VO (*func_t)(VI1,VI2);
89 func_t _ptr; ///<! Pointer to embedded function
90
91 static RooCFunction2Map<VO,VI1,VI2>* _fmap ; // Pointer to mapping service object
92
93 ClassDefOverride(RooCFunction2Ref,1) // Persistable reference to C function pointer
94} ;
95
96// Define static member
97template<class VO, class VI1, class VI2>
99
100
101template<class VO, class VI1, class VI2>
103{
104 RooFit::Detail::streamCFunctionRef(R__b, *this, _ptr, dummyFunction, fmap());
105}
106
107
108
109template<class VO,class VI1, class VI2>
111public:
113 // Default constructor
114 } ;
115 RooCFunction2Binding(const char *name, const char *title, VO (*_func)(VI1,VI2), RooAbsReal& _x, RooAbsReal& _y);
116 RooCFunction2Binding(const RooCFunction2Binding& other, const char* name=nullptr) ;
117 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction2Binding(*this,newname); }
118
119 void printArgs(std::ostream& os) const override {
120 // Print object arguments and name/address of function pointer
121 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
122 }
123
124protected:
125
126 RooCFunction2Ref<VO,VI1,VI2> func ; // Function pointer reference
127 RooRealProxy x ; // Argument reference
128 RooRealProxy y ; // Argument reference
129
130 double evaluate() const override {
131 // Return value of embedded function using value of referenced variable x
132 return func(x,y) ;
133 }
134
135private:
136
137 ClassDefOverride(RooCFunction2Binding,1) // RooAbsReal binding to external C functions
138};
139
140template<class VO,class VI1, class VI2>
141RooCFunction2Binding<VO,VI1,VI2>::RooCFunction2Binding(const char *name, const char *title, VO (*_func)(VI1,VI2),
142 RooAbsReal& _x, RooAbsReal& _y) :
143 RooAbsReal(name,title),
144 func(_func),
145 x(func.argName(0),func.argName(0),this,_x),
146 y(func.argName(1),func.argName(1),this,_y)
147{
148 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
149 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
150 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
151 // a RooWorkspace
152}
153
154
155template<class VO,class VI1, class VI2>
157 RooAbsReal(other,name),
158 func(other.func),
159 x("x",this,other.x),
160 y("y",this,other.y)
161{
162 // Copy constructor
163}
164
165
166
167
168template<class VO,class VI1, class VI2>
170public:
172 // Default constructor
173 } ;
174 RooCFunction2PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2), RooAbsReal& _x, RooAbsReal& _y);
175 RooCFunction2PdfBinding(const RooCFunction2PdfBinding& other, const char* name=nullptr) ;
176 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction2PdfBinding(*this,newname); }
177
178 void printArgs(std::ostream& os) const override {
179 // Print object arguments and name/address of function pointer
180 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
181 }
182
183protected:
184
185 RooCFunction2Ref<VO,VI1,VI2> func ; // Function pointer reference
186 RooRealProxy x ; // Argument reference
187 RooRealProxy y ; // Argument reference
188
189 double evaluate() const override {
190 // Return value of embedded function using value of referenced variable x
191 return func(x,y) ;
192 }
193
194private:
195
196 ClassDefOverride(RooCFunction2PdfBinding,1) // RooAbsReal binding to external C functions
197};
198
199template<class VO,class VI1, class VI2>
200RooCFunction2PdfBinding<VO,VI1,VI2>::RooCFunction2PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2),
201 RooAbsReal& _x, RooAbsReal& _y) :
202 RooAbsPdf(name,title),
203 func(_func),
204 x(func.argName(0),func.argName(0),this,_x),
205 y(func.argName(1),func.argName(1),this,_y)
206{
207 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
208 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
209 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
210 // a RooWorkspace
211}
212
213
214template<class VO,class VI1, class VI2>
216 RooAbsPdf(other,name),
217 func(other.func),
218 x("x",this,other.x),
219 y("y",this,other.y)
220{
221 // Copy constructor
222}
223
224#endif
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
#define ClassDefOverride(name, id)
Definition Rtypes.h:347
char name[80]
Definition TGX11.cxx:142
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooCFunction2Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
RooCFunction2Ref< VO, VI1, VI2 > func
TObject * clone(const char *newname=nullptr) const override
void printArgs(std::ostream &os) const override
Print object arguments, ie its proxies.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
TObject * clone(const char *newname=nullptr) const override
void printArgs(std::ostream &os) const override
Print object arguments, ie its proxies.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooCFunction2Ref< VO, VI1, VI2 > func
const char * argName(Int_t iarg)
VO operator()(VI1 x, VI2 y) const
RooCFunction2Ref(VO(*ptr)(VI1, VI2)=nullptr)
static RooCFunction2Map< VO, VI1, VI2 > & fmap()
static VO dummyFunction(VI1, VI2)
void Streamer(TBuffer &) override
Stream an object of class TObject.
func_t _ptr
! Pointer to embedded function
const char * name() const
VO(* func_t)(VI1, VI2)
static RooCFunction2Map< VO, VI1, VI2 > * _fmap
Name <-> pointer mapping service for C functions of type Func, used to persist the RooCFunction[1-4]R...
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Mother of all ROOT objects.
Definition TObject.h:42
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
void printCFunctionArgs(std::ostream &os, RooAbsArg const &arg, const char *funcName)
Print arguments of a function binding and name/address of the function pointer.
void streamCFunctionRef(TBuffer &R__b, TObject const &self, Func &ptr, Func dummyFunction, CFunctionMap< Func > &fmap)
Custom streamer for function pointer reference objects.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73
double(* CFUNCD2ID)(Int_t, double)
double(* CFUNCD2DD)(double, double)
double(* CFUNCD2DI)(double, Int_t)
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
double(* CFUNCD2UD)(UInt_t, double)
double(* CFUNCD2II)(Int_t, Int_t)