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
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
99
100////////////////////////////////////////////////////////////////////////////////
101/// Calculate value
102
104{
105 if (!_ftor) {
106 _ftor = std::unique_ptr<RooFunctor>{_func.arg().functor(_x.arg(),RooArgSet(),_nset)};
108 _rd = std::make_unique<ROOT::Math::RichardsonDerivator>(wf,_eps*(_x.max()-_x.min()),true);
109 }
110
111 switch (_order) {
112 case 1: return _rd->Derivative1(_x);
113 case 2: return _rd->Derivative2(_x);
114 case 3: return _rd->Derivative3(_x);
115 }
116 return 0 ;
117}
118
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Zap functor and derivator ;
123
124bool RooDerivative::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive)
125{
126 _ftor = nullptr ;
127 _rd = nullptr ;
128 return RooAbsReal::redirectServersHook(newServerList, mustReplaceAll, nameChange, isRecursive);
129}
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