Logo ROOT   6.08/07
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 \file RooDerivative.cxx
19 \class RooDerivative
20 \ingroup Roofitcore
21 
22 RooDerivative represents the first, second, or third order derivative
23 of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24 derivator class.
25 **/
26 
27 
28 #include "RooFit.h"
29 
30 #include "Riostream.h"
31 #include "Riostream.h"
32 #include <math.h>
33 #include <string>
34 
35 #include "RooDerivative.h"
36 #include "RooAbsReal.h"
37 #include "RooAbsPdf.h"
38 #include "RooErrorHandler.h"
39 #include "RooArgSet.h"
40 #include "RooMsgService.h"
41 #include "RooRealVar.h"
42 #include "RooFunctor.h"
43 
44 #include "Math/WrappedFunction.h"
46 
47 using namespace std;
48 
50 ;
51 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Default constructor
55 
56 RooDerivative::RooDerivative() : _order(1), _eps(1e-7), _ftor(0), _rd(0)
57 {
58 }
59 
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 
64 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Double_t epsIn) :
65  RooAbsReal(name, title),
66  _order(orderIn),
67  _eps(epsIn),
68  _nset("nset","nset",this,kFALSE,kFALSE),
69  _func("function","function",this,func),
70  _x("x","x",this,x),
71  _ftor(0),
72  _rd(0)
73 {
74  if (_order<0 || _order>3 ) {
75  throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
76  }
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 
81 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, Double_t epsIn) :
82  RooAbsReal(name, title),
83  _order(orderIn),
84  _eps(epsIn),
85  _nset("nset","nset",this,kFALSE,kFALSE),
86  _func("function","function",this,func),
87  _x("x","x",this,x),
88  _ftor(0),
89  _rd(0)
90 {
91  if (_order<0 || _order>3) {
92  throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
93  }
94  _nset.add(nset) ;
95 }
96 
97 
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 
101 RooDerivative::RooDerivative(const RooDerivative& other, const char* name) :
102  RooAbsReal(other, name),
103  _order(other._order),
104  _eps(other._eps),
105  _nset("nset",this,other._nset),
106  _func("function",this,other._func),
107  _x("x",this,other._x),
108  _ftor(0),
109  _rd(0)
110 {
111 }
112 
113 
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Destructor
117 
119 {
120  if (_rd) delete _rd ;
121  if (_ftor) delete _ftor ;
122 }
123 
124 
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Calculate value
128 
130 {
131  if (!_ftor) {
132  _ftor = _func.arg().functor(_x.arg(),RooArgSet(),_nset) ;
135  }
136 
137  switch (_order) {
138  case 1: return _rd->Derivative1(_x);
139  case 2: return _rd->Derivative2(_x);
140  case 3: return _rd->Derivative3(_x);
141  }
142  return 0 ;
143 }
144 
145 
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Zap functor and derivator ;
149 
150 Bool_t RooDerivative::redirectServersHook(const RooAbsCollection& /*newServerList*/, Bool_t /*mustReplaceAll*/, Bool_t /*nameChange*/, Bool_t /*isRecursive*/)
151 {
152  delete _ftor ;
153  delete _rd ;
154  _ftor = 0 ;
155  _rd = 0 ;
156  return kFALSE ;
157 }
double Derivative3(double x)
Returns the third derivative of the function at point x, computed by Richardson&#39;s extrapolation metho...
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&#39;s extrapolation meth...
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&#39;s extrapolation metho...
Double_t evaluate() const
Derivator.
friend class RooArgSet
Definition: RooAbsArg.h:469
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
Double_t _eps
Definition: RooDerivative.h:51
char * Form(const char *fmt,...)
#define ClassImp(name)
Definition: Rtypes.h:279
Double_t min(const char *rname=0) const
Definition: RooRealProxy.h:56
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
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
ROOT::Math::RichardsonDerivator * _rd
Functor binding of RooAbsReal.
Definition: RooDerivative.h:56
RooDerivative represents the first, second, or third order derivative of any RooAbsReal as calculated...
Definition: RooDerivative.h:31
Double_t max(const char *rname=0) const
Definition: RooRealProxy.h:57
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 RooAbsReal & arg() const
Definition: RooRealProxy.h:43
const Bool_t kTRUE
Definition: Rtypes.h:91
User class for calculating the derivatives of a function.
char name[80]
Definition: TGX11.cxx:109
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts &#39;var&#39; into set and registers &#39;var&#39; as server to owner with...