Logo ROOT   6.18/05
Reference Guide
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
21namespace ROOT {
22
23 namespace Math {
24
25
26 /**
27 Class to Wrap a ROOT Function class (like TF1) in a IParamFunction interface
28 of one dimensions to be used in the ROOT::Math numerical algorithms
29 The wrapper does not own bby default the TF1 pointer, so it assumes it exists during the wrapper lifetime
30
31 The class from ROOT version 6.03 does not contain anymore a copy of the parameters. The parameters are
32 stored in the TF1 class.
33
34
35 @ingroup CppFunctions
36 */
38
39 public:
40
44
45
46 /**
47 constructor from a TF1 function pointer.
48 */
50
51 /**
52 Destructor (no operations). TF1 Function pointer is not owned
53 */
54 virtual ~WrappedTF1() {}
55
56 /**
57 Copy constructor
58 */
59 WrappedTF1(const WrappedTF1 &rhs);
60
61 /**
62 Assignment operator
63 */
65
66 /** @name interface inherited from IFunction */
67
68 /**
69 Clone the wrapper but not the original function
70 */
72 {
73 return new WrappedTF1(*this);
74 }
75
76
77 /** @name interface inherited from IParamFunction */
78
79 /// get the parameter values (return values cachen inside, those inside TF1 might be different)
80 const double *Parameters() const
81 {
82 //return (fParams.size() > 0) ? &fParams.front() : 0;
83 return fFunc->GetParameters();
84 }
85
86 /// set parameter values
87 /// need to call also SetParameters in TF1 in ace some other operations (re-normalizations) are needed
88 void SetParameters(const double *p)
89 {
90 //std::copy(p,p+fParams.size(),fParams.begin());
92 }
93
94 /// return number of parameters
95 unsigned int NPar() const
96 {
97 //return fParams.size();
98 return fFunc->GetNpar();
99 }
100
101 /// return parameter name (this is stored in TF1)
102 std::string ParameterName(unsigned int i) const
103 {
104 return std::string(fFunc->GetParName(i));
105 }
106
107
108 using BaseGradFunc::operator();
109
110 /// evaluate the derivative of the function with respect to the parameters
111 void ParameterGradient(double x, const double *par, double *grad) const;
112
113 /// calculate function and derivative at same time (required by IGradient interface)
114 void FdF(double x, double &f, double &deriv) const
115 {
116 f = DoEval(x);
117 deriv = DoDerivative(x);
118 }
119
120 /// precision value used for calculating the derivative step-size
121 /// h = eps * |x|. The default is 0.001, give a smaller in case function changes rapidly
122 static void SetDerivPrecision(double eps);
123
124 /// get precision value used for calculating the derivative step-size
125 static double GetDerivPrecision();
126
127 private:
128
129
130 /// evaluate function passing coordinates x and vector of parameters
131 double DoEvalPar(double x, const double *p) const
132 {
133 fX[0] = x;
134 if (fFunc->GetMethodCall()) fFunc->InitArgs(fX, p); // needed for interpreted functions
135 return fFunc->EvalPar(fX, p);
136 }
137
138 /// evaluate function using the cached parameter values (of TF1)
139 /// re-implement for better efficiency
140 double DoEval(double x) const
141 {
142 // no need to call InitArg for interpreted functions (done in ctor)
143 // use EvalPar since it is much more efficient than Eval
144 fX[0] = x;
145 //const double * p = (fParams.size() > 0) ? &fParams.front() : 0;
146 return fFunc->EvalPar(fX, 0);
147 }
148
149 /// return the function derivatives w.r.t. x
150 double DoDerivative(double x) const;
151
152 /// evaluate the derivative of the function with respect to the parameters
153 double DoParameterDerivative(double x, const double *p, unsigned int ipar) const;
154
155 bool fLinear; // flag for linear functions
156 bool fPolynomial; // flag for polynomial functions
157 TF1 *fFunc; // pointer to ROOT function
158 mutable double fX[1]; //! cached vector for x value (needed for TF1::EvalPar signature)
159 //std::vector<double> fParams; // cached vector with parameter values
160
161 };
162
163 } // end namespace Fit
164
165} // end namespace ROOT
166
167
168#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:247
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:37
const double * Parameters() const
get the parameter values (return values cachen inside, those inside TF1 might be different)
Definition: WrappedTF1.h:80
WrappedTF1 & operator=(const WrappedTF1 &rhs)
Assignment operator.
Definition: WrappedTF1.cxx:83
WrappedTF1(TF1 &f)
constructor from a TF1 function pointer.
Definition: WrappedTF1.cxx:41
double DoEval(double x) const
evaluate function using the cached parameter values (of TF1) re-implement for better efficiency
Definition: WrappedTF1.h:140
static void SetDerivPrecision(double eps)
precision value used for calculating the derivative step-size h = eps * |x|.
Definition: WrappedTF1.cxx:142
static double GetDerivPrecision()
get precision value used for calculating the derivative step-size
Definition: WrappedTF1.cxx:147
ROOT::Math::IParamGradFunction BaseGradFunc
Definition: WrappedTF1.h:42
void FdF(double x, double &f, double &deriv) const
calculate function and derivative at same time (required by IGradient interface)
Definition: WrappedTF1.h:114
unsigned int NPar() const
return number of parameters
Definition: WrappedTF1.h:95
ROOT::Math::IGenFunction * Clone() const
Clone the wrapper but not the original function.
Definition: WrappedTF1.h:71
virtual ~WrappedTF1()
Destructor (no operations).
Definition: WrappedTF1.h:54
ROOT::Math::IGradientOneDim IGrad
Definition: WrappedTF1.h:41
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:88
void ParameterGradient(double x, const double *par, double *grad) const
evaluate the derivative of the function with respect to the parameters
Definition: WrappedTF1.cxx:95
std::string ParameterName(unsigned int i) const
return parameter name (this is stored in TF1)
Definition: WrappedTF1.h:102
double DoParameterDerivative(double x, const double *p, unsigned int ipar) const
evaluate the derivative of the function with respect to the parameters
Definition: WrappedTF1.cxx:119
double DoDerivative(double x) const
return the function derivatives w.r.t. x
Definition: WrappedTF1.cxx:110
double DoEvalPar(double x, const double *p) const
evaluate function passing coordinates x and vector of parameters
Definition: WrappedTF1.h:131
ROOT::Math::IParamGradFunction::BaseFunc BaseFunc
Definition: WrappedTF1.h:43
1-Dim function class
Definition: TF1.h:211
virtual Int_t GetNpar() const
Definition: TF1.h:475
virtual Double_t * GetParameters() const
Definition: TF1.h:514
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition: TF1.cxx:1458
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition: TF1.cxx:2454
TMethodCall * GetMethodCall() const
Definition: TF1.h:488
virtual const char * GetParName(Int_t ipar) const
Definition: TF1.h:523
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:638
Double_t x[n]
Definition: legend1.C:17
Namespace for new Math classes and functions.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21