Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
WrappedTF1.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Author: L. Moneta Wed Sep 6 09:52:26 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class WrappedTF1
12
13#ifndef ROOT_Math_WrappedTF1
14#define ROOT_Math_WrappedTF1
15
16
17#include "Math/IParamFunction.h"
18
19#include "TF1.h"
20#include <string>
21#include <vector>
22
23namespace ROOT {
24
25 namespace Math {
26
27
28 /**
29 Class to Wrap a ROOT Function class (like TF1) in a IParamFunction interface
30 of one dimensions to be used in the ROOT::Math numerical algorithms
31 The wrapper does not own bby default the TF1 pointer, so it assumes it exists during the wrapper lifetime
32
33 The class from ROOT version 6.03 does not contain anymore a copy of the parameters. The parameters are
34 stored in the TF1 class.
35
36
37 @ingroup CppFunctions
38 */
40
41 public:
42
46
47
48 /**
49 constructor from a TF1 function pointer.
50 */
52
53 /**
54 Destructor (no operations). TF1 Function pointer is not owned
55 */
56 virtual ~WrappedTF1() {}
57
58 /**
59 Copy constructor
60 */
61 WrappedTF1(const WrappedTF1 &rhs);
62
63 /**
64 Assignment operator
65 */
67
68 /** @name interface inherited from IFunction */
69
70 /**
71 Clone the wrapper but not the original function
72 */
74 {
75 return new WrappedTF1(*this);
76 }
77
78
79 /** @name interface inherited from IParamFunction */
80
81 /// get the parameter values (return values cachen inside, those inside TF1 might be different)
82 const double *Parameters() const
83 {
84 //return (fParams.size() > 0) ? &fParams.front() : 0;
85 return fFunc->GetParameters();
86 }
87
88 /// set parameter values
89 /// need to call also SetParameters in TF1 in ace some other operations (re-normalizations) are needed
90 void SetParameters(const double *p)
91 {
92 //std::copy(p,p+fParams.size(),fParams.begin());
94 }
95
96 /// return number of parameters
97 unsigned int NPar() const
98 {
99 //return fParams.size();
100 return fFunc->GetNpar();
101 }
102
103 /// return parameter name (this is stored in TF1)
104 std::string ParameterName(unsigned int i) const
105 {
106 return std::string(fFunc->GetParName(i));
107 }
108
109
110 using BaseGradFunc::operator();
111
112 /// evaluate the derivative of the function with respect to the parameters
113 void ParameterGradient(double x, const double *par, double *grad) const;
114
115 /// calculate function and derivative at same time (required by IGradient interface)
116 void FdF(double x, double &f, double &deriv) const
117 {
118 f = DoEval(x);
119 deriv = DoDerivative(x);
120 }
121
122 /// precision value used for calculating the derivative step-size
123 /// h = eps * |x|. The default is 0.001, give a smaller in case function changes rapidly
124 static void SetDerivPrecision(double eps);
125
126 /// get precision value used for calculating the derivative step-size
127 static double GetDerivPrecision();
128
129 private:
130
131
132 /// evaluate function passing coordinates x and vector of parameters
133 double DoEvalPar(double x, const double *p) const
134 {
135 fX[0] = x;
136 if (fFunc->GetMethodCall()) fFunc->InitArgs(fX, p); // needed for interpreted functions
137 return fFunc->EvalPar(fX, p);
138 }
139
140 /// evaluate function using the cached parameter values (of TF1)
141 /// re-implement for better efficiency
142 double DoEval(double x) const
143 {
144 // no need to call InitArg for interpreted functions (done in ctor)
145 // use EvalPar since it is much more efficient than Eval
146 fX[0] = x;
147 //const double * p = (fParams.size() > 0) ? &fParams.front() : 0;
148 return fFunc->EvalPar(fX, 0);
149 }
150
151 /// return the function derivatives w.r.t. x
152 double DoDerivative(double x) const;
153
154 /// evaluate the derivative of the function with respect to the parameters
155 double DoParameterDerivative(double x, const double *p, unsigned int ipar) const;
156
157 bool fLinear; // flag for linear functions
158 bool fPolynomial; // flag for polynomial functions
159 TF1 *fFunc; // pointer to ROOT function
160 mutable double fX[1]; //! cached vector for x value (needed for TF1::EvalPar signature)
161 //std::vector<double> fParams; // cached vector with parameter values
162
163 };
164
165 } // end namespace Fit
166
167} // end namespace ROOT
168
169
170#endif /* ROOT_Fit_WrappedTF1 */
#define f(i)
Definition RSha256.hxx:104
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:135
Specialized Gradient interface(abstract class) for one dimensional functions It provides a method to ...
Definition IFunction.h:263
Interface (abstract class) for parametric one-dimensional gradient functions providing in addition to...
Class to Wrap a ROOT Function class (like TF1) in a IParamFunction interface of one dimensions to be ...
Definition WrappedTF1.h:39
const double * Parameters() const
get the parameter values (return values cachen inside, those inside TF1 might be different)
Definition WrappedTF1.h:82
WrappedTF1 & operator=(const WrappedTF1 &rhs)
Assignment operator.
double DoEval(double x) const
evaluate function using the cached parameter values (of TF1) re-implement for better efficiency
Definition WrappedTF1.h:142
static void SetDerivPrecision(double eps)
precision value used for calculating the derivative step-size h = eps * |x|.
static double GetDerivPrecision()
get precision value used for calculating the derivative step-size
ROOT::Math::IParamGradFunction BaseGradFunc
Definition WrappedTF1.h:44
void FdF(double x, double &f, double &deriv) const
calculate function and derivative at same time (required by IGradient interface)
Definition WrappedTF1.h:116
unsigned int NPar() const
return number of parameters
Definition WrappedTF1.h:97
ROOT::Math::IGenFunction * Clone() const
Clone the wrapper but not the original function.
Definition WrappedTF1.h:73
virtual ~WrappedTF1()
Destructor (no operations).
Definition WrappedTF1.h:56
ROOT::Math::IGradientOneDim IGrad
Definition WrappedTF1.h:43
void SetParameters(const double *p)
set parameter values need to call also SetParameters in TF1 in ace some other operations (re-normaliz...
Definition WrappedTF1.h:90
void ParameterGradient(double x, const double *par, double *grad) const
evaluate the derivative of the function with respect to the parameters
std::string ParameterName(unsigned int i) const
return parameter name (this is stored in TF1)
Definition WrappedTF1.h:104
double DoParameterDerivative(double x, const double *p, unsigned int ipar) const
evaluate the derivative of the function with respect to the parameters
double DoDerivative(double x) const
return the function derivatives w.r.t. x
double DoEvalPar(double x, const double *p) const
evaluate function passing coordinates x and vector of parameters
Definition WrappedTF1.h:133
ROOT::Math::IParamGradFunction::BaseFunc BaseFunc
Definition WrappedTF1.h:45
1-Dim function class
Definition TF1.h:213
virtual Int_t GetNpar() const
Definition TF1.h:481
virtual Double_t * GetParameters() const
Definition TF1.h:520
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1469
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2473
TMethodCall * GetMethodCall() const
Definition TF1.h:494
virtual const char * GetParName(Int_t ipar) const
Definition TF1.h:529
virtual void SetParameters(const Double_t *params)
Definition TF1.h:644
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...