Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooCFunction1Binding.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 ROOCFUNCTION1BINDING
14#define ROOCFUNCTION1BINDING
15
16#include "RooAbsReal.h"
17#include "RooAbsPdf.h"
18#include "RooRealProxy.h"
20
21
22namespace RooFit {
23
24typedef double (*CFUNCD1D)(double) ;
25typedef double (*CFUNCD1I)(Int_t) ;
26
27RooAbsReal* bindFunction(const char* name,CFUNCD1D func,RooAbsReal& x) ;
28RooAbsReal* bindFunction(const char* name,CFUNCD1I func,RooAbsReal& x) ;
29RooAbsPdf* bindPdf(const char* name,CFUNCD1D func,RooAbsReal& x) ;
30RooAbsPdf* bindPdf(const char* name,CFUNCD1I func,RooAbsReal& x) ;
31
32}
33
34
35template <class VO, class VI>
37
38
39
40template<class VO, class VI>
41class RooCFunction1Ref : public TObject {
42 public:
43 RooCFunction1Ref(VO (*ptr)(VI)=nullptr) : _ptr(ptr) {
44 // Constructor of persistable function reference
45 } ;
46
47 VO operator()(VI x) const {
48 // Evaluate embedded function
49 return (*_ptr)(x) ;
50 }
51
52 const char* name() const {
53 // Return registered name of embedded function. If function
54 // is not registered return string with hex presentation
55 // of function pointer value
56 return fmap().nameOrAddress(_ptr);
57 }
58
59 const char* argName(Int_t iarg) {
60 // Return suggested name for i-th argument
61 return fmap().lookupArgName(_ptr,iarg) ;
62 }
63
65
66 private:
67
68 static VO dummyFunction(VI) {
69 // Dummy function used when registered function was not
70 // found in un-persisting object
71 return 0 ;
72 }
73
74 typedef VO (*func_t)(VI);
75 func_t _ptr; ///<! Pointer to embedded function
76
77 static RooCFunction1Map<VO,VI>* _fmap ; // Pointer to mapping service object
78
79 ClassDefOverride(RooCFunction1Ref,1) // Persistable reference to C function pointer
80} ;
81
82// Define static member
83template<class VO, class VI>
85
86template<class VO, class VI>
88{
89 RooFit::Detail::streamCFunctionRef(R__b, *this, _ptr, dummyFunction, fmap());
90}
91
92
93
94template<class VO,class VI>
96public:
98 // Default constructor
99 } ;
100 RooCFunction1Binding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x);
101 RooCFunction1Binding(const RooCFunction1Binding& other, const char* name=nullptr) ;
102 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction1Binding(*this,newname); }
103
104 void printArgs(std::ostream& os) const override {
105 // Print object arguments and name/address of function pointer
106 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
107 }
108
109protected:
110
111 RooCFunction1Ref<VO,VI> func ; // Function pointer reference
112 RooRealProxy x ; // Argument reference
113
114 double evaluate() const override {
115 // Return value of embedded function using value of referenced variable x
116 return func(x) ;
117 }
118
119private:
120
121 ClassDefOverride(RooCFunction1Binding,1) // RooAbsReal binding to external C functions
122};
123
124
125template<class VO,class VI>
126RooCFunction1Binding<VO,VI>::RooCFunction1Binding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x) :
127 RooAbsReal(name,title),
128 func(_func),
129 x(func.argName(0),func.argName(0),this,_x)
130{
131 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
132 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
133 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
134 // a RooWorkspace
135}
136
137
138template<class VO,class VI>
140 RooAbsReal(other,name),
141 func(other.func),
142 x("x",this,other.x)
143{
144 // Copy constructor
145}
146
147
148
149template<class VO,class VI>
151public:
153 // Default constructor
154 } ;
155 RooCFunction1PdfBinding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x);
156 RooCFunction1PdfBinding(const RooCFunction1PdfBinding& other, const char* name=nullptr) ;
157 TObject* clone(const char* newname=nullptr) const override { return new RooCFunction1PdfBinding(*this,newname); }
158
159 void printArgs(std::ostream& os) const override {
160 // Print object arguments and name/address of function pointer
161 RooFit::Detail::printCFunctionArgs(os, *this, func.name());
162 }
163
164protected:
165
166 RooCFunction1Ref<VO,VI> func ; // Function pointer reference
167 RooRealProxy x ; // Argument reference
168
169 double evaluate() const override {
170 // Return value of embedded function using value of referenced variable x
171 return func(x) ;
172 }
173
174private:
175
176 ClassDefOverride(RooCFunction1PdfBinding,1) // RooAbsReal binding to external C functions
177};
178
179
180template<class VO,class VI>
181RooCFunction1PdfBinding<VO,VI>::RooCFunction1PdfBinding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x) :
182 RooAbsPdf(name,title),
183 func(_func),
184 x(func.argName(0),func.argName(0),this,_x)
185{
186 // Constructor of C function binding object given a pointer to a function and a RooRealVar to which the function
187 // argument should be bound. This object is fully functional as a RooFit function object. The only restriction is
188 // if the referenced function is _not_ a standard ROOT TMath or MathCore function it can not be persisted in a
189 // a RooWorkspace
190}
191
192
193template<class VO,class VI>
195 RooAbsPdf(other,name),
196 func(other.func),
197 x("x",this,other.x)
198{
199 // Copy constructor
200}
201
202#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
RooCFunction1Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
RooCFunction1Ref< VO, VI > func
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.
RooCFunction1Ref< VO, VI > func
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.
func_t _ptr
! Pointer to embedded function
static VO dummyFunction(VI)
void Streamer(TBuffer &) override
Stream an object of class TObject.
VO operator()(VI x) const
const char * name() const
const char * argName(Int_t iarg)
static RooCFunction1Map< VO, VI > & fmap()
static RooCFunction1Map< VO, VI > * _fmap
RooCFunction1Ref(VO(*ptr)(VI)=nullptr)
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 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(* CFUNCD1D)(double)
double(* CFUNCD1I)(Int_t)
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)