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 <cmath>
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
52
53////////////////////////////////////////////////////////////////////////////////
54
55RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, double epsIn) :
56 RooAbsReal(name, title),
57 _order(orderIn),
58 _eps(epsIn),
59 _nset("nset","nset",this,false,false),
60 _func("function","function",this,func),
61 _x("x","x",this,x)
62{
63 if (_order<0 || _order>3 ) {
64 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
65 }
66}
67
68////////////////////////////////////////////////////////////////////////////////
69
70RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, double epsIn) :
71 RooAbsReal(name, title),
72 _order(orderIn),
73 _eps(epsIn),
74 _nset("nset","nset",this,false,false),
75 _func("function","function",this,func),
76 _x("x","x",this,x)
77{
78 if (_order<0 || _order>3) {
79 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
80 }
81 _nset.add(nset) ;
82}
83
84
85
86////////////////////////////////////////////////////////////////////////////////
87
89 RooAbsReal(other, name),
90 _order(other._order),
91 _eps(other._eps),
92 _nset("nset",this,other._nset),
93 _func("function",this,other._func),
94 _x("x",this,other._x)
95{
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Destructor
102
104{
105 if (_rd) delete _rd ;
106 if (_ftor) delete _ftor ;
107}
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Calculate value
113
115{
116 if (!_ftor) {
119 _rd = new ROOT::Math::RichardsonDerivator(wf,_eps*(_x.max()-_x.min()),true) ;
120 }
121
122 switch (_order) {
123 case 1: return _rd->Derivative1(_x);
124 case 2: return _rd->Derivative2(_x);
125 case 3: return _rd->Derivative3(_x);
126 }
127 return 0 ;
128}
129
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Zap functor and derivator ;
134
135bool RooDerivative::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive)
136{
137 delete _ftor ;
138 delete _rd ;
139 _ftor = nullptr ;
140 _rd = nullptr ;
141 return RooAbsReal::redirectServersHook(newServerList, mustReplaceAll, nameChange, isRecursive);
142}
#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.
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Function that is called at the end of redirectServers().
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:37
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