Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22RooDerivative represents the first, second, or third order derivative
23of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24derivator 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
44
45using namespace std;
46
48
49
50
51////////////////////////////////////////////////////////////////////////////////
52/// Default constructor
53
54RooDerivative::RooDerivative() : _order(1), _eps(1e-7), _ftor(0), _rd(0)
55{
56}
57
58
59
60////////////////////////////////////////////////////////////////////////////////
61
62RooDerivative::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
79RooDerivative::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
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) {
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
148Bool_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}
#define e(i)
Definition RSha256.hxx:103
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
User class for calculating the derivatives of a function.
double Derivative2(double x)
Returns the second derivative of the function at point x, computed by Richardson's extrapolation meth...
double Derivative3(double x)
Returns the third derivative of the function at point x, computed by Richardson's extrapolation metho...
double Derivative1(double x)
Returns the first derivative of the function at point x, computed by Richardson's extrapolation metho...
Template class to wrap any C++ callable object which takes one argument i.e.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
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...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooDerivative represents the first, second, or third order derivative of any RooAbsReal as calculated...
virtual ~RooDerivative()
Destructor.
ROOT::Math::RichardsonDerivator * _rd
Functor binding of RooAbsReal.
RooFunctor * _ftor
Double_t evaluate() const
Derivator
RooDerivative()
Default constructor.
RooSetProxy _nset
Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Zap functor and derivator ;.
RooRealProxy _func
RooRealProxy _x
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
double min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
double max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
const T & arg() const
Return reference to object held in proxy.
Double_t x[n]
Definition legend1.C:17