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 
21 using namespace std;
22 
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 
27 RooTFnBinding::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 
37 RooTFnBinding::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 
49 RooTFnBinding::RooTFnBinding(const RooTFnBinding& other, const char* name) :
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 
72 void 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 
88 namespace 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.
102  RooAbsReal* bindFunction(TF1* func,RooAbsReal& x, const RooArgList& params) {
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 }
RooAbsProxy::print
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print proxy name.
Definition: RooAbsProxy.cxx:74
RooAbsArg::numProxies
Int_t numProxies() const
Return the number of registered proxies.
Definition: RooAbsArg.cxx:1243
RooTFnBinding::RooTFnBinding
RooTFnBinding()
Definition: RooTFnBinding.h:18
RooAbsReal.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
TF1::GetNpar
virtual Int_t GetNpar() const
Definition: TF1.h:477
RooArgList
Definition: RooArgList.h:21
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooAbsProxy::name
virtual const char * name() const
Definition: RooAbsProxy.h:54
x
Double_t x[n]
Definition: legend1.C:17
RooAbsReal
Definition: RooAbsReal.h:61
RooAbsArg::getProxy
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Definition: RooAbsArg.cxx:1230
RooArgList::at
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:88
TString
Definition: TString.h:136
RooTFnBinding::_plist
RooListProxy _plist
Definition: RooTFnBinding.h:30
TF1::SetParameter
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:630
RooFit::bindFunction
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
Definition: RooCFunction1Binding.cxx:59
TF3.h
RooTFnBinding.h
RooFit
Definition: RooCFunction1Binding.h:29
RooTFnBinding
Definition: RooTFnBinding.h:16
TF3
Definition: TF3.h:28
TString::BeginsWith
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:615
RooListProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Definition: RooListProxy.cxx:104
y
Double_t y[n]
Definition: legend1.C:17
RooTFnBinding::evaluate
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooTFnBinding.cxx:59
TF2
Definition: TF2.h:29
RooTFnBinding::_olist
RooListProxy _olist
Definition: RooTFnBinding.h:29
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsCategory.h
TF1::Eval
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:1450
name
char name[80]
Definition: TGX11.cxx:110
RooAbsProxy
Definition: RooAbsProxy.h:30
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
TF1
1-Dim function class
Definition: TF1.h:212
Riostream.h
RooTFnBinding::printArgs
void printArgs(std::ostream &os) const
Print object arguments, ie its proxies.
Definition: RooTFnBinding.cxx:72
RooTFnBinding::_func
TF1 * _func
Definition: RooTFnBinding.h:31
int