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
00027 #include "RooFit.h"
00028
00029 #include "Riostream.h"
00030 #include "Riostream.h"
00031 #include <math.h>
00032 #include <string>
00033
00034 #include "RooDerivative.h"
00035 #include "RooAbsReal.h"
00036 #include "RooAbsPdf.h"
00037 #include "RooErrorHandler.h"
00038 #include "RooArgSet.h"
00039 #include "RooMsgService.h"
00040 #include "RooRealVar.h"
00041 #include "RooFunctor.h"
00042
00043 #include "Math/WrappedFunction.h"
00044 #include "Math/RichardsonDerivator.h"
00045
00046 ClassImp(RooDerivative)
00047 ;
00048
00049
00050
00051 RooDerivative::RooDerivative() : _ftor(0), _rd(0)
00052 {
00053
00054 }
00055
00056
00057
00058
00059 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Double_t epsIn) :
00060 RooAbsReal(name, title),
00061 _order(orderIn),
00062 _eps(epsIn),
00063 _nset("nset","nset",this,kFALSE,kFALSE),
00064 _func("function","function",this,func),
00065 _x("x","x",this,x),
00066 _ftor(0),
00067 _rd(0)
00068 {
00069 if (_order<0 || _order>3 ) {
00070 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
00071 }
00072 }
00073
00074
00075 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, Double_t epsIn) :
00076 RooAbsReal(name, title),
00077 _order(orderIn),
00078 _eps(epsIn),
00079 _nset("nset","nset",this,kFALSE,kFALSE),
00080 _func("function","function",this,func),
00081 _x("x","x",this,x),
00082 _ftor(0),
00083 _rd(0)
00084 {
00085 if (_order<0 || _order>3) {
00086 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
00087 }
00088 _nset.add(nset) ;
00089 }
00090
00091
00092
00093
00094 RooDerivative::RooDerivative(const RooDerivative& other, const char* name) :
00095 RooAbsReal(other, name),
00096 _order(other._order),
00097 _eps(other._eps),
00098 _nset("nset",this,other._nset),
00099 _func("function",this,other._func),
00100 _x("x",this,other._x),
00101 _ftor(0),
00102 _rd(0)
00103 {
00104 }
00105
00106
00107
00108
00109 RooDerivative::~RooDerivative()
00110 {
00111
00112 if (_rd) delete _rd ;
00113 if (_ftor) delete _ftor ;
00114 }
00115
00116
00117
00118
00119 Double_t RooDerivative::evaluate() const
00120 {
00121
00122 if (!_ftor) {
00123 _ftor = _func.arg().functor(_x.arg(),RooArgSet(),_nset) ;
00124 ROOT::Math::WrappedFunction<RooFunctor&> wf(*_ftor);
00125 _rd = new ROOT::Math::RichardsonDerivator(wf,_eps*(_x.max()-_x.min()),kTRUE) ;
00126 }
00127
00128 switch (_order) {
00129 case 1: return _rd->Derivative1(_x);
00130 case 2: return _rd->Derivative2(_x);
00131 case 3: return _rd->Derivative3(_x);
00132 }
00133 return 0 ;
00134 }
00135
00136
00137
00138
00139 Bool_t RooDerivative::redirectServersHook(const RooAbsCollection& , Bool_t , Bool_t , Bool_t )
00140 {
00141
00142 delete _ftor ;
00143 delete _rd ;
00144 _ftor = 0 ;
00145 _rd = 0 ;
00146 return kFALSE ;
00147 }