MINT2
Minimiser.h
Go to the documentation of this file.
1 #ifndef MINIMISER_HH
2 #define MINIMISER_HH
3 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
4 // status: Mon 9 Feb 2009 19:17:55 GMT
5 
6 #include "TMinuit.h"
7 #include "TMatrixTSym.h"
8 #include "Mint/NamedParameter.h"
9 #include "Mint/IMinimisable.h"
10 
11 #include <iostream>
12 #include <vector>
13 
14 class TGraph;
15 class TH2D;
16 
17 namespace MINT{
18 
19 class IMinuitParameter;
20 class FitParameter;
21 
22 class Minimiser : public TMinuit{
23  mutable Double_t arglist[10];
24  mutable Int_t ierflg;
25  protected:
28  static int _defaultMaxCalls;
29 
31  // MinuitParameterSet _floating;
32 
34  int _maxCalls;
35 
37  double _errdef ;
38 
39  bool init();
40  bool MakeSpace(int needSpace);
41  void TMinInit();
42 
43  bool updateFitParameters(Double_t* p);
44  bool setParametersToResult();
45  bool endOfFit();
46  // bool detachParameters();
47 
48  Int_t Eval(Int_t npar
49  , Double_t *grad
50  , Double_t &fval
51  , Double_t *par
52  , Int_t flag
53  );
54  public:
56 
57  Minimiser(IMinimisable* fitFunction=0, const double errdef = 1.);
58  virtual ~Minimiser();
59  bool attachFunction(IMinimisable* fcn);
61  const IMinimisable* theFunction() const{ return _theFunction;}
62 
63  const MinuitParameterSet* parSet()const{ return _parSet;}
65 
66  unsigned int nPars() const;
67  IMinuitParameter* getParPtr(unsigned int i);
68  const IMinuitParameter* getParPtr(unsigned int i) const;
69 
70  bool OK() const;
71  bool parsOK() const;
72  bool fcnOK() const;
73 
74  double getFCNVal();
75  void FCNGradient(std::vector<double>& grad);
76 
77  bool initialiseVariables();
78 
79  bool setPrintLevel(int level=-1);
80  bool temporarilyQuiet();
81  bool resetPrintLevel();
82 
83  bool SetSomeMinuitOptions();
84  bool CallMigrad();
85  bool CallMinos();
86  bool CallSeek(int maxCalls = 100, int devs = 5);
87  bool CallSimplex(int maxCalls = 300, double tolerance = 1. );
88  bool CallImprove(int maxCalls= 1500, int searches= 5);
89 
90  bool prepFit();
91  bool doFit();
92  bool doMinosFit();
93  bool doSeekFit(int maxCalls = 100, int devs = 5);
94  bool doSimplexFit(int maxCalls = 300, double tolerance = 1. );
95 
96  bool scanMarked();
97  bool scanAll();
102  TGraph* scan(int i, double from=0, double to=0);
103  TGraph* scan(IMinuitParameter& fp, double from=0, double to=0);
104 
105 
106  void setMaxCalls(int maxCalls);
107  int getMaxCalls() const;
108 
109  void printResultVsInput(std::ostream& os = std::cout) const;
110 
111  // get number of free parameters from TMinuit call:
112  // GetNumFreePars()
113 
114  TMatrixTSym<double> covMatrix();
115  TMatrixTSym<double> covMatrixFull();
116 
118  int status() ;
119 
121  enum FitStatus {
126  } ;
127 
130 
133 
135  int printStatus() ;
136 
138  bool isConverged() ;
139 
141  TGraph* contour(unsigned, unsigned, float nsigma = 1., unsigned npoints = 40) ;
142 
143 
144 };
145 }//namespace MINT
146 #endif
147 //
bool CallSeek(int maxCalls=100, int devs=5)
Definition: Minimiser.cpp:353
TMatrixTSym< double > covMatrixFull()
Definition: Minimiser.cpp:525
bool isConverged()
Definition: Minimiser.cpp:592
int getMaxCalls() const
Definition: Minimiser.cpp:52
const IMinimisable * theFunction() const
Definition: Minimiser.h:61
void FCNGradient(std::vector< double > &grad)
Definition: Minimiser.cpp:281
Minimiser(IMinimisable *fitFunction=0, const double errdef=1.)
Definition: Minimiser.cpp:32
IMinimisable * _theFunction
Definition: Minimiser.h:33
bool isStatusAtLeast(Minimiser::FitStatus)
Definition: Minimiser.cpp:566
const MinuitParameterSet * parSet() const
Definition: Minimiser.h:63
FAILED: Covariance matrix approximation only, not accurate.
Definition: Minimiser.h:123
bool _useAnalyticGradient
Definition: Minimiser.h:26
bool doSimplexFit(int maxCalls=300, double tolerance=1.)
Definition: Minimiser.cpp:426
bool initialiseVariables()
Definition: Minimiser.cpp:170
MinuitParameterSet * _parSet
Definition: Minimiser.h:30
TGraph * scan(int i, double from=0, double to=0)
Definition: Minimiser.cpp:473
MinuitParameterSet * parSet()
Definition: Minimiser.h:64
bool updateFitParameters(Double_t *p)
Definition: Minimiser.cpp:238
bool fcnOK() const
Definition: Minimiser.cpp:263
IMinimisable * theFunction()
Definition: Minimiser.h:60
double _errdef
Definition: Minimiser.h:37
virtual ~Minimiser()
Definition: Minimiser.cpp:46
void printResultVsInput(std::ostream &os=std::cout) const
Definition: Minimiser.cpp:501
double getFCNVal()
Definition: Minimiser.cpp:272
bool CallSimplex(int maxCalls=300, double tolerance=1.)
Definition: Minimiser.cpp:339
static Minimiser * getDefaultMinimiser()
Definition: Minimiser.cpp:23
FAILED: Full covariance matrix, but forced positive-definite.
Definition: Minimiser.h:124
static int _defaultMaxCalls
Definition: Minimiser.h:28
bool OK() const
Definition: Minimiser.cpp:268
TGraph * contour(unsigned, unsigned, float nsigma=1., unsigned npoints=40)
Definition: Minimiser.cpp:596
IMinuitParameter * getParPtr(unsigned int i)
Definition: Minimiser.cpp:149
Int_t Eval(Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag)
Definition: Minimiser.cpp:56
bool setPrintLevel(int level=-1)
Definition: Minimiser.cpp:289
bool attachFunction(IMinimisable *fcn)
Definition: Minimiser.cpp:139
bool parsOK() const
Definition: Minimiser.cpp:258
bool isStatus(Minimiser::FitStatus)
Definition: Minimiser.cpp:562
void setMaxCalls(int maxCalls)
Definition: Minimiser.cpp:49
bool temporarilyQuiet()
Definition: Minimiser.cpp:295
TMatrixTSym< double > covMatrix()
Definition: Minimiser.cpp:506
bool MakeSpace(int needSpace)
Definition: Minimiser.cpp:97
static Minimiser * _defaultMinimiser
Definition: Minimiser.h:27
Double_t arglist[10]
Definition: Minimiser.h:23
bool SetSomeMinuitOptions()
Definition: Minimiser.cpp:303
bool doSeekFit(int maxCalls=100, int devs=5)
Definition: Minimiser.cpp:415
unsigned int nPars() const
Definition: Minimiser.cpp:145
CONVERGED: Full accurate covariance matrix.
Definition: Minimiser.h:125
FAILED: Covariance matrix not calculated at all.
Definition: Minimiser.h:122
bool resetPrintLevel()
Definition: Minimiser.cpp:300
bool CallImprove(int maxCalls=1500, int searches=5)
Definition: Minimiser.cpp:367
bool setParametersToResult()
Definition: Minimiser.cpp:221