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::string(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, const RooArgSet& nset, Int_t orderIn, double epsIn) :
69 RooAbsReal(name, title),
70 _order(orderIn),
71 _eps(epsIn),
72 _nset("nset","nset",this,false,false),
73 _func("function","function",this,func),
74 _x("x","x",this,x)
75{
76 if (_order<0 || _order>3) {
77 throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
78 }
79 _nset.add(nset) ;
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85
87 RooAbsReal(other, name),
88 _order(other._order),
89 _eps(other._eps),
90 _nset("nset",this,other._nset),
91 _func("function",this,other._func),
92 _x("x",this,other._x)
93{
94}
95
97
98////////////////////////////////////////////////////////////////////////////////
99/// Calculate value
100
102{
103 if (!_ftor) {
104 _ftor = std::unique_ptr<RooFunctor>{_func.arg().functor(_x.arg(),RooArgSet(),_nset)};
106 _rd = std::make_unique<ROOT::Math::RichardsonDerivator>(wf,_eps*(_x.max()-_x.min()),true);
107 }
108
109 switch (_order) {
110 case 1: return _rd->Derivative1(_x);
111 case 2: return _rd->Derivative2(_x);
112 case 3: return _rd->Derivative3(_x);
113 }
114 return 0 ;
115}
116
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// Zap functor and derivator ;
121
122bool RooDerivative::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive)
123{
124 _ftor = nullptr ;
125 _rd = nullptr ;
126 return RooAbsReal::redirectServersHook(newServerList, mustReplaceAll, nameChange, isRecursive);
127}
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
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