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
22Represents 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
43
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Default constructor
48
50
51////////////////////////////////////////////////////////////////////////////////
52
53RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, double epsIn) :
54 RooAbsReal(name, title),
55 _order(orderIn),
56 _eps(epsIn),
57 _nset("nset","nset",this,false,false),
58 _func("function","function",this,func),
59 _x("x","x",this,x)
60{
61 if (_order<0 || _order>3 ) {
62 throw std::runtime_error(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
63 }
64}
65
66////////////////////////////////////////////////////////////////////////////////
67
68RooDerivative::RooDerivative(const char *name, const char *title, RooAbsReal &func, RooRealVar &x,
69 const RooArgSet &nset, Int_t orderIn, double epsIn)
70 : RooDerivative(name, title, func, x, orderIn, epsIn)
71{
72 _nset.add(nset);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76
78 RooAbsReal(other, name),
79 _order(other._order),
80 _eps(other._eps),
81 _nset("nset",this,other._nset),
82 _func("function",this,other._func),
83 _x("x",this,other._x)
84{
85}
86
88
89////////////////////////////////////////////////////////////////////////////////
90/// Calculate value
91
93{
94 if (!_ftor) {
95 _ftor = std::unique_ptr<RooFunctor>{_func.arg().functor(_x.arg(),RooArgSet(),_nset)};
97 _rd = std::make_unique<ROOT::Math::RichardsonDerivator>(wf,_eps,true);
98 }
99
100 switch (_order) {
101 case 1: return _rd->Derivative1(_x);
102 case 2: return _rd->Derivative2(_x);
103 case 3: return _rd->Derivative3(_x);
104 }
105 return 0 ;
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Zap functor and derivator ;
112
113bool RooDerivative::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive)
114{
115 _ftor = nullptr ;
116 _rd = nullptr ;
117 return RooAbsReal::redirectServersHook(newServerList, mustReplaceAll, nameChange, isRecursive);
118}
RooAbsReal * _func
Pointer to original input function.
#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:2489
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...
Represents the first, second, or third order derivative of any RooAbsReal as calculated (numerically)...
std::unique_ptr< ROOT::Math::RichardsonDerivator > _rd
! Derivator
~RooDerivative() override
RooDerivative()
Default constructor.
double _eps
Precision.
std::unique_ptr< RooFunctor > _ftor
! Functor binding of RooAbsReal
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.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
const T & arg() const
Return reference to object held in proxy.
Double_t x[n]
Definition legend1.C:17