Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MultiDimParamFunctionAdapter.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Author: L. Moneta Wed Dec 6 11:45:55 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class MultiDimParamFunctionAdapter
12
13#ifndef ROOT_Math_MultiDimParamFunctionAdapter
14#define ROOT_Math_MultiDimParamFunctionAdapter
15
16#include "Math/IFunction.h"
17#include "Math/IParamFunction.h"
18
20
21namespace ROOT {
22
23 namespace Math {
24
25
26 /**
27 MultiDimParamFunctionAdapter class to wrap a one-dimensional parametric function in
28 a multi dimensional parametric function interface
29 This is used typically in fitting where internally the function is stored as multidimension
30
31 To wrap a non-parametric one-dim function in a multi-dim interface one can use simply a
32 ROOT::Math::WrappedFunction<ROOT::Math::IGenFunction> or ROOT::Math::Functor
33 and ROOT::Math::GradFunctor for gradient functions
34
35 This class differs from WrappedParamFunction in the fact that the parameters are not stored in
36 the adapter class and optionally it keeps a cloned and managed copy of the adapter class.
37
38 @ingroup ParamFunc
39
40 */
42
43 public:
44
46
47
48 /**
49 Constructor from a parametric one dim function interface from a const reference
50 Own the function in this case
51 */
53 fOwn(true)
54 {
55 fFunc = dynamic_cast<IParamFunction *>(f.Clone());
56 }
57
58 /**
59 Constructor from a parametric one dim function interface from a non-const reference
60 Do not own the function in this case
61 */
63 fOwn(false),
64 fFunc(&f)
65 { }
66
67
68 /**
69 Copy constructor. Different behaviour according if function is owned or not
70 */
72 BaseFunc(),
74 fOwn(rhs.fOwn),
75 fFunc(nullptr)
76 {
77 if (fOwn)
78 fFunc = dynamic_cast<IParamFunction *>((rhs.fFunc)->Clone());
79 }
80
81 /**
82 Destructor (no operations)
83 */
85 {
86 if (fOwn && fFunc) delete fFunc;
87 }
88
89
90 /**
91 Assignment operator
92 */
94 {
95 fOwn = rhs.fOwn;
96 if (fOwn) {
97 if (fFunc) delete fFunc; // delete previously existing copy
98 fFunc = dynamic_cast<IParamFunction *>((rhs.fFunc)->Clone());
99 } else
100 fFunc = rhs.fFunc;
101
102 return *this;
103 }
104
105 /**
106 clone
107 */
108 BaseFunc *Clone() const override
109 {
110 return new MultiDimParamFunctionAdapter(*this);
111 }
112
113 public:
114
115 // methods required by interface
116 const double *Parameters() const override
117 {
118 return fFunc->Parameters();
119 }
120
121 void SetParameters(const double *p) override
122 {
124 }
125
126 unsigned int NPar() const override
127 {
128 return fFunc->NPar();
129 }
130
131 unsigned int NDim() const override
132 {
133 return 1;
134 }
135
136
137 private:
138
139 /// needed by the interface
140 double DoEvalPar(const double *x, const double *p) const override
141 {
142 return (*fFunc)(*x, p);
143 }
144
145
146 private:
147
148 bool fOwn;
150
151 };
152
153
154
155 /**
156 MultiDimParamGradFunctionAdapter class to wrap a one-dimensional parametric gradient function in
157 a multi dimensional parametric gradient function interface
158 This is used typically in fitting where internally the function is stored as multidimension
159
160 To wrap a non-parametric one-dim gradient function in a multi-dim interface one can use simply a
161 a ROOT::Math::GradFunctor
162
163 The parameters are not stored in the adapter class and by default the pointer to the 1D function is owned.
164 This means that deleting the class deletes also the 1D function and copying the class copies also the
165 1D function
166 This class differs from WrappedParamFunction in the fact that the parameters are not stored in
167 the adapter class and optionally it keeps a cloned and managed copy of the adapter class.
168
169 @ingroup ParamFunc
170
171 */
173
174 public:
175
177
178
179 /**
180 Constructor from a param one dim function interface from a const reference
181 Copy and manage the own function pointer
182 */
184 fOwn(true)
185 {
186 fFunc = dynamic_cast<IParamGradFunction *>(f.Clone());
187 }
188
189 /**
190 Constructor from a param one dim function interface from a non const reference
191 Do not own the function pointer in this case
192 */
194 fOwn(false),
195 fFunc(&f)
196 { }
197
198
199 /**
200 Copy constructor. Different behaviour according if function is owned or not
201 */
203 BaseFunc(),
205 fOwn(rhs.fOwn),
206 fFunc(rhs.fFunc)
207 {
208 if (fOwn)
209 fFunc = dynamic_cast<IParamGradFunction *>((rhs.fFunc)->Clone());
210 }
211
212 /**
213 Destructor (no operations)
214 */
216 {
217 if (fOwn && fFunc) delete fFunc;
218 }
219
220
221 /**
222 Assignment operator
223 */
225 {
226 fOwn = rhs.fOwn;
227 if (fOwn) {
228 if (fFunc) delete fFunc; // delete previously existing copy
229 fFunc = dynamic_cast<IParamGradFunction *>((rhs.fFunc)->Clone());
230 } else
231 fFunc = rhs.fFunc;
232
233 return *this;
234 }
235
236 /**
237 clone
238 */
239 BaseFunc *Clone() const override
240 {
241 return new MultiDimParamGradFunctionAdapter(*this);
242 }
243
244 public:
245
246 // methods required by interface
247 const double *Parameters() const override
248 {
249 return fFunc->Parameters();
250 }
251
252 void SetParameters(const double *p) override
253 {
255 }
256
257 unsigned int NPar() const override
258 {
259 return fFunc->NPar();
260 }
261
262 unsigned int NDim() const override
263 {
264 return 1;
265 }
266
267// void Gradient(const double *x, double * grad) const {
268// grad[0] = fFunc->Derivative( *x);
269// }
270
271 void ParameterGradient(const double *x, const double *p, double *grad) const override
272 {
273 fFunc->ParameterGradient(*x, p, grad);
274 }
275
276 // using IParamMultiGradFunction::BaseFunc::operator();
277
278 private:
279
280 /// functions needed by interface
281 double DoEvalPar(const double *x, const double *p) const override
282 {
283 return (*fFunc)(*x, p);
284 }
285
286// double DoDerivative(const double * x, unsigned int ) const {
287// return fFunc->Derivative(*x);
288// }
289
290 double DoParameterDerivative(const double *x, const double *p, unsigned int ipar) const override
291 {
292 return fFunc->ParameterDerivative(*x, p, ipar);
293 }
294
295 private:
296
297 bool fOwn;
299
300 };
301
302
303
304
305 } // end namespace Math
306
307} // end namespace ROOT
308
309
310#endif /* ROOT_Math_MultiDimParamFunctionAdapter */
#define f(i)
Definition RSha256.hxx:104
winID h TVirtualViewer3D TVirtualGLPainter p
virtual void SetParameters(const double *p)=0
Set the parameter values.
virtual const double * Parameters() const =0
Access the parameter values.
virtual unsigned int NPar() const =0
Return the number of Parameters.
IParamFunction interface (abstract class) describing multi-dimensional parametric functions It is a d...
Specialized IParamFunction interface (abstract class) for one-dimensional parametric functions It is ...
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
typename IParametricFunctionMultiDimTempl< T >::BaseFunc BaseFunc
Interface (abstract class) for parametric one-dimensional gradient functions providing in addition to...
virtual void ParameterGradient(double x, const double *p, double *grad) const
Evaluate the derivatives of the function with respect to the parameters at a point x.
double ParameterDerivative(double x, const double *p, unsigned int ipar=0) const
Partial derivative with respect a parameter.
MultiDimParamFunctionAdapter class to wrap a one-dimensional parametric function in a multi dimension...
MultiDimParamFunctionAdapter & operator=(const MultiDimParamFunctionAdapter &rhs)
Assignment operator.
MultiDimParamFunctionAdapter(const MultiDimParamFunctionAdapter &rhs)
Copy constructor.
MultiDimParamFunctionAdapter(const IParamFunction &f)
Constructor from a parametric one dim function interface from a const reference Own the function in t...
double DoEvalPar(const double *x, const double *p) const override
needed by the interface
const double * Parameters() const override
Access the parameter values.
MultiDimParamFunctionAdapter(IParamFunction &f)
Constructor from a parametric one dim function interface from a non-const reference Do not own the fu...
void SetParameters(const double *p) override
Set the parameter values.
unsigned int NPar() const override
Return the number of Parameters.
unsigned int NDim() const override
Retrieve the dimension of the function.
~MultiDimParamFunctionAdapter() override
Destructor (no operations)
MultiDimParamGradFunctionAdapter class to wrap a one-dimensional parametric gradient function in a mu...
MultiDimParamGradFunctionAdapter(IParamGradFunction &f)
Constructor from a param one dim function interface from a non const reference Do not own the functio...
unsigned int NDim() const override
Retrieve the dimension of the function.
double DoParameterDerivative(const double *x, const double *p, unsigned int ipar) const override
double DoEvalPar(const double *x, const double *p) const override
functions needed by interface
const double * Parameters() const override
Access the parameter values.
MultiDimParamGradFunctionAdapter(const IParamGradFunction &f)
Constructor from a param one dim function interface from a const reference Copy and manage the own fu...
void ParameterGradient(const double *x, const double *p, double *grad) const override
unsigned int NPar() const override
Return the number of Parameters.
~MultiDimParamGradFunctionAdapter() override
Destructor (no operations)
void SetParameters(const double *p) override
Set the parameter values.
MultiDimParamGradFunctionAdapter(const MultiDimParamGradFunctionAdapter &rhs)
Copy constructor.
MultiDimParamGradFunctionAdapter & operator=(const MultiDimParamGradFunctionAdapter &rhs)
Assignment operator.
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.