00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "TFcnAdapter.h"
00011
00012 #include <cassert>
00013
00014
00015 double TFcnAdapter::operator()(const std::vector<double>& par) const {
00016
00017
00018
00019 assert(fFCN != 0);
00020 double fs = 0.;
00021
00022
00023
00024 double* theCache = (double*)(&(par.front()));
00025
00026 int npar = par.size();
00027 (*fFCN)(npar, 0, fs, theCache, 4);
00028
00029
00030 return fs;
00031 }
00032
00033 std::vector<double> TFcnAdapter::Gradient(const std::vector<double>& par) const {
00034
00035
00036
00037
00038 assert(fFCN != 0);
00039 double fs = 0.;
00040 int npar = par.size();
00041
00042 double* theCache = (double*)(&(par.front()));
00043 if (fGradCache.size() != par.size() )
00044 fGradCache = std::vector<double>(par.size() );
00045
00046 for(int i = 0; i < npar; i++) theCache[i] = par[i];
00047
00048 (*fFCN)(npar, &fGradCache[0], fs, theCache, 4);
00049 return fGradCache;
00050 }
00051
00052
00053 double TFcnAdapter::operator()(int npar, double* params,int iflag) const {
00054
00055
00056
00057
00058 assert(fFCN != 0);
00059 double fs = 0.;
00060 (*fFCN)(npar, 0, fs, params, iflag);
00061 return fs;
00062 }
00063