20 Minimiser* Minimiser::_defaultMinimiser=0;
21 int Minimiser::_defaultMaxCalls=100000;
25 if(0 == _defaultMinimiser){
28 return _defaultMinimiser;
32 Minimiser::Minimiser(
IMinimisable* fitFunction,
const double errdef)
35 , _useAnalyticGradient(false)
36 , _theFunction(fitFunction)
37 , _maxCalls(_defaultMaxCalls)
63 if(dbThis) cout <<
"Eval got called " << endl;
65 cout <<
"ERROR in Minimiser::Eval (file: Minimiser.C)" 66 <<
" Got called although I'm not OK" << endl;
75 vector<double> gradient(npar);
77 for(
unsigned int i = 0; i < static_cast<unsigned int>(npar); i++){
92 fGraphicsMode = kTRUE;
100 this->DeleteArrays();
101 this->BuildArrays(needSpace + 2);
107 if(dbThis) cout <<
"Minimiser::init(): you called me" << endl;
109 std::cout <<
"ERROR IN Minimiser::init():" 110 <<
" the function-ptr is empty." 111 <<
" I won't do anything for now." 115 if(dbThis) cout <<
" ... calling theFunction()->beginFit()" << endl;
120 std::cout <<
"ERROR IN Minimiser::init():" 121 <<
" theFunction()->getParSet() returned empty pointer" 122 <<
" I won't do anything for now." 129 if(dbThis) cout <<
"... made space, now initialising variables" << endl;
131 if(dbThis) cout <<
" initialised variables." << endl;
135 if(dbThis) cout <<
"Minimiser::init(): returning true" << endl;
140 if(0==fcn)
return false;
151 if(i >=
nPars())
return 0;
156 if(i >=
nPars())
return 0;
172 if(!
parsOK())
return false;
176 cout <<
"Minimiser::initialiseVariables() called. " << endl;
177 cout <<
"\n\t(declaring them to MINUIT)" << endl;
181 for(
unsigned int i=0; i <
nPars(); i++){
190 for(
unsigned int i=0; i <
nPars(); i++){
206 success &= ! ierflag;
209 cout <<
"Minimiser::initialiseVariables():" 210 <<
"done declaring variables, now:" 211 <<
"theFunction()->parametersChanged();" 215 if(dbThis) cout <<
"Minimiser::initialiseVariables():" 216 <<
" all done - returning " << success << endl;
222 if(!
parsOK())
return false;
224 Double_t mean, err, errN, errP;
226 for(
unsigned int i=0; i <
nPars(); i++){
228 this->mnerrs(i, errP, errN, err, gcc);
229 this->GetParameter(i, mean, err);
239 if(!
parsOK())
return false;
241 for(
unsigned int i=0; i <
nPars(); i++){
251 if(!
parsOK())
return false;
260 if(0 ==
nPars())
return false;
274 cout <<
"ERROR IN Minimiser::getFCNVal()" 275 <<
" I'm not OK!!" << endl;
283 cout <<
"ERROR IN Minimiser::FCNGradient()" 284 <<
" I'm not OK!!" << endl;
321 if(dbThis) cout <<
"calling MIGRAD" << endl;
323 if(dbThis) cout <<
"did that. How did I do? ierflg=" <<
ierflg << endl;
332 if(dbThis) cout <<
"calling MINOS" << endl;
334 if(dbThis) cout <<
"did that. How did I do? ierflg=" <<
ierflg << endl;
345 if(dbThis) cout <<
"calling SIMPLEX" << endl;
347 if(dbThis) cout <<
"did that. How did I do? ierflg=" <<
ierflg << endl;
359 if(dbThis) cout <<
"calling SEEK" << endl;
361 if(dbThis) cout <<
"did that. How did I do? ierflg=" <<
ierflg << endl;
373 if(dbThis) cout <<
"calling IMPROVE" << endl;
375 if(dbThis) cout <<
"did that. How did I do? ierflg=" <<
ierflg << endl;
387 if(dbThis) cout <<
"re-initialised variables" << endl;
394 if(dbThis) cout <<
"Minimiser::doFit() called" << endl;
396 if(dbThis) cout <<
"... called prepFit " << success << endl;
398 if(dbThis) cout <<
"... called MIGRAD" << success << endl;
400 if(dbThis) cout <<
"... scanned" << success << endl;
409 if(dbThis) cout <<
"called MINOS" << endl;
419 success &=
CallSeek(maxCalls, devs);
420 if(dbThis) cout <<
"called SEEK" << endl;
431 if(dbThis) cout <<
"called SIMPLEX" << endl;
440 if(0 ==
nPars())
return false;
441 for(
unsigned int i=0; i <
nPars(); i++){
443 if(0 == p || (! p->
scan()) )
continue;
450 if(0 ==
nPars())
return false;
451 for(
unsigned int i=0; i <
nPars(); i++){
461 cout <<
"ERROR Minimiser::scanParameter: " 462 <<
" You are trying to scan a parameter that is" 463 <<
" associated to a different fit (different fit parameter set)" 464 <<
" will not do it." 465 <<
" The parameter you tried was: " << endl;
482 string fname =
"scan_" + p->
name() +
".root";
489 TGraph *gr = (TGraph*) this->GetPlot();
491 cout <<
" didn't get plot " << endl;
493 TFile fscan(fname.c_str(),
"RECREATE");
511 unsigned int internalPars = fNpar;
515 this->mnemat(&m1[0][0], internalPars);
516 TMatrixTSym<double> matrix(internalPars);
517 for(
unsigned int i=0; i < internalPars; i++){
518 for(
unsigned int j=i; j < internalPars; j++){
519 matrix(i,j) = matrix(j,i) = m1[i][j];
531 unsigned int internalPars = fNpar;
535 this->mnemat(&m1[0][0], internalPars);
536 TMatrixTSym<double> matrix(
nPars());
537 for(
unsigned int i=0; i < internalPars; i++){
538 for(
unsigned int j=i; j < internalPars; j++){
539 int ex_i = fNexofi[i] -1;
540 int ex_j = fNexofi[j] -1;
542 cout <<
"Minimiser::covMatrixFull(): doing: " 543 <<
"matrix(" << ex_i<<
", " << ex_j <<
" )" 544 <<
" = matrix(" << ex_j <<
", " << ex_i <<
")" 545 <<
" = m1[" << i <<
"][" << j<<
"];" 549 matrix(ex_i,ex_j) = matrix(ex_j,ex_i) = m1[i][j];
556 double fmin, fedm, errdef ;
557 int npari, nparx,
status ;
558 mnstat( fmin, fedm, errdef, npari, nparx,
status ) ;
572 cout <<
"Fit status: " << stat << endl ;
575 cout <<
"FAILED: Covariance matrix not calculated at all." << endl ;
578 cout <<
"FAILED: Covariance matrix approximation only, not accurate." << endl ;
581 cout <<
"FAILED: Full covariance matrix, but forced positive-definite." << endl ;
584 cout <<
"CONVERGED: Full accurate covariance matrix." << endl ;
587 cout <<
"UNKNOWN." << endl ;
598 deque<deque<double> > initvals ;
599 for(
unsigned i = 0 ; i <
parSet()->
size() ; ++i){
601 initvals.push_back(deque<double>()) ;
602 deque<double>& parvals = initvals.back() ;
603 parvals.push_back(par->
mean()) ;
604 parvals.push_back(par->
err()) ;
605 parvals.push_back(par->
errPos()) ;
606 parvals.push_back(par->
errNeg()) ;
612 float errdef =
_errdef * nsigma * nsigma ;
613 SetErrorDef(errdef) ;
614 TGraph* graph = (TGraph*)Contour(npoints, iparx, ipary) ;
616 ostringstream title ;
617 title << pary->
name() <<
"_vs_" << parx->
name() <<
"_" << nsigma <<
"_sigma_contour" ;
618 string titlestr(title.str()) ;
619 graph->SetName(titlestr.c_str()) ;
622 for(
unsigned i = 0 ; i <
parSet()->
size() ; ++i)
623 getParPtr(i)->
setResult(initvals[i][0], initvals[i][1], initvals[i][2], initvals[i][3]) ;
bool CallSeek(int maxCalls=100, int devs=5)
TMatrixTSym< double > covMatrixFull()
virtual const MinuitParameterSet * parSet() const =0
void FCNGradient(std::vector< double > &grad)
virtual double scanMin() const =0
IMinimisable * _theFunction
bool isStatusAtLeast(Minimiser::FitStatus)
const MinuitParameterSet * parSet() const
FAILED: Covariance matrix approximation only, not accurate.
bool _useAnalyticGradient
bool doSimplexFit(int maxCalls=300, double tolerance=1.)
bool initialiseVariables()
bool setCovMatrix(const CovMatrix &)
Set the covariance matrix.
MinuitParameterSet * _parSet
IMinuitParameter * getParPtr(unsigned int i)
unsigned int size() const
TGraph * scan(int i, double from=0, double to=0)
bool updateFitParameters(Double_t *p)
virtual const std::string & name() const =0
IMinimisable * theFunction()
void printResultVsInput(std::ostream &os=std::cout) const
virtual void Gradient(std::vector< double > &grad)
bool unregister(IMinuitParameter *patPtr)
bool CallSimplex(int maxCalls=300, double tolerance=1.)
virtual const std::string & name() const
virtual bool scan() const =0
virtual double blinding() const =0
FAILED: Full covariance matrix, but forced positive-definite.
TGraph * contour(unsigned, unsigned, float nsigma=1., unsigned npoints=40)
void printResultVsInput(std::ostream &os=std::cout) const
virtual bool hidden() const =0
IMinuitParameter * getParPtr(unsigned int i)
virtual double stepInit() const =0
Int_t Eval(Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag)
virtual void beginFit()=0
bool setPrintLevel(int level=-1)
bool attachFunction(IMinimisable *fcn)
bool isStatus(Minimiser::FitStatus)
virtual void print(std::ostream &os=std::cout) const =0
void setMaxCalls(int maxCalls)
virtual bool useAnalyticGradient()
TMatrixTSym< double > covMatrix()
virtual double getVal()=0
bool MakeSpace(int needSpace)
virtual MinuitParameterSet * getParSet()=0
virtual void parametersChanged()=0
bool SetSomeMinuitOptions()
virtual void setResult(double fitMean, double fitErr, double fitErrPos, double fitErrNeg)=0
virtual int parSetIndex() const =0
virtual void setCurrentFitVal(double pval)=0
bool doSeekFit(int maxCalls=100, int devs=5)
unsigned int nPars() const
virtual double scanMax() const =0
CONVERGED: Full accurate covariance matrix.
FAILED: Covariance matrix not calculated at all.
bool CallImprove(int maxCalls=1500, int searches=5)
bool setParametersToResult()