// RooCFunction1Binding is a templated implementation of class RooAbsReal that binds
// generic C(++) functions to a RooAbsReal argument thus allowing generic C++
// functions to be used as RooFit functions. Instances of function binding
// classes are fully functional RooFit function objects with one exception:
// if the bound function is _not_ a standard TMath or MathMore function the
// class cannot be persisted in a RooWorkspace without registering the function
// pointer first using RooCFunction1Binding<T1,T2>::register().
// END_HTML
#include "Riostream.h"
#include "RooFunctorBinding.h"
using namespace std ;
ClassImp(RooFunctorBinding)
ClassImp(RooFunctorPdfBinding)
;
RooFunctorBinding::RooFunctorBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionMultiDim& ftor, const RooArgList& v) :
RooAbsReal(name,title),
func(&ftor),
vars("vars","vars",this)
{
if (ftor.NDim()!=UInt_t(v.getSize())) {
coutE(InputArguments) << "RooFunctorBinding::ctor(" << GetName() << ") ERROR number of provided variables (" << v.getSize()
<< ") does not match dimensionality of function (" << ftor.NDim() << ")" << endl ;
throw string("RooFunctor::ctor ERROR") ;
}
x = new Double_t[func->NDim()] ;
vars.add(v) ;
}
RooFunctorBinding::RooFunctorBinding(const RooFunctorBinding& other, const char* name) :
RooAbsReal(other,name),
func(other.func),
vars("vars",this,other.vars)
{
x = new Double_t[func->NDim()] ;
}
void RooFunctorBinding::printArgs(ostream& os) const {
os << "[ function=" << func << " " ;
for (Int_t i=0 ; i<numProxies() ; i++) {
RooAbsProxy* p = getProxy(i) ;
if (!TString(p->name()).BeginsWith("!")) {
p->print(os) ;
os << " " ;
}
}
os << "]" ;
}
Double_t RooFunctorBinding::evaluate() const {
for (int i=0 ; i<vars.getSize() ; i++) {
x[i] = ((RooAbsReal*)vars.at(i))->getVal() ;
}
return (*func)(x) ;
}
RooFunctorPdfBinding::RooFunctorPdfBinding(const char *name, const char *title, const ROOT::Math::IBaseFunctionMultiDim& ftor, const RooArgList& v) :
RooAbsPdf(name,title),
func(&ftor),
vars("vars","vars",this)
{
if (ftor.NDim()!=UInt_t(v.getSize())) {
coutE(InputArguments) << "RooFunctorPdfBinding::ctor(" << GetName() << ") ERROR number of provided variables (" << v.getSize()
<< ") does not match dimensionality of function (" << ftor.NDim() << ")" << endl ;
throw string("RooFunctor::ctor ERROR") ;
}
x = new Double_t[func->NDim()] ;
vars.add(v) ;
}
RooFunctorPdfBinding::RooFunctorPdfBinding(const RooFunctorPdfBinding& other, const char* name) :
RooAbsPdf(other,name),
func(other.func),
vars("vars",this,other.vars)
{
x = new Double_t[func->NDim()] ;
}
void RooFunctorPdfBinding::printArgs(ostream& os) const {
os << "[ function=" << func << " " ;
for (Int_t i=0 ; i<numProxies() ; i++) {
RooAbsProxy* p = getProxy(i) ;
if (!TString(p->name()).BeginsWith("!")) {
p->print(os) ;
os << " " ;
}
}
os << "]" ;
}
Double_t RooFunctorPdfBinding::evaluate() const {
for (int i=0 ; i<vars.getSize() ; i++) {
x[i] = ((RooAbsReal*)vars.at(i))->getVal() ;
}
return (*func)(x) ;
}
namespace RooFit {
RooAbsReal* bindFunction(const char* name, const ROOT::Math::IBaseFunctionMultiDim& ftor,const RooArgList& vars) {
return new RooFunctorBinding(name,name,ftor,vars) ;
}
RooAbsPdf* bindPdf(const char* name, const ROOT::Math::IBaseFunctionMultiDim& ftor, const RooArgList& vars) {
return new RooFunctorPdfBinding(name,name,ftor,vars) ;
}
}
RooFunctorBinding.cxx:100 RooFunctorBinding.cxx:101 RooFunctorBinding.cxx:102 RooFunctorBinding.cxx:103 RooFunctorBinding.cxx:104 RooFunctorBinding.cxx:105 RooFunctorBinding.cxx:106 RooFunctorBinding.cxx:107 RooFunctorBinding.cxx:108 RooFunctorBinding.cxx:109 RooFunctorBinding.cxx:110 RooFunctorBinding.cxx:111 RooFunctorBinding.cxx:112 RooFunctorBinding.cxx:113 RooFunctorBinding.cxx:114 RooFunctorBinding.cxx:115 RooFunctorBinding.cxx:116 RooFunctorBinding.cxx:117 RooFunctorBinding.cxx:118 RooFunctorBinding.cxx:119 RooFunctorBinding.cxx:120 RooFunctorBinding.cxx:121 RooFunctorBinding.cxx:122 RooFunctorBinding.cxx:123 RooFunctorBinding.cxx:124 RooFunctorBinding.cxx:125 RooFunctorBinding.cxx:126 RooFunctorBinding.cxx:127 RooFunctorBinding.cxx:128 RooFunctorBinding.cxx:129 RooFunctorBinding.cxx:130 RooFunctorBinding.cxx:131 RooFunctorBinding.cxx:132 RooFunctorBinding.cxx:133 RooFunctorBinding.cxx:134 RooFunctorBinding.cxx:135 RooFunctorBinding.cxx:136 RooFunctorBinding.cxx:137 RooFunctorBinding.cxx:138 RooFunctorBinding.cxx:139 RooFunctorBinding.cxx:140 RooFunctorBinding.cxx:141 RooFunctorBinding.cxx:142 RooFunctorBinding.cxx:143 RooFunctorBinding.cxx:144 RooFunctorBinding.cxx:145 RooFunctorBinding.cxx:146 RooFunctorBinding.cxx:147 RooFunctorBinding.cxx:148 RooFunctorBinding.cxx:149 RooFunctorBinding.cxx:150