Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooCFunction4Binding.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 ROOCFUNCTION4BINDING
14#define ROOCFUNCTION4BINDING
15
16#include "RooAbsReal.h"
17#include "RooAbsPdf.h"
18#include "RooRealProxy.h"
20
21namespace RooFit {
22
26
33
34}
35
36
37template <class VO, class VI1, class VI2, class VI3, class VI4>
38using RooCFunction4Map = RooFit::Detail::CFunctionMap<VO (*)(VI1, VI2, VI3, VI4)>;
39
40
41
42template<class VO, class VI1, class VI2, class VI3, class VI4>
43class RooCFunction4Ref : public TObject {
44 public:
45 RooCFunction4Ref(VO (*ptr)(VI1,VI2,VI3,VI4)=nullptr) : _ptr(ptr) {
46 // Constructor of persistable function reference
47 } ;
48
49 VO operator()(VI1 x,VI2 y,VI3 z,VI4 w) const {
50 // Evaluate embedded function
51 return (*_ptr)(x,y,z,w) ;
52 }
53
54 const char* name() const {
55 // Return registered name of embedded function. If function
56 // is not registered return string with hex presentation
57 // of function pointer value
58 return fmap().nameOrAddress(_ptr);
59 }
60
61 const char* argName(Int_t iarg) {
62 // Return suggested name for i-th argument
63 return fmap().lookupArgName(_ptr,iarg) ;
64 }
65
67 // Return reference to function pointer-to-name mapping service
68 if (!_fmap) {
70 }
71 return *_fmap ;
72 }
73 private:
74
75 static VO dummyFunction(VI1,VI2,VI3,VI4) {
76 // Dummy function used when registered function was not
77 // found in un-persisting object
78 return 0 ;
79 }
80
81
82 typedef VO (*func_t)(VI1,VI2,VI3,VI4);
83 func_t _ptr; ///<! Pointer to embedded function
84
85 static RooCFunction4Map<VO,VI1,VI2,VI3,VI4>* _fmap ; // Pointer to mapping service object
86
87 ClassDefOverride(RooCFunction4Ref,1) // Persistable reference to C function pointer
88} ;
89
90// Define static member
91template<class VO, class VI1, class VI2, class VI3, class VI4>
93
94template<class VO, class VI1, class VI2, class VI3, class VI4>
96{
97 RooFit::Detail::streamCFunctionRef(R__b, *this, _ptr, dummyFunction, fmap());
98}
99
100
101
102template<class VO,class VI1, class VI2, class VI3, class VI4>
104public:
106 // Default constructor
107 } ;
108 RooCFunction4Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w);
109 RooCFunction4Binding(const RooCFunction4Binding& other, const char* name=nullptr) ;
110 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction4Binding(*this,newname); }
111
112 void printArgs(std::ostream& os) const override {
113 // Print object arguments and name/address of function pointer
114 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
115 }
116
117protected:
118
119 RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> func ; // Function pointer reference
120 RooRealProxy x ; // Argument reference
121 RooRealProxy y ; // Argument reference
122 RooRealProxy z ; // Argument reference
123 RooRealProxy w ; // Argument reference
124
125 double evaluate() const override {
126 // Return value of embedded function using value of referenced variable x
127 return func(x,y,z,w) ;
128 }
129
130private:
131
132 ClassDefOverride(RooCFunction4Binding,1) // RooAbsReal binding to external C functions
133};
134
135
136template<class VO,class VI1, class VI2, class VI3, class VI4>
137RooCFunction4Binding<VO,VI1,VI2,VI3,VI4>::RooCFunction4Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4),
138 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w) :
139 RooAbsReal(name,title),
140 func(_func),
141 x(func.argName(0),func.argName(0),this,_x),
142 y(func.argName(1),func.argName(1),this,_y),
143 z(func.argName(2),func.argName(2),this,_z),
144 w(func.argName(3),func.argName(3),this,_w)
145{
146 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
147 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
148 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
149 // a RooWorkspace
150}
151
152
153template<class VO,class VI1, class VI2, class VI3, class VI4>
155 RooAbsReal(other,name),
156 func(other.func),
157 x("x",this,other.x),
158 y("y",this,other.y),
159 z("z",this,other.z),
160 w("w",this,other.w)
161{
162 // Copy constructor
163}
164
165
166template<class VO,class VI1, class VI2, class VI3, class VI4>
168public:
170 // Default constructor
171 } ;
172 RooCFunction4PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w);
173 RooCFunction4PdfBinding(const RooCFunction4PdfBinding& other, const char* name=nullptr) ;
174 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction4PdfBinding(*this,newname); }
175
176 void printArgs(std::ostream& os) const override {
177 // Print object arguments and name/address of function pointer
178 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
179 }
180
181protected:
182
183 RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> func ; // Function pointer reference
184 RooRealProxy x ; // Argument reference
185 RooRealProxy y ; // Argument reference
186 RooRealProxy z ; // Argument reference
187 RooRealProxy w ; // 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,z,w) ;
192 }
193
194private:
195
196 ClassDefOverride(RooCFunction4PdfBinding,1) // RooAbsReal binding to external C functions
197};
198
199
200template<class VO,class VI1, class VI2, class VI3, class VI4>
201RooCFunction4PdfBinding<VO,VI1,VI2,VI3,VI4>::RooCFunction4PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4),
202 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w) :
203 RooAbsPdf(name,title),
204 func(_func),
205 x(func.argName(0),func.argName(0),this,_x),
206 y(func.argName(1),func.argName(1),this,_y),
207 z(func.argName(2),func.argName(2),this,_z),
208 w(func.argName(3),func.argName(3),this,_w)
209{
210 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
211 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
212 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
213 // a RooWorkspace
214}
215
216
217template<class VO,class VI1, class VI2, class VI3, class VI4>
219 RooAbsPdf(other,name),
220 func(other.func),
221 x("x",this,other.x),
222 y("y",this,other.y),
223 z("z",this,other.z),
224 w("w",this,other.w)
225{
226 // Copy constructor
227}
228
229#endif
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
#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
RooCFunction4Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void printArgs(std::ostream &os) const override
Print object arguments, ie its proxies.
TObject * clone(const char *newname=nullptr) const override
RooCFunction4Ref< VO, VI1, VI2, VI3, VI4 > 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.
RooCFunction4Ref< VO, VI1, VI2, VI3, VI4 > func
static RooCFunction4Map< VO, VI1, VI2, VI3, VI4 > * _fmap
RooCFunction4Ref(VO(*ptr)(VI1, VI2, VI3, VI4)=nullptr)
void Streamer(TBuffer &) override
Stream an object of class TObject.
func_t _ptr
! Pointer to embedded function
const char * argName(Int_t iarg)
const char * name() const
VO(* func_t)(VI1, VI2, VI3, VI4)
VO operator()(VI1 x, VI2 y, VI3 z, VI4 w) const
static RooCFunction4Map< VO, VI1, VI2, VI3, VI4 > & fmap()
static VO dummyFunction(VI1, VI2, VI3, VI4)
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(* CFUNCD4DDDB)(double, double, double, bool)
double(* CFUNCD4DDDD)(double, double, double, double)
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
double(* CFUNCD4DDDI)(double, double, double, Int_t)
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)