00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_Math_MultiDimParamFunctionAdapter
00014 #define ROOT_Math_MultiDimParamFunctionAdapter
00015
00016 #ifndef ROOT_Math_IFunction
00017 #include "Math/IFunction.h"
00018 #endif
00019 #ifndef ROOT_Math_IParamFunction
00020 #include "Math/IParamFunction.h"
00021 #endif
00022
00023 #ifndef ROOT_Math_WrappedFunction
00024 #include "Math/WrappedFunction.h"
00025 #endif
00026
00027 #include <cassert>
00028
00029 namespace ROOT {
00030
00031 namespace Math {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class MultiDimParamFunctionAdapter : public IParamMultiFunction {
00050
00051 public:
00052
00053 typedef IParamMultiFunction::BaseFunc BaseFunc;
00054
00055
00056
00057
00058
00059
00060 MultiDimParamFunctionAdapter (const IParamFunction & f ) :
00061 fOwn(true)
00062 {
00063 fFunc = dynamic_cast<IParamFunction *>( f.Clone() );
00064 }
00065
00066
00067
00068
00069
00070 MultiDimParamFunctionAdapter (IParamFunction & f ) :
00071 fOwn(false),
00072 fFunc(&f)
00073 { }
00074
00075
00076
00077
00078
00079 MultiDimParamFunctionAdapter (const MultiDimParamFunctionAdapter & rhs) :
00080 BaseFunc(),
00081 IParamMultiFunction(),
00082 fOwn(rhs.fOwn),
00083 fFunc(0)
00084 {
00085 if (fOwn)
00086 fFunc = dynamic_cast<IParamFunction *>( (rhs.fFunc)->Clone() );
00087 }
00088
00089
00090
00091
00092 virtual ~MultiDimParamFunctionAdapter () {
00093 if (fOwn && fFunc != 0) delete fFunc;
00094 }
00095
00096
00097
00098
00099
00100 MultiDimParamFunctionAdapter & operator=(const MultiDimParamFunctionAdapter & rhs) {
00101 fOwn = rhs.fOwn;
00102 if (fOwn) {
00103 if (fFunc) delete fFunc;
00104 fFunc = dynamic_cast<IParamFunction *> ( (rhs.fFunc)->Clone() );
00105 }
00106 else
00107 fFunc = rhs.fFunc;
00108
00109 return *this;
00110 }
00111
00112
00113
00114
00115 virtual BaseFunc * Clone( ) const {
00116 return new MultiDimParamFunctionAdapter( *this);
00117 }
00118
00119 public:
00120
00121
00122 const double * Parameters() const { return fFunc->Parameters(); }
00123
00124 void SetParameters(const double * p) { fFunc->SetParameters(p); }
00125
00126 unsigned int NPar() const { return fFunc->NPar(); }
00127
00128 unsigned int NDim() const { return 1; }
00129
00130
00131 private:
00132
00133
00134 double DoEvalPar(const double * x, const double * p) const {
00135 return (*fFunc)(*x, p);
00136 }
00137
00138
00139 private:
00140
00141 bool fOwn;
00142 IParamFunction * fFunc;
00143
00144 };
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 class MultiDimParamGradFunctionAdapter : public IParamMultiGradFunction {
00166
00167 public:
00168
00169 typedef IParamMultiGradFunction::BaseFunc BaseFunc;
00170
00171
00172
00173
00174
00175
00176 MultiDimParamGradFunctionAdapter (const IParamGradFunction & f) :
00177 fOwn(true)
00178 {
00179 fFunc = dynamic_cast<IParamGradFunction *>( f.Clone() );
00180 }
00181
00182
00183
00184
00185
00186 MultiDimParamGradFunctionAdapter (IParamGradFunction & f) :
00187 fOwn(false),
00188 fFunc(&f)
00189 { }
00190
00191
00192
00193
00194
00195 MultiDimParamGradFunctionAdapter (const MultiDimParamGradFunctionAdapter & rhs) :
00196 BaseFunc(),
00197 IParamMultiGradFunction(),
00198 fOwn(rhs.fOwn),
00199 fFunc(rhs.fFunc)
00200 {
00201 if (fOwn)
00202 fFunc = dynamic_cast<IParamGradFunction *>( (rhs.fFunc)->Clone() );
00203 }
00204
00205
00206
00207
00208 virtual ~MultiDimParamGradFunctionAdapter () { if (fOwn && fFunc != 0) delete fFunc; }
00209
00210
00211
00212
00213
00214 MultiDimParamGradFunctionAdapter & operator=(const MultiDimParamGradFunctionAdapter & rhs) {
00215 fOwn = rhs.fOwn;
00216 if (fOwn) {
00217 if (fFunc) delete fFunc;
00218 fFunc = dynamic_cast<IParamGradFunction *> ( (rhs.fFunc)->Clone() );
00219 }
00220 else
00221 fFunc = rhs.fFunc;
00222
00223 return *this;
00224 }
00225
00226
00227
00228
00229 virtual BaseFunc * Clone( ) const {
00230 return new MultiDimParamGradFunctionAdapter( *this);
00231 }
00232
00233 public:
00234
00235
00236 const double * Parameters() const { return fFunc->Parameters(); }
00237
00238 void SetParameters(const double * p) { fFunc->SetParameters(p); }
00239
00240 unsigned int NPar() const { return fFunc->NPar(); }
00241
00242 unsigned int NDim() const { return 1; }
00243
00244
00245
00246
00247
00248 void ParameterGradient(const double *x, const double * p, double * grad) const {
00249 fFunc->ParameterGradient(*x, p, grad);
00250 }
00251
00252
00253
00254 private:
00255
00256
00257 double DoEvalPar(const double * x, const double * p) const {
00258 return (*fFunc)(*x, p);
00259 }
00260
00261
00262
00263
00264
00265 double DoParameterDerivative(const double * x, const double * p, unsigned int ipar ) const {
00266 return fFunc->ParameterDerivative(*x, p, ipar);
00267 }
00268
00269 private:
00270
00271 bool fOwn;
00272 IParamGradFunction * fFunc;
00273
00274 };
00275
00276
00277
00278
00279 }
00280
00281 }
00282
00283
00284 #endif