MINT2
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
MINT::Minimiser Class Reference

#include <Minimiser.h>

Inheritance diagram for MINT::Minimiser:

Public Types

enum  FitStatus { NOTCALCULATED = 0, NOTACCURATE, NOTPOSDEF, CONVERGED }
 

Public Member Functions

 Minimiser (IMinimisable *fitFunction=0, const double errdef=1.)
 
virtual ~Minimiser ()
 
bool attachFunction (IMinimisable *fcn)
 
IMinimisabletheFunction ()
 
const IMinimisabletheFunction () const
 
const MinuitParameterSetparSet () const
 
MinuitParameterSetparSet ()
 
unsigned int nPars () const
 
IMinuitParametergetParPtr (unsigned int i)
 
const IMinuitParametergetParPtr (unsigned int i) const
 
bool OK () const
 
bool parsOK () const
 
bool fcnOK () const
 
double getFCNVal ()
 
void FCNGradient (std::vector< double > &grad)
 
bool initialiseVariables ()
 
bool setPrintLevel (int level=-1)
 
bool temporarilyQuiet ()
 
bool resetPrintLevel ()
 
bool SetSomeMinuitOptions ()
 
bool CallMigrad ()
 
bool CallMinos ()
 
bool CallSeek (int maxCalls=100, int devs=5)
 
bool CallSimplex (int maxCalls=300, double tolerance=1.)
 
bool CallImprove (int maxCalls=1500, int searches=5)
 
bool prepFit ()
 
bool doFit ()
 
bool doMinosFit ()
 
bool doSeekFit (int maxCalls=100, int devs=5)
 
bool doSimplexFit (int maxCalls=300, double tolerance=1.)
 
bool scanMarked ()
 
bool scanAll ()
 
TGraph * scan (int i, double from=0, double to=0)
 
TGraph * scan (IMinuitParameter &fp, double from=0, double to=0)
 
void setMaxCalls (int maxCalls)
 
int getMaxCalls () const
 
void printResultVsInput (std::ostream &os=std::cout) const
 
TMatrixTSym< double > covMatrix ()
 
TMatrixTSym< double > covMatrixFull ()
 
int status ()
 
bool isStatus (Minimiser::FitStatus)
 
bool isStatusAtLeast (Minimiser::FitStatus)
 
int printStatus ()
 
bool isConverged ()
 
TGraph * contour (unsigned, unsigned, float nsigma=1., unsigned npoints=40)
 

Static Public Member Functions

static MinimisergetDefaultMinimiser ()
 

Protected Member Functions

bool init ()
 
bool MakeSpace (int needSpace)
 
void TMinInit ()
 
bool updateFitParameters (Double_t *p)
 
bool setParametersToResult ()
 
bool endOfFit ()
 
Int_t Eval (Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag)
 

Protected Attributes

bool _useAnalyticGradient
 
MinuitParameterSet_parSet
 
IMinimisable_theFunction
 
int _maxCalls
 
int _printLevel
 
double _errdef
 

Static Protected Attributes

static Minimiser_defaultMinimiser =0
 
static int _defaultMaxCalls =100000
 

Private Attributes

Double_t arglist [10]
 
Int_t ierflg
 

Detailed Description

Definition at line 22 of file Minimiser.h.

Member Enumeration Documentation

◆ FitStatus

Fit status enumerators.

Enumerator
NOTCALCULATED 

FAILED: Covariance matrix not calculated at all.

NOTACCURATE 

FAILED: Covariance matrix approximation only, not accurate.

NOTPOSDEF 

FAILED: Full covariance matrix, but forced positive-definite.

CONVERGED 

CONVERGED: Full accurate covariance matrix.

Definition at line 121 of file Minimiser.h.

121  {
122  NOTCALCULATED = 0,
123  NOTACCURATE,
124  NOTPOSDEF,
125  CONVERGED
126  } ;
FAILED: Covariance matrix approximation only, not accurate.
Definition: Minimiser.h:123
FAILED: Full covariance matrix, but forced positive-definite.
Definition: Minimiser.h:124
CONVERGED: Full accurate covariance matrix.
Definition: Minimiser.h:125
FAILED: Covariance matrix not calculated at all.
Definition: Minimiser.h:122

Constructor & Destructor Documentation

◆ Minimiser()

Minimiser::Minimiser ( IMinimisable fitFunction = 0,
const double  errdef = 1. 
)

Definition at line 32 of file Minimiser.cpp.

33  : TMinuit(0)
34  , ierflg(0)
35  , _useAnalyticGradient(false)
36  , _theFunction(fitFunction)
38  , _printLevel(3)
39  , _errdef(errdef)
40 {
41  if(0 != theFunction()){
42  init();
43  }
44 }
IMinimisable * _theFunction
Definition: Minimiser.h:33
bool _useAnalyticGradient
Definition: Minimiser.h:26
IMinimisable * theFunction()
Definition: Minimiser.h:60
double _errdef
Definition: Minimiser.h:37
static int _defaultMaxCalls
Definition: Minimiser.h:28

◆ ~Minimiser()

Minimiser::~Minimiser ( )
virtual

Definition at line 46 of file Minimiser.cpp.

46  {
47 }

Member Function Documentation

◆ attachFunction()

bool Minimiser::attachFunction ( IMinimisable fcn)

Definition at line 139 of file Minimiser.cpp.

139  {
140  if(0==fcn) return false;
141  // detachParameters();
142  _theFunction = fcn;
143  return init();
144 }
IMinimisable * _theFunction
Definition: Minimiser.h:33

◆ CallImprove()

bool Minimiser::CallImprove ( int  maxCalls = 1500,
int  searches = 5 
)

Definition at line 367 of file Minimiser.cpp.

367  {
368  bool dbThis=true;
369  bool success=true;
370  bool useAnalyticGradient = _useAnalyticGradient;
371  _useAnalyticGradient = false;
372  arglist[0] = maxCalls; arglist[1] = searches;
373  if(dbThis) cout << "calling IMPROVE" << endl;
374  TMinuit::mnexcm("IMPROVE", arglist ,2,ierflg);
375  if(dbThis) cout << "did that. How did I do? ierflg=" << ierflg << endl;
376  success &= (! ierflg);
377  _useAnalyticGradient = useAnalyticGradient;
378  return success;
379 }
bool _useAnalyticGradient
Definition: Minimiser.h:26
Double_t arglist[10]
Definition: Minimiser.h:23

◆ CallMigrad()

bool Minimiser::CallMigrad ( )

Definition at line 317 of file Minimiser.cpp.

317  {
318  bool dbThis=true;
319  bool success=true;
320  arglist[0] = _maxCalls; arglist[1] = 1.e-2;
321  if(dbThis) cout << "calling MIGRAD" << endl;
322  TMinuit::mnexcm("MIGRAD", arglist ,2,ierflg);
323  if(dbThis) cout << "did that. How did I do? ierflg=" << ierflg << endl;
324  success &= (! ierflg);
325  return success;
326 }
Double_t arglist[10]
Definition: Minimiser.h:23

◆ CallMinos()

bool Minimiser::CallMinos ( )

Definition at line 327 of file Minimiser.cpp.

327  {
328  // thanks to Daniel Johnson for contributing this.
329  bool dbThis=false;
330  bool success=true;
331  arglist[0] = _maxCalls; arglist[1] = 1.e-2;
332  if(dbThis) cout << "calling MINOS" << endl;
333  TMinuit::mnexcm("MINOS", arglist ,2,ierflg);
334  if(dbThis) cout << "did that. How did I do? ierflg=" << ierflg << endl;
335  success &= (! ierflg);
336  return success;
337 }
Double_t arglist[10]
Definition: Minimiser.h:23

◆ CallSeek()

bool Minimiser::CallSeek ( int  maxCalls = 100,
int  devs = 5 
)

Definition at line 353 of file Minimiser.cpp.

353  {
354  bool dbThis=true;
355  bool success=true;
356  bool useAnalyticGradient = _useAnalyticGradient;
357  _useAnalyticGradient = false;
358  arglist[0] = maxCalls; arglist[1] = devs;
359  if(dbThis) cout << "calling SEEK" << endl;
360  TMinuit::mnexcm("SEEK", arglist ,2,ierflg);
361  if(dbThis) cout << "did that. How did I do? ierflg=" << ierflg << endl;
362  success &= (! ierflg);
363  _useAnalyticGradient = useAnalyticGradient;
364  return success;
365 }
bool _useAnalyticGradient
Definition: Minimiser.h:26
Double_t arglist[10]
Definition: Minimiser.h:23

◆ CallSimplex()

bool Minimiser::CallSimplex ( int  maxCalls = 300,
double  tolerance = 1. 
)

Definition at line 339 of file Minimiser.cpp.

339  {
340  bool dbThis=true;
341  bool success=true;
342  bool useAnalyticGradient = _useAnalyticGradient;
343  _useAnalyticGradient = false;
344  arglist[0] = maxCalls; arglist[1] = tolerance;
345  if(dbThis) cout << "calling SIMPLEX" << endl;
346  TMinuit::mnexcm("SIMPLEX", arglist ,2,ierflg);
347  if(dbThis) cout << "did that. How did I do? ierflg=" << ierflg << endl;
348  success &= (! ierflg);
349  _useAnalyticGradient = useAnalyticGradient;
350  return success;
351 }
bool _useAnalyticGradient
Definition: Minimiser.h:26
Double_t arglist[10]
Definition: Minimiser.h:23

◆ contour()

TGraph * Minimiser::contour ( unsigned  iparx,
unsigned  ipary,
float  nsigma = 1.,
unsigned  npoints = 40 
)

Make the nsigma contour plot for the given parameters - note that parameter numbers run from 0-N.

Definition at line 596 of file Minimiser.cpp.

596  {
597  // Cache the initial values and errors.
598  deque<deque<double> > initvals ;
599  for(unsigned i = 0 ; i < parSet()->size() ; ++i){
600  FitParameter* par = (FitParameter*)getParPtr(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()) ;
607  }
608 
609  FitParameter* parx = (FitParameter*)getParPtr(iparx) ;
610  FitParameter* pary = (FitParameter*)getParPtr(ipary) ;
611 
612  float errdef = _errdef * nsigma * nsigma ;
613  SetErrorDef(errdef) ;
614  TGraph* graph = (TGraph*)Contour(npoints, iparx, ipary) ;
615  SetErrorDef(_errdef) ;
616  ostringstream title ;
617  title << pary->name() << "_vs_" << parx->name() << "_" << nsigma << "_sigma_contour" ;
618  string titlestr(title.str()) ;
619  graph->SetName(titlestr.c_str()) ;
620 
621 
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]) ;
625 
626  return graph ;
627 }
const MinuitParameterSet * parSet() const
Definition: Minimiser.h:63
unsigned int size() const
IMinimisable * theFunction()
Definition: Minimiser.h:60
double _errdef
Definition: Minimiser.h:37
virtual const std::string & name() const
Definition: FitParameter.h:144
double mean() const
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
double err() const
virtual void parametersChanged()=0
virtual void setResult(double fitMean, double fitErr, double fitErrPos, double fitErrNeg)=0

◆ covMatrix()

TMatrixTSym< double > Minimiser::covMatrix ( )

Definition at line 506 of file Minimiser.cpp.

506  {
507  // only entries for variable parameters.
508  // if you want rows and columns to correspond
509  // to parameter numbers in MinuitParameterSets
510  // use covMatrixFull.
511  unsigned int internalPars = fNpar;
512 
513  TwoDArray<double> m1(internalPars, internalPars, 0.0);
514 
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];
520  }
521  }
522  return matrix;
523 }

◆ covMatrixFull()

TMatrixTSym< double > Minimiser::covMatrixFull ( )

Definition at line 525 of file Minimiser.cpp.

525  {
526  // rows and columns correspond to external parameter numbers
527  // (if you have many fixed parameters, you'll get a lot of zeros)
528 
529  bool dbThis=false;
530 
531  unsigned int internalPars = fNpar;
532 
533  TwoDArray<double> m1(internalPars, internalPars, 0.0);
534 
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;
541  if(dbThis){
542  cout << "Minimiser::covMatrixFull(): doing: "
543  << "matrix(" << ex_i<< ", " << ex_j << " )"
544  << " = matrix(" << ex_j << ", " << ex_i << ")"
545  << " = m1[" << i << "][" << j<< "];"
546  << " = " << m1[i][j]
547  << endl;
548  }
549  matrix(ex_i,ex_j) = matrix(ex_j,ex_i) = m1[i][j];
550  }
551  }
552  return matrix;
553 }
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ doFit()

bool Minimiser::doFit ( )

Definition at line 391 of file Minimiser.cpp.

391  {
392  bool dbThis=false;
393  bool success = true;
394  if(dbThis) cout << "Minimiser::doFit() called" << endl;
395  success &= prepFit();
396  if(dbThis) cout << "... called prepFit " << success << endl;
397  success &= CallMigrad();
398  if(dbThis) cout << "... called MIGRAD" << success << endl;
399  scanMarked();
400  if(dbThis) cout << "... scanned" << success << endl;
401  success &= this->endOfFit();
402  return success;
403 }

◆ doMinosFit()

bool Minimiser::doMinosFit ( )

Definition at line 404 of file Minimiser.cpp.

404  {
405  bool dbThis=false;
406  bool success = true;
407  success &= prepFit();
408  success &= CallMinos();
409  if(dbThis) cout << "called MINOS" << endl;
410  scanMarked();
411  success &= this->endOfFit();
412  return success;
413 }

◆ doSeekFit()

bool Minimiser::doSeekFit ( int  maxCalls = 100,
int  devs = 5 
)

Definition at line 415 of file Minimiser.cpp.

415  {
416  bool dbThis=false;
417  bool success = true;
418  success &= prepFit();
419  success &= CallSeek(maxCalls, devs);
420  if(dbThis) cout << "called SEEK" << endl;
421  //scanMarked();
422  success &= this->endOfFit();
423  return success;
424 }
bool CallSeek(int maxCalls=100, int devs=5)
Definition: Minimiser.cpp:353

◆ doSimplexFit()

bool Minimiser::doSimplexFit ( int  maxCalls = 300,
double  tolerance = 1. 
)

Definition at line 426 of file Minimiser.cpp.

426  {
427  bool dbThis=false;
428  bool success = true;
429  success &= prepFit();
430  success &= CallSimplex(maxCalls, tolerance);
431  if(dbThis) cout << "called SIMPLEX" << endl;
432  //scanMarked();
433  success &= this->endOfFit();
434  return success;
435 }
bool CallSimplex(int maxCalls=300, double tolerance=1.)
Definition: Minimiser.cpp:339

◆ endOfFit()

bool Minimiser::endOfFit ( )
protected

Definition at line 250 of file Minimiser.cpp.

250  {
251  if(! parsOK())return false;
253  theFunction()->endFit();
255  return true;
256 }
TMatrixTSym< double > covMatrixFull()
Definition: Minimiser.cpp:525
const MinuitParameterSet * parSet() const
Definition: Minimiser.h:63
virtual void endFit()=0
bool setCovMatrix(const CovMatrix &)
Set the covariance matrix.
IMinimisable * theFunction()
Definition: Minimiser.h:60
bool parsOK() const
Definition: Minimiser.cpp:258
bool setParametersToResult()
Definition: Minimiser.cpp:221

◆ Eval()

Int_t Minimiser::Eval ( Int_t  npar,
Double_t *  grad,
Double_t &  fval,
Double_t *  par,
Int_t  flag 
)
protected

Definition at line 56 of file Minimiser.cpp.

61  {
62  bool dbThis=false;
63  if(dbThis) cout << "Eval got called " << endl;
64  if(! this->OK()){
65  cout << "ERROR in Minimiser::Eval (file: Minimiser.C)"
66  << " Got called although I'm not OK" << endl;
67  fval = -9999;
68  return -1;
69  }
70  this->updateFitParameters(par);
71  fval = this->getFCNVal();
72  if (flag == 4) {
74  //calculate GRAD, the first derivatives of FVAL
75  vector<double> gradient(npar);
76  this->FCNGradient(gradient);
77  for(unsigned int i = 0; i < static_cast<unsigned int>(npar); i++){
78  grad[i]=gradient[i];
79  }
80  }
81  }
82  return -1;
83  (void)npar;
84 }
void FCNGradient(std::vector< double > &grad)
Definition: Minimiser.cpp:281
bool _useAnalyticGradient
Definition: Minimiser.h:26
bool updateFitParameters(Double_t *p)
Definition: Minimiser.cpp:238
double getFCNVal()
Definition: Minimiser.cpp:272
bool OK() const
Definition: Minimiser.cpp:268

◆ FCNGradient()

void Minimiser::FCNGradient ( std::vector< double > &  grad)

Definition at line 281 of file Minimiser.cpp.

281  {
282  if(! this->OK()){
283  cout << "ERROR IN Minimiser::FCNGradient()"
284  << " I'm not OK!!" << endl;
285  }
286  return theFunction()->Gradient(grad);
287 }
IMinimisable * theFunction()
Definition: Minimiser.h:60
virtual void Gradient(std::vector< double > &grad)
Definition: IMinimisable.h:24
bool OK() const
Definition: Minimiser.cpp:268

◆ fcnOK()

bool Minimiser::fcnOK ( ) const

Definition at line 263 of file Minimiser.cpp.

263  {
264  if(0 == theFunction()) return false;
265  return true;
266 }
IMinimisable * theFunction()
Definition: Minimiser.h:60

◆ getDefaultMinimiser()

Minimiser * Minimiser::getDefaultMinimiser ( )
static

Definition at line 23 of file Minimiser.cpp.

23  {
24 
25  if(0 == _defaultMinimiser){
27  }
28  return _defaultMinimiser;
29 }
Minimiser(IMinimisable *fitFunction=0, const double errdef=1.)
Definition: Minimiser.cpp:32
static Minimiser * _defaultMinimiser
Definition: Minimiser.h:27

◆ getFCNVal()

double Minimiser::getFCNVal ( )

Definition at line 272 of file Minimiser.cpp.

272  {
273  if(! this->OK()){
274  cout << "ERROR IN Minimiser::getFCNVal()"
275  << " I'm not OK!!" << endl;
276  return -9999.0;
277  }
278  return theFunction()->getVal();
279 }
IMinimisable * theFunction()
Definition: Minimiser.h:60
bool OK() const
Definition: Minimiser.cpp:268
virtual double getVal()=0

◆ getMaxCalls()

int Minimiser::getMaxCalls ( ) const

Definition at line 52 of file Minimiser.cpp.

52  {
53  return _maxCalls;
54 }

◆ getParPtr() [1/2]

IMinuitParameter * Minimiser::getParPtr ( unsigned int  i)

Definition at line 149 of file Minimiser.cpp.

149  {
150  if(0 == _parSet) return 0;
151  if(i >= nPars()) return 0;
152  return _parSet->getParPtr(i);
153 }
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
IMinuitParameter * getParPtr(unsigned int i)
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ getParPtr() [2/2]

const IMinuitParameter * Minimiser::getParPtr ( unsigned int  i) const

Definition at line 154 of file Minimiser.cpp.

154  {
155  if(0 == _parSet) return 0;
156  if(i >= nPars()) return 0;
157  return _parSet->getParPtr(i);
158 }
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
IMinuitParameter * getParPtr(unsigned int i)
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ init()

bool Minimiser::init ( )
protected

Definition at line 105 of file Minimiser.cpp.

105  {
106  bool dbThis=true;
107  if(dbThis) cout << "Minimiser::init(): you called me" << endl;
108  if(0 == theFunction()){
109  std::cout << "ERROR IN Minimiser::init():"
110  << " the function-ptr is empty."
111  << " I won't do anything for now."
112  << std::endl;
113  return false;
114  }
115  if(dbThis) cout << " ... calling theFunction()->beginFit()" << endl;
116  theFunction()->beginFit();
117 
119  if(0 == _parSet){
120  std::cout << "ERROR IN Minimiser::init():"
121  << " theFunction()->getParSet() returned empty pointer"
122  << " I won't do anything for now."
123  << std::endl;
124  return false;
125  }
126 
127  MakeSpace(nPars());
128 
129  if(dbThis) cout << "... made space, now initialising variables" << endl;
131  if(dbThis) cout << " initialised variables." << endl;
132 
134 
135  if(dbThis) cout << "Minimiser::init(): returning true" << endl;
136  return true;
137 }
bool _useAnalyticGradient
Definition: Minimiser.h:26
bool initialiseVariables()
Definition: Minimiser.cpp:170
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
IMinimisable * theFunction()
Definition: Minimiser.h:60
virtual void beginFit()=0
virtual bool useAnalyticGradient()
Definition: IMinimisable.h:31
bool MakeSpace(int needSpace)
Definition: Minimiser.cpp:97
virtual MinuitParameterSet * getParSet()=0
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ initialiseVariables()

bool Minimiser::initialiseVariables ( )

Definition at line 170 of file Minimiser.cpp.

170  {
171  bool dbThis=false;
172  if(! parsOK()) return false;
173 
174  bool success=true;
175  if(dbThis) {
176  cout << "Minimiser::initialiseVariables() called. " << endl;
177  cout << "\n\t(declaring them to MINUIT)" << endl;
178  }
179 
180  //remove hidden MinuitParameter
181  for(unsigned int i=0; i < nPars(); i++){
182  if(getParPtr(i)->hidden()){
183  if(dbThis) cout << i << ")" << getParPtr(i)->name() << endl;
184  parSet()->unregister(getParPtr(i));
185  i--;
186  }
187  }
188 
189  //temporarilyQuiet();
190  for(unsigned int i=0; i < nPars(); i++){
191  int ierflag=0;
192  //if(! getParPtr(i)->hidden()){ //hidden MinuitParamter already removed
193  if(dbThis) cout << i << ")" << getParPtr(i)->name() << endl;
194  double step = getParPtr(i)->stepInit();
195  if(getParPtr(i)->iFixInit()) step=0;
196  this->mnparm( i
197  , getParPtr(i)->name().c_str()
198  , getParPtr(i)->meanInit()
199  , step
200  , getParPtr(i)->minInit()
201  , getParPtr(i)->maxInit()
202  , ierflag);
203  //if(getParPtr(i)->iFixInit()) FixParameter(i);
204  //}
205  //getParPtr(i)->associate(this, i);
206  success &= ! ierflag;
207  }
208  if(dbThis){
209  cout << "Minimiser::initialiseVariables():"
210  << "done declaring variables, now:"
211  << "theFunction()->parametersChanged();"
212  << endl;
213  }
215  if(dbThis) cout << "Minimiser::initialiseVariables():"
216  << " all done - returning " << success << endl;
217  //resetPrintLevel();
218  return success;
219 }
const MinuitParameterSet * parSet() const
Definition: Minimiser.h:63
virtual const std::string & name() const =0
IMinimisable * theFunction()
Definition: Minimiser.h:60
bool unregister(IMinuitParameter *patPtr)
virtual bool hidden() const =0
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
virtual double stepInit() const =0
bool parsOK() const
Definition: Minimiser.cpp:258
virtual void parametersChanged()=0
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ isConverged()

bool Minimiser::isConverged ( )

Check if the fit status is CONVERGED

Definition at line 592 of file Minimiser.cpp.

592  {
594 }
bool isStatus(Minimiser::FitStatus)
Definition: Minimiser.cpp:562
CONVERGED: Full accurate covariance matrix.
Definition: Minimiser.h:125

◆ isStatus()

bool Minimiser::isStatus ( Minimiser::FitStatus  stat)

Check if the fit status is of the given type.

Definition at line 562 of file Minimiser.cpp.

562  {
563  return status() == stat ;
564 }

◆ isStatusAtLeast()

bool Minimiser::isStatusAtLeast ( Minimiser::FitStatus  stat)

Check if the fit status is >= the given status type.

Definition at line 566 of file Minimiser.cpp.

566  {
567  return status() >= stat ;
568 }

◆ MakeSpace()

bool Minimiser::MakeSpace ( int  needSpace)
protected

Definition at line 97 of file Minimiser.cpp.

97  {
98  //return true;
99 
100  this->DeleteArrays();
101  this->BuildArrays(needSpace + 2); // +2 for good luck
102  TMinInit();
103  return true;
104 }

◆ nPars()

unsigned int Minimiser::nPars ( ) const

Definition at line 145 of file Minimiser.cpp.

145  {
146  if(0 == _parSet) return 0;
147  return _parSet->size();
148 }
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
unsigned int size() const

◆ OK()

bool Minimiser::OK ( ) const

Definition at line 268 of file Minimiser.cpp.

268  {
269  return parsOK() && fcnOK();
270 }
bool fcnOK() const
Definition: Minimiser.cpp:263
bool parsOK() const
Definition: Minimiser.cpp:258

◆ parSet() [1/2]

const MinuitParameterSet* MINT::Minimiser::parSet ( ) const
inline

Definition at line 63 of file Minimiser.h.

63 { return _parSet;}
MinuitParameterSet * _parSet
Definition: Minimiser.h:30

◆ parSet() [2/2]

MinuitParameterSet* MINT::Minimiser::parSet ( )
inline

Definition at line 64 of file Minimiser.h.

64 { return _parSet;}
MinuitParameterSet * _parSet
Definition: Minimiser.h:30

◆ parsOK()

bool Minimiser::parsOK ( ) const

Definition at line 258 of file Minimiser.cpp.

258  {
259  if(0 == _parSet) return false;
260  if(0 == nPars()) return false;
261  return true;
262 }
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ prepFit()

bool Minimiser::prepFit ( )

Definition at line 381 of file Minimiser.cpp.

381  {
382  bool dbThis=false;
383  bool success=true;
384  success &= SetSomeMinuitOptions();
385  theFunction()->beginFit();
386  success &= this->initialiseVariables();
387  if(dbThis) cout << "re-initialised variables" << endl;
388  return success;
389 }
bool initialiseVariables()
Definition: Minimiser.cpp:170
IMinimisable * theFunction()
Definition: Minimiser.h:60
virtual void beginFit()=0
bool SetSomeMinuitOptions()
Definition: Minimiser.cpp:303

◆ printResultVsInput()

void Minimiser::printResultVsInput ( std::ostream &  os = std::cout) const

Definition at line 501 of file Minimiser.cpp.

501  {
502  if(0 == _parSet) return;
504 }
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
void printResultVsInput(std::ostream &os=std::cout) const

◆ printStatus()

int Minimiser::printStatus ( )

Print the fit status.

Definition at line 570 of file Minimiser.cpp.

570  {
571  int stat = status() ;
572  cout << "Fit status: " << stat << endl ;
573  switch(stat) {
574  case NOTCALCULATED :
575  cout << "FAILED: Covariance matrix not calculated at all." << endl ;
576  break ;
577  case NOTACCURATE :
578  cout << "FAILED: Covariance matrix approximation only, not accurate." << endl ;
579  break ;
580  case NOTPOSDEF :
581  cout << "FAILED: Full covariance matrix, but forced positive-definite." << endl ;
582  break ;
583  case CONVERGED :
584  cout << "CONVERGED: Full accurate covariance matrix." << endl ;
585  break ;
586  default :
587  cout << "UNKNOWN." << endl ;
588  }
589  return stat ;
590 }
FAILED: Covariance matrix approximation only, not accurate.
Definition: Minimiser.h:123
FAILED: Full covariance matrix, but forced positive-definite.
Definition: Minimiser.h:124
CONVERGED: Full accurate covariance matrix.
Definition: Minimiser.h:125
FAILED: Covariance matrix not calculated at all.
Definition: Minimiser.h:122

◆ resetPrintLevel()

bool Minimiser::resetPrintLevel ( )

Definition at line 300 of file Minimiser.cpp.

300  {
301  return setPrintLevel(-9999);
302 }
bool setPrintLevel(int level=-1)
Definition: Minimiser.cpp:289

◆ scan() [1/2]

TGraph * Minimiser::scan ( int  i,
double  from = 0,
double  to = 0 
)

note that the index i is the one in the parameter list which goes from 0 to n-1 (i.e. C-style). This corresponds to Minuit's parameter number i+1. (so if you want Minuit's fit parameter 1, pass it 1-1=0)

Definition at line 473 of file Minimiser.cpp.

473  {
474  // note that the index i is the one in the parameter list
475  // which goes from 0 to n-1 (i.e. C-style).
476  // This corresponds to Minuit's parameter number i+1.
477  // (so if you want Minuit's fit parameter 1, pass it 1-1=0)
478  IMinuitParameter* p = getParPtr(i);
479  if(0 == p) return 0;
480 
481  double points = 100;
482  string fname = "scan_" + p->name() + ".root";
483 
484  Double_t arglist[10] = {0};
485  Int_t ierflg=0;
486 
487  arglist[0]=i+1; arglist[1]=points; arglist[2]=from; arglist[3]=to;
488  this->mnexcm("SCAN", arglist, 4, ierflg);
489  TGraph *gr = (TGraph*) this->GetPlot();
490  if(0 == gr){
491  cout << " didn't get plot " << endl;
492  }else{
493  TFile fscan(fname.c_str(), "RECREATE");
494  fscan.cd();
495  gr->Write();
496  fscan.Close();
497  }
498  return gr;
499 }
virtual const std::string & name() const =0
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
Double_t arglist[10]
Definition: Minimiser.h:23

◆ scan() [2/2]

TGraph * Minimiser::scan ( IMinuitParameter fp,
double  from = 0,
double  to = 0 
)

Definition at line 459 of file Minimiser.cpp.

459  {
460  if(fp.parSet() != this->parSet()){
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;
466  fp.print();
467  cout << endl;
468  return 0;
469  }
470  return scan(fp.parSetIndex(), from, to);
471 }
virtual const MinuitParameterSet * parSet() const =0
const MinuitParameterSet * parSet() const
Definition: Minimiser.h:63
TGraph * scan(int i, double from=0, double to=0)
Definition: Minimiser.cpp:473
virtual void print(std::ostream &os=std::cout) const =0
virtual int parSetIndex() const =0

◆ scanAll()

bool Minimiser::scanAll ( )

Definition at line 448 of file Minimiser.cpp.

448  {
449  bool sc=true;
450  if(0 == nPars()) return false;
451  for(unsigned int i=0; i < nPars(); i++){
453  if(0 == p) continue;
454  sc &= (bool) scan(i, p->scanMin(), p->scanMax());
455  }
456  return sc;
457 }
virtual double scanMin() const =0
TGraph * scan(int i, double from=0, double to=0)
Definition: Minimiser.cpp:473
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
unsigned int nPars() const
Definition: Minimiser.cpp:145
virtual double scanMax() const =0

◆ scanMarked()

bool Minimiser::scanMarked ( )

Definition at line 438 of file Minimiser.cpp.

438  {
439  bool sc=true;
440  if(0 == nPars()) return false;
441  for(unsigned int i=0; i < nPars(); i++){
443  if(0 == p || (! p->scan()) ) continue;
444  sc &= (bool) scan(i, p->scanMin(), p->scanMax());
445  }
446  return sc;
447 }
virtual double scanMin() const =0
TGraph * scan(int i, double from=0, double to=0)
Definition: Minimiser.cpp:473
virtual bool scan() const =0
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
unsigned int nPars() const
Definition: Minimiser.cpp:145
virtual double scanMax() const =0

◆ setMaxCalls()

void Minimiser::setMaxCalls ( int  maxCalls)

Definition at line 49 of file Minimiser.cpp.

49  {
50  _maxCalls = maxCalls;
51 }

◆ setParametersToResult()

bool Minimiser::setParametersToResult ( )
protected

Definition at line 221 of file Minimiser.cpp.

221  {
222  if(! parsOK())return false;
223 
224  Double_t mean, err, errN, errP;
225  Double_t gcc;
226  for(unsigned int i=0; i < nPars(); i++){
227  //if(! getParPtr(i)->hidden()){
228  this->mnerrs(i, errP, errN, err, gcc);
229  this->GetParameter(i, mean, err);
230  mean += this->getParPtr(i)->blinding();
231  this->getParPtr(i)->setResult(mean, err, errP, errN);
232  //}
233  }
235  return true;
236 }
IMinimisable * theFunction()
Definition: Minimiser.h:60
virtual double blinding() const =0
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
bool parsOK() const
Definition: Minimiser.cpp:258
virtual void parametersChanged()=0
virtual void setResult(double fitMean, double fitErr, double fitErrPos, double fitErrNeg)=0
unsigned int nPars() const
Definition: Minimiser.cpp:145

◆ setPrintLevel()

bool Minimiser::setPrintLevel ( int  level = -1)

Definition at line 289 of file Minimiser.cpp.

289  {
290  if(level >=0 )_printLevel=level;
291  arglist[0] = _printLevel;
292  TMinuit::mnexcm("SET PRINTOUT", arglist , 1, ierflg);
293  return (! ierflg);
294 }
Double_t arglist[10]
Definition: Minimiser.h:23

◆ SetSomeMinuitOptions()

bool Minimiser::SetSomeMinuitOptions ( )

Definition at line 303 of file Minimiser.cpp.

303  {
304  bool success = true;
305  success &= setPrintLevel();
306  arglist[0] = _errdef ;
307  TMinuit::mnexcm("SET ERR", arglist , 1, ierflg);
308  success &= (! ierflg);
309  arglist[0] = 1;
310  TMinuit::mnexcm("SET STRATEGY", arglist , 1, ierflg);
311  success &= (! ierflg);
312  if(_useAnalyticGradient)TMinuit::mnexcm("SET GRADIENT", arglist , 1, ierflg);
313  else TMinuit::mnexcm("SET NOGRADIENT", arglist , 1, ierflg);
314  return success;
315 }
bool _useAnalyticGradient
Definition: Minimiser.h:26
double _errdef
Definition: Minimiser.h:37
bool setPrintLevel(int level=-1)
Definition: Minimiser.cpp:289
Double_t arglist[10]
Definition: Minimiser.h:23

◆ status()

int Minimiser::status ( )

Get the fit status

Definition at line 555 of file Minimiser.cpp.

555  {
556  double fmin, fedm, errdef ;
557  int npari, nparx, status ;
558  mnstat( fmin, fedm, errdef, npari, nparx, status ) ;
559  return status ;
560 }

◆ temporarilyQuiet()

bool Minimiser::temporarilyQuiet ( )

Definition at line 295 of file Minimiser.cpp.

295  {
296  arglist[0] = -1;
297  TMinuit::mnexcm("SET PRINTOUT", arglist , 1, ierflg);
298  return (! ierflg);
299 }
Double_t arglist[10]
Definition: Minimiser.h:23

◆ theFunction() [1/2]

IMinimisable* MINT::Minimiser::theFunction ( )
inline

Definition at line 60 of file Minimiser.h.

60 { return _theFunction;}
IMinimisable * _theFunction
Definition: Minimiser.h:33

◆ theFunction() [2/2]

const IMinimisable* MINT::Minimiser::theFunction ( ) const
inline

Definition at line 61 of file Minimiser.h.

61 { return _theFunction;}
IMinimisable * _theFunction
Definition: Minimiser.h:33

◆ TMinInit()

void Minimiser::TMinInit ( )
protected

Definition at line 86 of file Minimiser.cpp.

86  {
87  fStatus = 0;
88  fEmpty = 0;
89  fObjectFit = 0;
90  fMethodCall = 0;
91  fPlot = 0;
92  fGraphicsMode = kTRUE;
93  SetMaxIterations();
94  mninit(5,6,7);
95 }

◆ updateFitParameters()

bool Minimiser::updateFitParameters ( Double_t *  p)
protected

Definition at line 238 of file Minimiser.cpp.

238  {
239  if(! parsOK())return false;
240 
241  for(unsigned int i=0; i < nPars(); i++){
242  //if(! getParPtr(i)->hidden()){
243  //getParPtr(i)->setCurrentFitVal(par[i]);
244  getParPtr(i)->setCurrentFitVal(par[i] + this->getParPtr(i)->blinding());
245  //}
246  }
248  return true;
249 }
IMinimisable * theFunction()
Definition: Minimiser.h:60
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
bool parsOK() const
Definition: Minimiser.cpp:258
virtual void parametersChanged()=0
virtual void setCurrentFitVal(double pval)=0
unsigned int nPars() const
Definition: Minimiser.cpp:145

Member Data Documentation

◆ _defaultMaxCalls

int Minimiser::_defaultMaxCalls =100000
staticprotected

Definition at line 28 of file Minimiser.h.

◆ _defaultMinimiser

Minimiser * Minimiser::_defaultMinimiser =0
staticprotected

Definition at line 27 of file Minimiser.h.

◆ _errdef

double MINT::Minimiser::_errdef
protected

Definition at line 37 of file Minimiser.h.

◆ _maxCalls

int MINT::Minimiser::_maxCalls
protected

Definition at line 34 of file Minimiser.h.

◆ _parSet

MinuitParameterSet* MINT::Minimiser::_parSet
protected

Definition at line 30 of file Minimiser.h.

◆ _printLevel

int MINT::Minimiser::_printLevel
protected

Definition at line 36 of file Minimiser.h.

◆ _theFunction

IMinimisable* MINT::Minimiser::_theFunction
protected

Definition at line 33 of file Minimiser.h.

◆ _useAnalyticGradient

bool MINT::Minimiser::_useAnalyticGradient
protected

Definition at line 26 of file Minimiser.h.

◆ arglist

Double_t MINT::Minimiser::arglist[10]
mutableprivate

Definition at line 23 of file Minimiser.h.

◆ ierflg

Int_t MINT::Minimiser::ierflg
mutableprivate

Definition at line 24 of file Minimiser.h.


The documentation for this class was generated from the following files: