//////////////////////////////////////////////////////////////// // $Id: TMinuitMinimizer.cxx,v 1.5 2007/10/31 04:56:55 ltrung Exp $ // // Implement the base class for function minimizers. #include #include #include #include "TMinuitMinimizer.hxx" COMET::TMinuitMinimizer::TMinuitMinimizer(COMET::IMinimizerFunc& func) : COMET::IMinimizer(func), TMinuit(func.GetParameterCount()) { } Int_t COMET::TMinuitMinimizer::Eval(Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag) { fval = fFunction.Evaluate(par); return 0; } double COMET::TMinuitMinimizer::GetParameter(int ipar) const { double value = 0.0; double error = 0.0; TMinuit::GetParameter(ipar, value, error); return value; } double COMET::TMinuitMinimizer::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::TMinuitMinimizer::GetMinimum(void) const { return fMinimum; }; int COMET::TMinuitMinimizer::GetStatus(void) const { return fStatus; }; void COMET::TMinuitMinimizer::SetPrecision(double accuracy) { double arglist[1]; arglist[0] = accuracy; Int_t ierr = 0; mnexcm("SET ERR",arglist,1,ierr); }; Int_t COMET::TMinuitMinimizer::SetPrintLevel(int printLevel) { TMinuit::SetPrintLevel(printLevel); return 0; }; int COMET::TMinuitMinimizer::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 MIDGRAD algorithm to get the minimum mnexcm("MIGRAD",arglist,0,ierr); fStatus = ierr; // Get the values for the parameters. for (int i=0; i