Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooTFnBinding.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 *
4 * Copyright (c) 2023, CERN
5 *
6 * Redistribution and use in source and binary forms,
7 * with or without modification, are permitted according to the terms
8 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
9 */
10
11/** \class RooTFnBinding
12 \ingroup Roofit
13 Use TF1, TF2, TF3 functions as RooFit objects. To create a function binding,
14 either directly invoke RooTFnBinding::RooTFnBinding() or use the convenience
15 functions RooFit::bindFunction().
16**/
17
18#include "Riostream.h"
19
20#include "RooTFnBinding.h"
21#include "RooAbsCategory.h"
22#include "TF3.h"
23
24using std::ostream;
25
26
27////////////////////////////////////////////////////////////////////////////////
28
29RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* func, const RooArgList& list) :
30 RooAbsReal(name,title),
31 _olist("obs","obs",this),
32 _func(func)
33{
34 _olist.add(list) ;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38
39RooTFnBinding::RooTFnBinding(const char *name, const char *title, TF1* func, const RooArgList& obsList, const RooArgList& paramList) :
40 RooAbsReal(name,title),
41 _olist("obs","obs",this),
42 _plist("params","params",this),
43 _func(func)
44{
46 _plist.add(paramList) ;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50
53 _olist("obs",this,other._olist),
54 _plist("params",this,other._plist),
55 _func(other._func)
56{
57}
58
59////////////////////////////////////////////////////////////////////////////////
60
62{
63 double x = _olist.at(0) ? (static_cast<RooAbsReal*>(_olist.at(0)))->getVal() : 0 ;
64 double y = _olist.at(1) ? (static_cast<RooAbsReal*>(_olist.at(1)))->getVal() : 0 ;
65 double z = _olist.at(2) ? (static_cast<RooAbsReal*>(_olist.at(2)))->getVal() : 0 ;
66 for (Int_t i=0 ; i<_func->GetNpar() ; i++) {
67 _func->SetParameter(i,_plist.at(i)?(static_cast<RooAbsReal*>(_plist.at(i)))->getVal() : 0) ;
68 }
69 return _func->Eval(x,y,z) ;
70}
71
72////////////////////////////////////////////////////////////////////////////////
73
74void RooTFnBinding::printArgs(ostream& os) const
75{
76 // Print object arguments and name/address of function pointer
77 os << "[ TFn={" << _func->GetName() << "=" << _func->GetTitle() << "} " ;
78 for (Int_t i=0 ; i<numProxies() ; i++) {
79 RooAbsProxy* p = getProxy(i) ;
80 if (!TString(p->name()).BeginsWith("!")) {
81 p->print(os) ;
82 os << " " ;
83 }
84 }
85 os << "]" ;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89
90namespace RooFit {
91 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
93 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x) ;
94 }
95 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
97 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y)) ;
98 }
99 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
101 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z)) ;
102 }
103 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
105 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,x,params) ;
106 }
107 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
109 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y),params) ;
110 }
111 /// Bind a TFx function to RooFit variables. Also see RooTFnBinding.
113 return new RooTFnBinding(func->GetName(),func->GetTitle(),func,RooArgList(x,y,z),params) ;
114 }
115
116}
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:110
Int_t numProxies() const
Return the number of registered proxies.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Abstract interface for proxy classes.
Definition RooAbsProxy.h:37
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
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.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooListProxy _plist
RooTFnBinding()=default
void printArgs(std::ostream &os) const override
Print object arguments, ie its proxies.
RooListProxy _olist
1-Dim function class
Definition TF1.h:233
virtual Int_t GetNpar() const
Definition TF1.h:509
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:1439
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:667
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:139
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:623
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 CodegenImpl.h:64
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)