00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "RooFit.h"
00027 #include "Riostream.h"
00028
00029 #include "RooFunctor.h"
00030 #include "RooRealBinding.h"
00031 #include "RooAbsReal.h"
00032 #include "RooAbsPdf.h"
00033 #include "RooArgSet.h"
00034
00035 #include <assert.h>
00036
00037
00038
00039 ClassImp(RooFunctor)
00040 ;
00041
00042
00043
00044 RooFunctor::RooFunctor(const RooAbsFunc& func)
00045 {
00046 _ownBinding = kFALSE ;
00047
00048 _x = new Double_t[func.getDimension()] ;
00049
00050 _nobs = func.getDimension() ;
00051 _npar = 0 ;
00052 _binding = (RooAbsFunc*) &func ;
00053 }
00054
00055
00056
00057
00058 RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters)
00059 {
00060
00061 _nset.add(observables) ;
00062
00063
00064 RooArgList allVars(observables) ;
00065 allVars.add(parameters) ;
00066
00067
00068 _binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
00069 _ownBinding = kTRUE ;
00070
00071
00072 _x = new Double_t[allVars.getSize()] ;
00073 _nobs = observables.getSize() ;
00074 _npar = parameters.getSize() ;
00075 }
00076
00077
00078
00079 RooFunctor::RooFunctor(const RooAbsReal& func, const RooArgList& observables, const RooArgList& parameters, const RooArgSet& nset)
00080 {
00081
00082 _nset.add(nset) ;
00083
00084
00085 RooArgList allVars(observables) ;
00086 allVars.add(parameters) ;
00087
00088
00089 _binding = new RooRealBinding(func,allVars,&_nset,kFALSE,0) ;
00090 _ownBinding = kTRUE ;
00091
00092
00093 _x = new Double_t[allVars.getSize()] ;
00094 _nobs = observables.getSize() ;
00095 _npar = parameters.getSize() ;
00096 }
00097
00098
00099
00100
00101 RooFunctor::RooFunctor(const RooFunctor& other) :
00102 _ownBinding(other._ownBinding),
00103 _nset(other._nset),
00104 _binding(0),
00105 _npar(other._npar),
00106 _nobs(other._nobs)
00107 {
00108 if (other._ownBinding) {
00109 _binding = new RooRealBinding((RooRealBinding&)*other._binding,&_nset) ;
00110 } else {
00111 _binding = other._binding ;
00112 }
00113 _x = new Double_t[_nobs+_npar] ;
00114 }
00115
00116
00117
00118
00119
00120 RooFunctor::~RooFunctor()
00121 {
00122
00123 if (_ownBinding) delete _binding ;
00124 delete[] _x ;
00125 }
00126
00127
00128
00129
00130 Double_t RooFunctor::eval(const Double_t *x) const
00131 {
00132 return (*_binding)(x) ;
00133 }
00134
00135
00136 Double_t RooFunctor::eval(Double_t x) const
00137 {
00138 return (*_binding)(&x) ;
00139 }
00140
00141
00142 Double_t RooFunctor::eval(const Double_t *x, const Double_t *p) const
00143 {
00144 for (int i=0 ; i<_nobs ; i++) {
00145 _x[i] = x[i] ;
00146 }
00147 for (int i=0 ; i<_npar ; i++) {
00148 _x[i+_nobs] = p[i] ;
00149 }
00150 return (*_binding)(_x) ;
00151 }