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#include "Riostream.h"
28#include <math.h>
29
30#include "RooDerivative.h"
31#include "RooAbsReal.h"
32#include "RooAbsPdf.h"
33#include "RooErrorHandler.h"
34#include "RooArgSet.h"
35#include "RooMsgService.h"
36#include "RooRealVar.h"
37#include "RooFunctor.h"
38
41
42using namespace std;
43
45
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Default constructor
50
51RooDerivative::RooDerivative() : _order(1), _eps(1e-7), _ftor(0), _rd(0)
52{
53}
54
55
56
57////////////////////////////////////////////////////////////////////////////////
58
59RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, double epsIn) :
60 RooAbsReal(name, title),
61 _order(orderIn),
62 _eps(epsIn),
63 _nset("nset","nset",this,false,false),
64 _func("function","function",this,func),
65 _x("x","x",this,x),
66 _ftor(0),
67 _rd(0)
68{
69 if (_order<0 || _order>3 ) {
70 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75
76RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, double epsIn) :
77 RooAbsReal(name, title),
78 _order(orderIn),
79 _eps(epsIn),
80 _nset("nset","nset",this,false,false),
81 _func("function","function",this,func),
82 _x("x","x",this,x),
83 _ftor(0),
84 _rd(0)
85{
86 if (_order<0 || _order>3) {
87 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
88 }
89 _nset.add(nset) ;
90}
91
92
93
94////////////////////////////////////////////////////////////////////////////////
95
97 RooAbsReal(other, name),
98 _order(other._order),
99 _eps(other._eps),
100 _nset("nset",this,other._nset),
101 _func("function",this,other._func),
102 _x("x",this,other._x),
103 _ftor(0),
104 _rd(0)
105{
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Destructor
112
114{
115 if (_rd) delete _rd ;
116 if (_ftor) delete _ftor ;
117}
118
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Calculate value
123
125{
126 if (!_ftor) {
129 _rd = new ROOT::Math::RichardsonDerivator(wf,_eps*(_x.max()-_x.min()),true) ;
130 }
131
132 switch (_order) {
133 case 1: return _rd->Derivative1(_x);
134 case 2: return _rd->Derivative2(_x);
135 case 3: return _rd->Derivative3(_x);
136 }
137 return 0 ;
138}
139
140
141
142////////////////////////////////////////////////////////////////////////////////
143/// Zap functor and derivator ;
144
145bool RooDerivative::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive)
146{
147 delete _ftor ;
148 delete _rd ;
149 _ftor = 0 ;
150 _rd = 0 ;
151 return RooAbsReal::redirectServersHook(newServerList, mustReplaceAll, nameChange, isRecursive);
152}
#define e(i)
Definition RSha256.hxx:103
RooAbsReal * _func
Definition RooMinuit.h:90
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
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:62
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
A buffer for reading values from trees.
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:55
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
RooDerivative represents the first, second, or third order derivative of any RooAbsReal as calculated...
~RooDerivative() override
Destructor.
ROOT::Math::RichardsonDerivator * _rd
! Derivator
RooFunctor * _ftor
! Functor binding of RooAbsReal
RooDerivative()
Default constructor.
double _eps
Precision.
RooSetProxy _nset
Normalization set (optional)
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Zap functor and derivator ;.
Int_t _order
Derivation order.
double evaluate() const override
Calculate value.
RooRealProxy _func
Input function.
RooRealProxy _x
Observable.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
double max(const char *rname=nullptr) 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 min(const char *rname=nullptr) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
Double_t x[n]
Definition legend1.C:17