//////////////////////////////////////////////////////////////// // $Id: ISimplexMinimizer.cxx,v 1.5 2007/10/31 04:56:55 ltrung Exp $ // // Implement the base class for function minimizers. #include #include #include #include "ISimplexMinimizer.hxx" COMET::ISimplexMinimizer::ISimplexMinimizer(COMET::IMinimizerFunc& func) : COMET::IMinimizer(func), TMinuit(func.GetParameterCount()) { } Int_t COMET::ISimplexMinimizer::Eval(Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag) { fval = fFunction.Evaluate(par); return 0; } double COMET::ISimplexMinimizer::GetParameter(int ipar) const { double value = 0.0; double error = 0.0; TMinuit::GetParameter(ipar, value, error); return value; } double COMET::ISimplexMinimizer::GetCovariance(int i, int j) const { int npars = fFunction.GetParameterCount(); double cov[npars*npars]; const_cast(this)->mnemat(cov,npars); return cov[i*npars+j]; } double COMET::ISimplexMinimizer::GetMinimum(void) const { return fMinimum; }; int COMET::ISimplexMinimizer::GetStatus(void) const { return fStatus; }; void COMET::ISimplexMinimizer::SetPrecision(double accuracy) { double arglist[1]; arglist[0] = accuracy; Int_t ierr = 0; mnexcm("SET ERR",arglist,1,ierr); }; Int_t COMET::ISimplexMinimizer::SetPrintLevel(int printLevel) { TMinuit::SetPrintLevel(printLevel); return 0; }; int COMET::ISimplexMinimizer::Minimize(int nPar, double *par) { double arglist[4]; if (nPar > fFunction.GetParameterCount()) throw EParameterCount(); // Assign initial values for the parameters. Int_t ierr = 0; for (int i = 0; i < nPar; ++i) { mnparm(i,fFunction.GetParameterName(i), par[i], // Value fFunction.GetScale(i), // Scale 0,0,ierr); // Bounds } // Call the SIMPLEX algorithm to get the minimum mnexcm("SIMPLEX",arglist,0,ierr); fStatus = ierr; // Get the values for the parameters. for (int i=0; i