Logo ROOT  
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 <math.h>
32 
33 #include "RooDerivative.h"
34 #include "RooAbsReal.h"
35 #include "RooAbsPdf.h"
36 #include "RooErrorHandler.h"
37 #include "RooArgSet.h"
38 #include "RooMsgService.h"
39 #include "RooRealVar.h"
40 #include "RooFunctor.h"
41 
42 #include "Math/WrappedFunction.h"
44 
45 using namespace std;
46 
48 
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default constructor
53 
54 RooDerivative::RooDerivative() : _order(1), _eps(1e-7), _ftor(0), _rd(0)
55 {
56 }
57 
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 
62 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Double_t epsIn) :
63  RooAbsReal(name, title),
64  _order(orderIn),
65  _eps(epsIn),
66  _nset("nset","nset",this,kFALSE,kFALSE),
67  _func("function","function",this,func),
68  _x("x","x",this,x),
69  _ftor(0),
70  _rd(0)
71 {
72  if (_order<0 || _order>3 ) {
73  throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
74  }
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 
79 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, Double_t epsIn) :
80  RooAbsReal(name, title),
81  _order(orderIn),
82  _eps(epsIn),
83  _nset("nset","nset",this,kFALSE,kFALSE),
84  _func("function","function",this,func),
85  _x("x","x",this,x),
86  _ftor(0),
87  _rd(0)
88 {
89  if (_order<0 || _order>3) {
90  throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
91  }
92  _nset.add(nset) ;
93 }
94 
95 
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 
99 RooDerivative::RooDerivative(const RooDerivative& other, const char* name) :
100  RooAbsReal(other, name),
101  _order(other._order),
102  _eps(other._eps),
103  _nset("nset",this,other._nset),
104  _func("function",this,other._func),
105  _x("x",this,other._x),
106  _ftor(0),
107  _rd(0)
108 {
109 }
110 
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Destructor
115 
117 {
118  if (_rd) delete _rd ;
119  if (_ftor) delete _ftor ;
120 }
121 
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Calculate value
126 
128 {
129  if (!_ftor) {
130  _ftor = _func.arg().functor(_x.arg(),RooArgSet(),_nset) ;
133  }
134 
135  switch (_order) {
136  case 1: return _rd->Derivative1(_x);
137  case 2: return _rd->Derivative2(_x);
138  case 3: return _rd->Derivative3(_x);
139  }
140  return 0 ;
141 }
142 
143 
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Zap functor and derivator ;
147 
148 Bool_t RooDerivative::redirectServersHook(const RooAbsCollection& /*newServerList*/, Bool_t /*mustReplaceAll*/, Bool_t /*nameChange*/, Bool_t /*isRecursive*/)
149 {
150  delete _ftor ;
151  delete _rd ;
152  _ftor = 0 ;
153  _rd = 0 ;
154  return kFALSE ;
155 }
RooDerivative::_eps
Double_t _eps
Definition: RooDerivative.h:51
RooSetProxy::add
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...
Definition: RooSetProxy.cxx:165
RooDerivative::_order
Int_t _order
Definition: RooDerivative.h:50
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
ROOT::Math::WrappedFunction
Template class to wrap any C++ callable object which takes one argument i.e.
Definition: WrappedFunction.h:94
e
#define e(i)
Definition: RSha256.hxx:121
RooAbsReal.h
RooMsgService.h
RooDerivative::_x
RooRealProxy _x
Definition: RooDerivative.h:54
RooDerivative::RooDerivative
RooDerivative()
Default constructor.
Definition: RooDerivative.cxx:54
RooFit.h
RooDerivative
Definition: RooDerivative.h:31
RooTemplateProxy::arg
const T & arg() const
Return reference to object held in proxy.
Definition: RooTemplateProxy.h:271
RooAbsReal::functor
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...
Definition: RooAbsReal.cxx:4148
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooDerivative::_nset
RooSetProxy _nset
Definition: RooDerivative.h:52
ROOT::Math::RichardsonDerivator::Derivative2
double Derivative2(double x)
Returns the second derivative of the function at point x, computed by Richardson's extrapolation meth...
Definition: RichardsonDerivator.h:172
RooDerivative::~RooDerivative
virtual ~RooDerivative()
Destructor.
Definition: RooDerivative.cxx:116
RooDerivative::_ftor
RooFunctor * _ftor
Definition: RooDerivative.h:55
RichardsonDerivator.h
x
Double_t x[n]
Definition: legend1.C:17
ROOT::Math::RichardsonDerivator
User class for calculating the derivatives of a function.
Definition: RichardsonDerivator.h:55
RooAbsReal
Definition: RooAbsReal.h:61
ROOT::Math::RichardsonDerivator::Derivative1
double Derivative1(double x)
Returns the first derivative of the function at point x, computed by Richardson's extrapolation metho...
Definition: RichardsonDerivator.h:116
bool
RooDerivative.h
RooAbsPdf.h
RooTemplateProxy::min
double min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
Definition: RooTemplateProxy.h:287
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooAbsCollection
Definition: RooAbsCollection.h:30
RooRealVar.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooDerivative::evaluate
Double_t evaluate() const
Derivator
Definition: RooDerivative.cxx:127
name
char name[80]
Definition: TGX11.cxx:110
RooDerivative::_func
RooRealProxy _func
Definition: RooDerivative.h:53
RooErrorHandler.h
RooTemplateProxy::max
double max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
Definition: RooTemplateProxy.h:289
WrappedFunction.h
RooFunctor.h
RooRealVar
Definition: RooRealVar.h:35
RooDerivative::_rd
ROOT::Math::RichardsonDerivator * _rd
Functor binding of RooAbsReal.
Definition: RooDerivative.h:56
RooDerivative::redirectServersHook
Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Zap functor and derivator ;.
Definition: RooDerivative.cxx:148
Riostream.h
ROOT::Math::RichardsonDerivator::Derivative3
double Derivative3(double x)
Returns the third derivative of the function at point x, computed by Richardson's extrapolation metho...
Definition: RichardsonDerivator.h:211
RooArgSet
Definition: RooArgSet.h:28
int