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 "RooAbsCategory.h"
18#include "TF3.h"
19
20using namespace std;
21
23
24////////////////////////////////////////////////////////////////////////////////
25
26RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* func, const RooArgList& list) :
27 RooAbsReal(name,title),
28 _olist("obs","obs",this),
29 _func(func)
30{
31 _olist.add(list) ;
32}
33
34////////////////////////////////////////////////////////////////////////////////
35
36RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* func, const RooArgList& obsList, const RooArgList& paramList) :
37 RooAbsReal(name,title),
38 _olist("obs","obs",this),
39 _plist("params","params",this),
40 _func(func)
41{
42 _olist.add(obsList) ;
43 _plist.add(paramList) ;
44}
45
46////////////////////////////////////////////////////////////////////////////////
47
49 RooAbsReal(other,name),
50 _olist("obs",this,other._olist),
51 _plist("params",this,other._plist),
52 _func(other._func)
53{
54}
55
56////////////////////////////////////////////////////////////////////////////////
57
59{
60 double x = _olist.at(0) ? ((RooAbsReal*)_olist.at(0))->getVal() : 0 ;
61 double y = _olist.at(1) ? ((RooAbsReal*)_olist.at(1))->getVal() : 0 ;
62 double z = _olist.at(2) ? ((RooAbsReal*)_olist.at(2))->getVal() : 0 ;
63 for (Int_t i=0 ; i<_func->GetNpar() ; i++) {
64 _func->SetParameter(i,_plist.at(i)?((RooAbsReal*)_plist.at(i))->getVal() : 0) ;
65 }
66 return _func->Eval(x,y,z) ;
67}
68
69////////////////////////////////////////////////////////////////////////////////
70
71void RooTFnBinding::printArgs(ostream& os) const
72{
73 // Print object arguments and name/address of function pointer
74 os << "[ TFn={" << _func->GetName() << "=" << _func->GetTitle() << "} " ;
75 for (Int_t i=0 ; i<numProxies() ; i++) {
76 RooAbsProxy* p = getProxy(i) ;
77 if (!TString(p->name()).BeginsWith("!")) {
78 p->print(os) ;
79 os << " " ;
80 }
81 }
82 os << "]" ;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86
87namespace RooFit {
88 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
90 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x) ;
91 }
92 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
94 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y)) ;
95 }
96 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
98 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z)) ;
99 }
100 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
102 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x,params) ;
103 }
104 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
106 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y),params) ;
107 }
108 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
110 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z),params) ;
111 }
112
113}
#define ClassImp(name)
Definition: Rtypes.h:375
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition: TGX11.cxx:110
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1339
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1326
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:33
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
double 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
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
Use TF1, TF2, TF3 functions as RooFit objects.
Definition: RooTFnBinding.h:16
double evaluate() const override
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 override
Interface for printing of object arguments.
RooListProxy _olist
Definition: RooTFnBinding.h:29
1-Dim function class
Definition: TF1.h:213
virtual Int_t GetNpar() const
Definition: TF1.h:486
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:1459
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:639
A 2-Dim function with parameters.
Definition: TF2.h:29
A 3-Dim function with parameters.
Definition: TF3.h:28
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
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...
Definition: Common.h:18
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)