// Lightweight interface adaptor that exports a RooAbsPdf as a functor
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "RooFunctor.h"
#include "RooRealBinding.h"
#include "RooAbsReal.h"
#include "RooAbsPdf.h"
#include "RooArgSet.h"
#include <assert.h>
using namespace std;
ClassImp(RooFunctor)
;
RooFunctor::RooFunctor(const RooAbsFunc& func)
{
_ownBinding = kFALSE ;
_x = new Double_t[func.getDimension()] ;
_nobs = func.getDimension() ;
_npar = 0 ;
_binding = (RooAbsFunc*) &func ;
}
RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters)
{
_nset.add(observables) ;
RooArgList allVars(observables) ;
allVars.add(parameters) ;
_binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
_ownBinding = kTRUE ;
_x = new Double_t[allVars.getSize()] ;
_nobs = observables.getSize() ;
_npar = parameters.getSize() ;
}
RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters, const RooArgSet& nset)
{
_nset.add(nset) ;
RooArgList allVars(observables) ;
allVars.add(parameters) ;
_binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
_ownBinding = kTRUE ;
_x = new Double_t[allVars.getSize()] ;
_nobs = observables.getSize() ;
_npar = parameters.getSize() ;
}
RooFunctor::RooFunctor(const RooFunctor& other) :
_ownBinding(other._ownBinding),
_nset(other._nset),
_binding(0),
_npar(other._npar),
_nobs(other._nobs)
{
if (other._ownBinding) {
_binding = new RooRealBinding((RooRealBinding&)*other._binding,&_nset) ;
} else {
_binding = other._binding ;
}
_x = new Double_t[_nobs+_npar] ;
}
RooFunctor::~RooFunctor()
{
if (_ownBinding) delete _binding ;
delete[] _x ;
}
Double_t RooFunctor::eval(const Double_t *x) const
{
return (*_binding)(x) ;
}
Double_t RooFunctor::eval(Double_t x) const
{
return (*_binding)(&x) ;
}
Double_t RooFunctor::eval(const Double_t *x, const Double_t *p) const
{
for (int i=0 ; i<_nobs ; i++) {
_x[i] = x[i] ;
}
for (int i=0 ; i<_npar ; i++) {
_x[i+_nobs] = p[i] ;
}
return (*_binding)(_x) ;
}