Logo ROOT  
Reference Guide
RooTFnBinding.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * *
4 * This code was autogenerated by RooClassFactory *
5 *****************************************************************************/
6
7/** \class RooTFnBinding
8 \ingroup Roofit
9 Use TF1, TF2, TF3 functions as RooFit objects. To create a function binding,
10 either directly invoke RooTFnBinding::RooTFnBinding() or use the convenience
11 functions RooFit::bindFunction().
12**/
13
14#include "Riostream.h"
15
16#include "RooTFnBinding.h"
17#include "RooAbsReal.h"
18#include "RooAbsCategory.h"
19#include "TF3.h"
20
21using namespace std;
22
24
25////////////////////////////////////////////////////////////////////////////////
26
27RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* func, const RooArgList& list) :
28 RooAbsReal(name,title),
29 _olist("obs","obs",this),
30 _func(func)
31{
32 _olist.add(list) ;
33}
34
35////////////////////////////////////////////////////////////////////////////////
36
37RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* func, const RooArgList& obsList, const RooArgList& paramList) :
38 RooAbsReal(name,title),
39 _olist("obs","obs",this),
40 _plist("params","params",this),
41 _func(func)
42{
43 _olist.add(obsList) ;
44 _plist.add(paramList) ;
45}
46
47////////////////////////////////////////////////////////////////////////////////
48
50 RooAbsReal(other,name),
51 _olist("obs",this,other._olist),
52 _plist("params",this,other._plist),
53 _func(other._func)
54{
55}
56
57////////////////////////////////////////////////////////////////////////////////
58
60{
61 Double_t x = _olist.at(0) ? ((RooAbsReal*)_olist.at(0))->getVal() : 0 ;
62 Double_t y = _olist.at(1) ? ((RooAbsReal*)_olist.at(1))->getVal() : 0 ;
63 Double_t z = _olist.at(2) ? ((RooAbsReal*)_olist.at(2))->getVal() : 0 ;
64 for (Int_t i=0 ; i<_func->GetNpar() ; i++) {
65 _func->SetParameter(i,_plist.at(i)?((RooAbsReal*)_plist.at(i))->getVal() : 0) ;
66 }
67 return _func->Eval(x,y,z) ;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71
72void RooTFnBinding::printArgs(ostream& os) const
73{
74 // Print object arguments and name/address of function pointer
75 os << "[ TFn={" << _func->GetName() << "=" << _func->GetTitle() << "} " ;
76 for (Int_t i=0 ; i<numProxies() ; i++) {
77 RooAbsProxy* p = getProxy(i) ;
78 if (!TString(p->name()).BeginsWith("!")) {
79 p->print(os) ;
80 os << " " ;
81 }
82 }
83 os << "]" ;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87
88namespace RooFit {
89 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
91 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x) ;
92 }
93 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
95 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y)) ;
96 }
97 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
99 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z)) ;
100 }
101 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
103 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x,params) ;
104 }
105 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
107 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y),params) ;
108 }
109 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
111 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z),params) ;
112 }
113
114}
int Int_t
Definition: RtypesCore.h:45
double Double_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:364
char name[80]
Definition: TGX11.cxx:110
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1327
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1314
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:30
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print proxy name.
Definition: RooAbsProxy.cxx:74
virtual const char * name() const
Definition: RooAbsProxy.h:40
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:110
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
Use TF1, TF2, TF3 functions as RooFit objects.
Definition: RooTFnBinding.h:16
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooListProxy _plist
Definition: RooTFnBinding.h:30
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
RooListProxy _olist
Definition: RooTFnBinding.h:29
1-Dim function class
Definition: TF1.h:213
virtual Int_t GetNpar() const
Definition: TF1.h:481
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1440
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:634
A 2-Dim function with parameters.
Definition: TF2.h:29
A 3-Dim function with parameters.
Definition: TF3.h:28
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:136
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:615
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)