ROOT  6.06/09
Reference Guide
RooDerivative.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //////////////////////////////////////////////////////////////////////////////
18 //
19 // BEGIN_HTML
20 // RooDerivative represents the first, second, or third order derivative
21 // of any RooAbsReal as calculated (numerically) by the MathCore Richardson
22 // derivator class.
23 // END_HTML
24 //
25 
26 
27 #include "RooFit.h"
28 
29 #include "Riostream.h"
30 #include "Riostream.h"
31 #include <math.h>
32 #include <string>
33 
34 #include "RooDerivative.h"
35 #include "RooAbsReal.h"
36 #include "RooAbsPdf.h"
37 #include "RooErrorHandler.h"
38 #include "RooArgSet.h"
39 #include "RooMsgService.h"
40 #include "RooRealVar.h"
41 #include "RooFunctor.h"
42 
43 #include "Math/WrappedFunction.h"
45 
46 using namespace std;
47 
49 ;
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Default constructor
54 
55 RooDerivative::RooDerivative() : _order(1), _eps(1e-7), _ftor(0), _rd(0)
56 {
57 }
58 
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 
63 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Double_t epsIn) :
64  RooAbsReal(name, title),
65  _order(orderIn),
66  _eps(epsIn),
67  _nset("nset","nset",this,kFALSE,kFALSE),
68  _func("function","function",this,func),
69  _x("x","x",this,x),
70  _ftor(0),
71  _rd(0)
72 {
73  if (_order<0 || _order>3 ) {
74  throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
75  }
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 
80 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, Double_t epsIn) :
81  RooAbsReal(name, title),
82  _order(orderIn),
83  _eps(epsIn),
84  _nset("nset","nset",this,kFALSE,kFALSE),
85  _func("function","function",this,func),
86  _x("x","x",this,x),
87  _ftor(0),
88  _rd(0)
89 {
90  if (_order<0 || _order>3) {
91  throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
92  }
93  _nset.add(nset) ;
94 }
95 
96 
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 
100 RooDerivative::RooDerivative(const RooDerivative& other, const char* name) :
101  RooAbsReal(other, name),
102  _order(other._order),
103  _eps(other._eps),
104  _nset("nset",this,other._nset),
105  _func("function",this,other._func),
106  _x("x",this,other._x),
107  _ftor(0),
108  _rd(0)
109 {
110 }
111 
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Destructor
116 
118 {
119  if (_rd) delete _rd ;
120  if (_ftor) delete _ftor ;
121 }
122 
123 
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Calculate value
127 
129 {
130  if (!_ftor) {
131  _ftor = _func.arg().functor(_x.arg(),RooArgSet(),_nset) ;
134  }
135 
136  switch (_order) {
137  case 1: return _rd->Derivative1(_x);
138  case 2: return _rd->Derivative2(_x);
139  case 3: return _rd->Derivative3(_x);
140  }
141  return 0 ;
142 }
143 
144 
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Zap functor and derivator ;
148 
149 Bool_t RooDerivative::redirectServersHook(const RooAbsCollection& /*newServerList*/, Bool_t /*mustReplaceAll*/, Bool_t /*nameChange*/, Bool_t /*isRecursive*/)
150 {
151  delete _ftor ;
152  delete _rd ;
153  _ftor = 0 ;
154  _rd = 0 ;
155  return kFALSE ;
156 }
double Derivative3(double x)
Returns the third derivative of the function at point x, computed by Richardson's extrapolation metho...
Double_t evaluate() const
Derivator.
RooDerivative()
Default constructor.
Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Zap functor and derivator ;.
RooRealProxy _x
Definition: RooDerivative.h:54
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
double Derivative2(double x)
Returns the second derivative of the function at point x, computed by Richardson's extrapolation meth...
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
RooRealProxy _func
Definition: RooDerivative.h:53
Template class to wrap any C++ callable object which takes one argument i.e.
RooFunctor * _ftor
Definition: RooDerivative.h:55
RooSetProxy _nset
Definition: RooDerivative.h:52
Double_t x[n]
Definition: legend1.C:17
double Derivative1(double x)
Returns the first derivative of the function at point x, computed by Richardson's extrapolation metho...
friend class RooArgSet
Definition: RooAbsArg.h:469
ClassImp(RooDerivative)
Double_t _eps
Definition: RooDerivative.h:51
char * Form(const char *fmt,...)
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual ~RooDerivative()
Destructor.
double func(double *x, double *p)
Definition: stressTF1.cxx:213
#define name(a, b)
Definition: linkTestLib0.cpp:5
ROOT::Math::RichardsonDerivator * _rd
Functor binding of RooAbsReal.
Definition: RooDerivative.h:56
Double_t min(const char *rname=0) const
Definition: RooRealProxy.h:56
RooFunctor * functor(const RooArgList &obs, const RooArgList &pars=RooArgList(), const RooArgSet &nset=RooArgSet()) const
Return a RooFunctor object bound to this RooAbsReal with given definition of observables and paramete...
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t max(const char *rname=0) const
Definition: RooRealProxy.h:57
User class for calculating the derivatives of a function.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...