Logo ROOT   6.16/01
Reference Guide
RooFunctorBinding.cxx
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/** \class RooFunctorBinding
14 \ingroup Roofit
15
16RooCFunction1Binding is a templated implementation of class RooAbsReal that binds
17generic C(++) functions to a RooAbsReal argument thus allowing generic C++
18functions to be used as RooFit functions. Instances of function binding
19classes are fully functional RooFit function objects with one exception:
20if the bound function is _not_ a standard TMath or MathMore function the
21class cannot be persisted in a RooWorkspace without registering the function
22pointer first using RooCFunction1Binding<T1,T2>::register().
23**/
24
25/** \class RooFunctorPdfBinding
26 \ingroup Roofit
27**/
28
29#include "Riostream.h"
30#include "RooFunctorBinding.h"
31
32using namespace std ;
33
36
37////////////////////////////////////////////////////////////////////////////////
38RooFunctorBinding::RooFunctorBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionMultiDim& ftor, const RooArgList& v) :
39 RooAbsReal(name,title),
40 func(&ftor),
41 vars("vars","vars",this)
42{
43 // Check that function dimension and number of variables match
44 if (ftor.NDim()!=UInt_t(v.getSize())) {
45 coutE(InputArguments) << "RooFunctorBinding::ctor(" << GetName() << ") ERROR number of provided variables (" << v.getSize()
46 << ") does not match dimensionality of function (" << ftor.NDim() << ")" << endl ;
47 throw string("RooFunctor::ctor ERROR") ;
48 }
49 x = new Double_t[func->NDim()] ;
50 vars.add(v) ;
51}
52
53////////////////////////////////////////////////////////////////////////////////
55 RooAbsReal(other,name),
56 func(other.func),
57 vars("vars",this,other.vars)
58{
59 // Copy constructor
60 x = new Double_t[func->NDim()] ;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64void RooFunctorBinding::printArgs(ostream& os) const {
65 // Print object arguments and name/address of function pointer
66 os << "[ function=" << func << " " ;
67 for (Int_t i=0 ; i<numProxies() ; i++) {
68 RooAbsProxy* p = getProxy(i) ;
69 if (!TString(p->name()).BeginsWith("!")) {
70 p->print(os) ;
71 os << " " ;
72 }
73 }
74 os << "]" ;
75}
76
77////////////////////////////////////////////////////////////////////////////////
79 // Return value of embedded function using value of referenced variable x
80 for (int i=0 ; i<vars.getSize() ; i++) {
81 x[i] = ((RooAbsReal*)vars.at(i))->getVal() ;
82 }
83 return (*func)(x) ;
84}
85
86////////////////////////////////////////////////////////////////////////////////
88 RooAbsPdf(name,title),
89 func(&ftor),
90 vars("vars","vars",this)
91{
92 // Check that function dimension and number of variables match
93 if (ftor.NDim()!=UInt_t(v.getSize())) {
94 coutE(InputArguments) << "RooFunctorPdfBinding::ctor(" << GetName() << ") ERROR number of provided variables (" << v.getSize()
95 << ") does not match dimensionality of function (" << ftor.NDim() << ")" << endl ;
96 throw string("RooFunctor::ctor ERROR") ;
97 }
98 x = new Double_t[func->NDim()] ;
99 vars.add(v) ;
100}
101
102////////////////////////////////////////////////////////////////////////////////
104 RooAbsPdf(other,name),
105 func(other.func),
106 vars("vars",this,other.vars)
107{
108 // Copy constructor
109 x = new Double_t[func->NDim()] ;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113void RooFunctorPdfBinding::printArgs(ostream& os) const {
114 // Print object arguments and name/address of function pointer
115 os << "[ function=" << func << " " ;
116 for (Int_t i=0 ; i<numProxies() ; i++) {
117 RooAbsProxy* p = getProxy(i) ;
118 if (!TString(p->name()).BeginsWith("!")) {
119 p->print(os) ;
120 os << " " ;
121 }
122 }
123 os << "]" ;
124}
125
126////////////////////////////////////////////////////////////////////////////////
128 // Return value of embedded function using value of referenced variable x
129 for (int i=0 ; i<vars.getSize() ; i++) {
130 x[i] = ((RooAbsReal*)vars.at(i))->getVal() ;
131 }
132 return (*func)(x) ;
133 }
134
135namespace RooFit {
136
138 return new RooFunctorBinding(name,name,ftor,vars) ;
139 }
140
141 RooAbsPdf* bindPdf(const char* name, const ROOT::Math::IBaseFunctionMultiDim& ftor, const RooArgList& vars) {
142 return new RooFunctorPdfBinding(name,name,ftor,vars) ;
143 }
144
145}
SVector< double, 2 > v
Definition: Dict.h:5
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:363
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1259
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1246
Int_t getSize() const
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:31
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print proxy name.
Definition: RooAbsProxy.cxx:75
virtual const char * name() const
Definition: RooAbsProxy.h:41
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Double_t getVal(const RooArgSet *set=0) const
Evaluate object. Returns either cached value or triggers a recalculation.
Definition: RooAbsReal.h:64
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
RooCFunction1Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
const ROOT::Math::IBaseFunctionMultiDim * func
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
const ROOT::Math::IBaseFunctionMultiDim * func
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
@ InputArguments
Definition: RooGlobalFunc.h:58
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
STL namespace.