Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooCFunction3Binding.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id$
5 * Authors: * WV, Wouter Verkerke, NIKHEF, verkerke@nikhef.nl *
6 * *
7 * Copyright (c) 2000-2008, NIKHEF, Regents of the University of California *
8 * and Stanford University. All rights reserved. *
9 * *
10 *****************************************************************************/
11
12#ifndef ROOCFUNCTION3BINDING
13#define ROOCFUNCTION3BINDING
14
15#include "RooAbsReal.h"
16#include "RooRealProxy.h"
17#include "RooAbsPdf.h"
19
20
21namespace RooFit {
22
29
42
43}
44
45template <class VO, class VI1, class VI2, class VI3>
46using RooCFunction3Map = RooFit::Detail::CFunctionMap<VO (*)(VI1, VI2, VI3)>;
47
48
49template<class VO, class VI1, class VI2, class VI3>
50class RooCFunction3Ref : public TObject {
51 public:
52 RooCFunction3Ref(VO (*ptr)(VI1,VI2,VI3)=nullptr) : _ptr(ptr) {
53 // Constructor of persistable function reference
54 } ;
55
56 VO operator()(VI1 x,VI2 y, VI3 z) const {
57 // Evaluate embedded function
58 return (*_ptr)(x,y,z) ;
59 }
60
61 const char* name() const {
62 // Return registered name of embedded function. If function
63 // is not registered return string with hex presentation
64 // of function pointer value
65 return fmap().nameOrAddress(_ptr);
66 }
67
68 const char* argName(Int_t iarg) {
69 // Return suggested name for i-th argument
70 return fmap().lookupArgName(_ptr,iarg) ;
71 }
72
74 // Return reference to function pointer-to-name mapping service
75 if (!_fmap) {
77 }
78 return *_fmap ;
79 }
80
81 private:
82
83 static VO dummyFunction(VI1,VI2,VI3) {
84 // Dummy function used when registered function was not
85 // found in un-persisting object
86 return 0 ;
87 }
88
89
90 typedef VO (*func_t)(VI1,VI2,VI3) ; ///<! Pointer to embedded function
91 func_t _ptr; ///<! Pointer to embedded function
92
93 static RooCFunction3Map<VO,VI1,VI2,VI3>* _fmap ; // Pointer to mapping service object
94
95 ClassDefOverride(RooCFunction3Ref,1) // Persistable reference to C function pointer
96} ;
97
98// Define static member
99template<class VO, class VI1, class VI2, class VI3>
101
102
103
104template<class VO, class VI1, class VI2, class VI3>
106{
107 RooFit::Detail::streamCFunctionRef(R__b, *this, _ptr, dummyFunction, fmap());
108}
109
110
111
112template<class VO,class VI1, class VI2, class VI3>
114public:
116 // Default constructor
117 } ;
118 RooCFunction3Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z);
119 RooCFunction3Binding(const RooCFunction3Binding& other, const char* name=nullptr) ;
120 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction3Binding(*this,newname); }
121
122 void printArgs(std::ostream& os) const override {
123 // Print object arguments and name/address of function pointer
124 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
125 }
126
127protected:
128
129 RooCFunction3Ref<VO,VI1,VI2,VI3> func ; // Function pointer reference
130 RooRealProxy x ; // Argument reference
131 RooRealProxy y ; // Argument reference
132 RooRealProxy z ; // Argument reference
133
134 double evaluate() const override {
135 // Return value of embedded function using value of referenced variable x
136 return func(x,y,z) ;
137 }
138
139private:
140
141 ClassDefOverride(RooCFunction3Binding,1) // RooAbsReal binding to external C functions
142};
143
144
145
146template<class VO,class VI1, class VI2, class VI3>
147RooCFunction3Binding<VO,VI1,VI2,VI3>::RooCFunction3Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3),
148 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z) :
149 RooAbsReal(name,title),
150 func(_func),
151 x(func.argName(0),func.argName(0),this,_x),
152 y(func.argName(1),func.argName(1),this,_y),
153 z(func.argName(2),func.argName(2),this,_z)
154{
155 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
156 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
157 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
158 // a RooWorkspace
159}
160
161
162template<class VO,class VI1, class VI2, class VI3>
164 RooAbsReal(other,name),
165 func(other.func),
166 x("x",this,other.x),
167 y("y",this,other.y),
168 z("z",this,other.z)
169{
170 // Copy constructor
171}
172
173
174template<class VO,class VI1, class VI2, class VI3>
176public:
178 // Default constructor
179 } ;
180 RooCFunction3PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z);
181 RooCFunction3PdfBinding(const RooCFunction3PdfBinding& other, const char* name=nullptr) ;
182 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction3PdfBinding(*this,newname); }
183
184 void printArgs(std::ostream& os) const override {
185 // Print object arguments and name/address of function pointer
186 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
187 }
188
189protected:
190
191 RooCFunction3Ref<VO,VI1,VI2,VI3> func ; // Function pointer reference
192 RooRealProxy x ; // Argument reference
193 RooRealProxy y ; // Argument reference
194 RooRealProxy z ; // Argument reference
195
196 double evaluate() const override {
197 // Return value of embedded function using value of referenced variable x
198 return func(x,y,z) ;
199 }
200
201private:
202
203 ClassDefOverride(RooCFunction3PdfBinding,1) // RooAbsReal binding to external C functions
204};
205
206
207
208template<class VO,class VI1, class VI2, class VI3>
209RooCFunction3PdfBinding<VO,VI1,VI2,VI3>::RooCFunction3PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3),
210 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z) :
211 RooAbsPdf(name,title),
212 func(_func),
213 x(func.argName(0),func.argName(0),this,_x),
214 y(func.argName(1),func.argName(1),this,_y),
215 z(func.argName(2),func.argName(2),this,_z)
216{
217 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
218 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
219 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
220 // a RooWorkspace
221}
222
223
224template<class VO,class VI1, class VI2, class VI3>
226 RooAbsPdf(other,name),
227 func(other.func),
228 x("x",this,other.x),
229 y("y",this,other.y),
230 z("z",this,other.z)
231{
232 // Copy constructor
233}
234
235#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
RooCFunction3Binding 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.
RooCFunction3Ref< VO, VI1, VI2, VI3 > func
TObject * clone(const char *newname=nullptr) const override
RooCFunction3Ref< VO, VI1, VI2, VI3 > func
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
const char * name() const
static RooCFunction3Map< VO, VI1, VI2, VI3 > * _fmap
static RooCFunction3Map< VO, VI1, VI2, VI3 > & fmap()
void Streamer(TBuffer &) override
Stream an object of class TObject.
static VO dummyFunction(VI1, VI2, VI3)
VO(* func_t)(VI1, VI2, VI3)
! Pointer to embedded function
const char * argName(Int_t iarg)
RooCFunction3Ref(VO(*ptr)(VI1, VI2, VI3)=nullptr)
VO operator()(VI1 x, VI2 y, VI3 z) const
func_t _ptr
! Pointer to embedded function
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(* CFUNCD3DDD)(double, double, double)
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
double(* CFUNCD3DDB)(double, double, bool)
double(* CFUNCD3UDD)(UInt_t, double, double)
double(* CFUNCD3DII)(double, Int_t, Int_t)
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
double(* CFUNCD3UDU)(UInt_t, double, UInt_t)
double(* CFUNCD3UUD)(UInt_t, UInt_t, double)