Logo ROOT  
Reference Guide
MnApplication.cxx
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #include "Minuit2/MnApplication.h"
14 #include "Minuit2/MnPrint.h"
15 
16 namespace ROOT {
17 
18 namespace Minuit2 {
19 
20 // constructor from non-gradient functions
22  unsigned int nfcn)
23  : fFCN(fcn), fState(state), fStrategy(stra), fNumCall(nfcn), fUseGrad(false)
24 {
25 }
26 
27 // constructor from functions
29  unsigned int nfcn)
30  : fFCN(fcn), fState(state), fStrategy(stra), fNumCall(nfcn), fUseGrad(true)
31 {
32 }
33 
34 FunctionMinimum MnApplication::operator()(unsigned int maxfcn, double toler)
35 {
36  // constructor from macfcn calls and tolerance
37  MnPrint print("MnApplication");
38 
39  assert(fState.IsValid());
40  unsigned int npar = VariableParameters();
41  // assert(npar > 0);
42  if (maxfcn == 0)
43  maxfcn = 200 + 100 * npar + 5 * npar * npar;
44 
45  const FCNBase &fcn = Fcnbase();
46  assert(!fUseGrad || dynamic_cast<const FCNGradientBase *>(&fcn) != nullptr);
47 
48  FunctionMinimum min =
49  fUseGrad ? Minimizer().Minimize(static_cast<const FCNGradientBase &>(fcn), fState, fStrategy, maxfcn, toler)
50  : Minimizer().Minimize(fcn, fState, fStrategy, maxfcn, toler);
51  fNumCall += min.NFcn();
52  fState = min.UserState();
53 
54  const std::vector<ROOT::Minuit2::MinimumState> &iterationStates = min.States();
55  print.Debug("State resulting from Migrad after", iterationStates.size(), "iterations:", fState);
56 
57  print.Debug([&](std::ostream &os) {
58  for (unsigned int i = 0; i < iterationStates.size(); ++i) {
59  // std::cout << iterationStates[i] << std::endl;
60  const ROOT::Minuit2::MinimumState &st = iterationStates[i];
61  os << "\n----------> Iteration " << i << '\n';
62  int pr = os.precision(18);
63  os << " FVAL = " << st.Fval() << " Edm = " << st.Edm() << " Nfcn = " << st.NFcn() << '\n';
64  os.precision(pr);
65  os << " Error matrix change = " << st.Error().Dcovar() << '\n';
66  os << " Internal parameters : ";
67  for (int j = 0; j < st.size(); ++j)
68  os << " p" << j << " = " << st.Vec()(j);
69  }
70  });
71 
72  return min;
73 }
74 
75 // facade: forward interface of MnUserParameters and MnUserTransformation
76 // via MnUserParameterState
77 
78 const std::vector<MinuitParameter> &MnApplication::MinuitParameters() const
79 {
80  // access to parameters (row-wise)
81  return fState.MinuitParameters();
82 }
83 // access to parameters and errors in column-wise representation
84 std::vector<double> MnApplication::Params() const
85 {
86  return fState.Params();
87 }
88 std::vector<double> MnApplication::Errors() const
89 {
90  return fState.Errors();
91 }
92 
93 const MinuitParameter &MnApplication::Parameter(unsigned int i) const
94 {
95  // access to single Parameter
96  return fState.Parameter(i);
97 }
98 
99 void MnApplication::Add(const char *name, double val, double err)
100 {
101  // add free Parameter
102  fState.Add(name, val, err);
103 }
104 
105 void MnApplication::Add(const char *name, double val, double err, double low, double up)
106 {
107  // add limited Parameter
108  fState.Add(name, val, err, low, up);
109 }
110 
111 void MnApplication::Add(const char *name, double val)
112 {
113  // add const Parameter
114  fState.Add(name, val);
115 }
116 
117 // interaction via external number of Parameter
118 void MnApplication::Fix(unsigned int i)
119 {
120  fState.Fix(i);
121 }
122 void MnApplication::Release(unsigned int i)
123 {
124  fState.Release(i);
125 }
126 void MnApplication::SetValue(unsigned int i, double val)
127 {
128  // set value for parameter i
129  fState.SetValue(i, val);
130 }
131 void MnApplication::SetError(unsigned int i, double val)
132 {
133  // set parameter error
134  fState.SetError(i, val);
135 }
136 void MnApplication::SetLimits(unsigned int i, double low, double up)
137 {
138  // set parameter limits
139  fState.SetLimits(i, low, up);
140 }
141 void MnApplication::RemoveLimits(unsigned int i)
142 {
143  fState.RemoveLimits(i);
144 }
145 
146 double MnApplication::Value(unsigned int i) const
147 {
148  return fState.Value(i);
149 }
150 double MnApplication::Error(unsigned int i) const
151 {
152  return fState.Error(i);
153 }
154 
155 // interaction via Name of Parameter
156 void MnApplication::Fix(const char *i)
157 {
158  fState.Fix(i);
159 }
160 void MnApplication::Release(const char *i)
161 {
162  fState.Release(i);
163 }
164 void MnApplication::SetValue(const char *i, double val)
165 {
166  fState.SetValue(i, val);
167 }
168 void MnApplication::SetError(const char *i, double val)
169 {
170  fState.SetError(i, val);
171 }
172 void MnApplication::SetLimits(const char *i, double low, double up)
173 {
174  fState.SetLimits(i, low, up);
175 }
176 void MnApplication::RemoveLimits(const char *i)
177 {
178  fState.RemoveLimits(i);
179 }
181 {
182  fState.SetPrecision(eps);
183 }
184 
185 double MnApplication::Value(const char *i) const
186 {
187  return fState.Value(i);
188 }
189 double MnApplication::Error(const char *i) const
190 {
191  return fState.Error(i);
192 }
193 
194 unsigned int MnApplication::Index(const char *name) const
195 {
196  // convert name into external number of Parameter
197  return fState.Index(name);
198 }
199 
200 const char *MnApplication::Name(unsigned int i) const
201 {
202  // convert external number into name of Parameter
203  return fState.Name(i);
204 }
205 
206 double MnApplication::Int2ext(unsigned int i, double val) const
207 {
208  // transformation internal -> external
209  return fState.Int2ext(i, val);
210 }
211 double MnApplication::Ext2int(unsigned int e, double val) const
212 {
213  // transformation external -> internal
214  return fState.Ext2int(e, val);
215 }
216 unsigned int MnApplication::IntOfExt(unsigned int ext) const
217 {
218  // get internal index for external parameter with index ext
219  return fState.IntOfExt(ext);
220 }
221 unsigned int MnApplication::ExtOfInt(unsigned int internal) const
222 {
223  // get external index for internal parameter with index internal
224  return fState.ExtOfInt(internal);
225 }
227 {
228  // get number of variable parameters
229  return fState.VariableParameters();
230 }
231 
232 } // namespace Minuit2
233 
234 } // namespace ROOT
ROOT::Minuit2::MinuitParameter
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
Definition: MinuitParameter.h:33
ROOT::Minuit2::MnApplication::Fix
void Fix(unsigned int)
Definition: MnApplication.cxx:118
ROOT::Minuit2::MinimumState::Edm
double Edm() const
Definition: MinimumState.h:57
ROOT::Minuit2::MnApplication::RemoveLimits
void RemoveLimits(unsigned int)
Definition: MnApplication.cxx:141
e
#define e(i)
Definition: RSha256.hxx:103
ROOT::Minuit2::MnApplication::SetError
void SetError(unsigned int, double)
Definition: MnApplication.cxx:131
ROOT::Minuit2::MnUserParameterState::Error
double Error(unsigned int) const
Definition: MnUserParameterState.cxx:409
ROOT::Minuit2::MnApplication::Add
void Add(const char *Name, double val, double err)
Definition: MnApplication.cxx:99
ROOT::Minuit2::MnApplication::fUseGrad
bool fUseGrad
Definition: MnApplication.h:76
ROOT::Minuit2::MinimumState
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
ROOT::Minuit2::MnPrint::Debug
void Debug(const Ts &... args)
Definition: MnPrint.h:138
ROOT::Minuit2::MnUserParameterState::MinuitParameters
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
Definition: MnUserParameterState.cxx:213
ROOT::Minuit2::MnApplication::SetLimits
void SetLimits(unsigned int, double, double)
Definition: MnApplication.cxx:136
ROOT::Minuit2::MnUserParameterState::RemoveLimits
void RemoveLimits(unsigned int)
Definition: MnUserParameterState.cxx:394
FunctionMinimum.h
ROOT::Minuit2::FCNBase
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:45
ROOT::Minuit2::MnApplication::Ext2int
double Ext2int(unsigned int, double) const
Definition: MnApplication.cxx:211
ROOT::Minuit2::MnApplication::Error
double Error(unsigned int) const
Definition: MnApplication.cxx:150
ModularFunctionMinimizer.h
ROOT::Minuit2::MnApplication::Release
void Release(unsigned int)
Definition: MnApplication.cxx:122
ROOT::Minuit2::MnUserParameterState::SetError
void SetError(unsigned int, double)
Definition: MnUserParameterState.cxx:341
ROOT::Minuit2::MnApplication::MinuitParameters
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
Definition: MnApplication.cxx:78
ROOT::Minuit2::MnApplication::Fcnbase
virtual const FCNBase & Fcnbase() const
Definition: MnApplication.h:67
ROOT::Minuit2::MnApplication::Value
double Value(unsigned int) const
Definition: MnApplication.cxx:146
ROOT::Minuit2::MinimumState::NFcn
int NFcn() const
Definition: MinimumState.h:58
ROOT::Minuit2::MnApplication::SetPrecision
void SetPrecision(double)
Definition: MnApplication.cxx:180
ROOT::Minuit2::MnUserParameterState::VariableParameters
unsigned int VariableParameters() const
Definition: MnUserParameterState.cxx:506
ROOT::Minuit2::MnApplication::IntOfExt
unsigned int IntOfExt(unsigned int) const
Definition: MnApplication.cxx:216
ROOT::Minuit2::MnUserParameterState::SetPrecision
void SetPrecision(double eps)
Definition: MnUserParameterState.cxx:517
ROOT::Minuit2::MnUserParameterState::SetLimits
void SetLimits(unsigned int, double, double)
Definition: MnUserParameterState.cxx:347
ROOT::Minuit2::MnUserParameterState::IsValid
bool IsValid() const
Definition: MnUserParameterState.h:106
ROOT::Minuit2::FunctionMinimum::UserState
const MnUserParameterState & UserState() const
Definition: FunctionMinimum.h:71
MnApplication.h
ROOT::Minuit2::MnApplication::operator()
virtual FunctionMinimum operator()(unsigned int maxfcn=0, double tolerance=0.1)
Minimize the function.
Definition: MnApplication.cxx:34
ROOT::Minuit2::MinimumState::Error
const MinimumError & Error() const
Definition: MinimumState.h:54
ROOT::Minuit2::MnApplication::Params
std::vector< double > Params() const
Definition: MnApplication.cxx:84
ROOT::Minuit2::MnApplication::ExtOfInt
unsigned int ExtOfInt(unsigned int) const
Definition: MnApplication.cxx:221
ROOT::Minuit2::MnUserParameterState::Name
const char * Name(unsigned int) const
Definition: MnUserParameterState.cxx:473
FCNGradientBase.h
ROOT::Minuit2::MnApplication::fStrategy
MnStrategy fStrategy
Definition: MnApplication.h:74
ROOT::Minuit2::MnApplication::VariableParameters
unsigned int VariableParameters() const
Definition: MnApplication.cxx:226
ROOT::Minuit2::MnUserParameterState::SetValue
void SetValue(unsigned int, double)
Definition: MnUserParameterState.cxx:328
ROOT::Minuit2::MinimumState::Fval
double Fval() const
Definition: MinimumState.h:56
ROOT::Minuit2::MnUserParameterState::Params
std::vector< double > Params() const
Definition: MnUserParameterState.cxx:219
ROOT::Minuit2::MnUserParameterState::Errors
std::vector< double > Errors() const
Definition: MnUserParameterState.cxx:224
ROOT::Minuit2::MnApplication::Index
unsigned int Index(const char *) const
Definition: MnApplication.cxx:194
ROOT::Minuit2::MinimumError::Dcovar
double Dcovar() const
Definition: MinimumError.h:65
ROOT::Minuit2::MnApplication::Minimizer
virtual ModularFunctionMinimizer & Minimizer()=0
ROOT::Minuit2::MnApplication::SetValue
void SetValue(unsigned int, double)
Definition: MnApplication.cxx:126
ROOT::Minuit2::MnUserParameterState::ExtOfInt
unsigned int ExtOfInt(unsigned int) const
Definition: MnUserParameterState.cxx:501
ROOT::Minuit2::MinimumState::size
int size() const
Definition: MinimumState.h:52
ROOT::Minuit2::MinimumState::Vec
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:51
ROOT::Minuit2::MnUserParameterState::Add
void Add(const std::string &name, double val, double err)
Definition: MnUserParameterState.cxx:236
ROOT::Minuit2::MnApplication::fState
MnUserParameterState fState
Definition: MnApplication.h:73
ROOT::Minuit2::FunctionMinimum
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
Definition: FunctionMinimum.h:33
ROOT::Minuit2::FCNGradientBase
Extension of the FCNBase for providing the analytical Gradient of the function.
Definition: FCNGradientBase.h:34
ROOT::Minuit2::MnUserParameterState
class which holds the external user and/or internal Minuit representation of the parameters and error...
Definition: MnUserParameterState.h:33
ROOT::Minuit2::MnUserParameterState::Parameter
const MinuitParameter & Parameter(unsigned int i) const
Definition: MnUserParameterState.cxx:230
ROOT::Minuit2::MnUserParameterState::IntOfExt
unsigned int IntOfExt(unsigned int) const
Definition: MnUserParameterState.cxx:496
ROOT::Minuit2::FunctionMinimum::NFcn
int NFcn() const
Definition: FunctionMinimum.h:82
ROOT::Minuit2::MnApplication::Errors
std::vector< double > Errors() const
Definition: MnApplication.cxx:88
ROOT::Minuit2::MnStrategy
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition: MnStrategy.h:27
ROOT::Minuit2::MnUserParameterState::Index
unsigned int Index(const std::string &) const
Definition: MnUserParameterState.cxx:467
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Minuit2::MnUserParameterState::Release
void Release(unsigned int)
Definition: MnUserParameterState.cxx:312
ROOT::Minuit2::MnUserParameterState::Ext2int
double Ext2int(unsigned int, double) const
Definition: MnUserParameterState.cxx:491
ROOT::Minuit2::MnUserParameterState::Value
double Value(unsigned int) const
Definition: MnUserParameterState.cxx:404
MnPrint.h
ROOT::Minuit2::FunctionMinimum::States
const std::vector< ROOT::Minuit2::MinimumState > & States() const
Definition: FunctionMinimum.h:68
ROOT::Minuit2::MnApplication::fNumCall
unsigned int fNumCall
Definition: MnApplication.h:75
for
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
ROOT::Minuit2::MnApplication::Parameter
const MinuitParameter & Parameter(unsigned int i) const
Definition: MnApplication.cxx:93
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MnApplication::Int2ext
double Int2ext(unsigned int, double) const
Definition: MnApplication.cxx:206
ROOT::Minuit2::MnUserParameterState::Int2ext
double Int2ext(unsigned int, double) const
Definition: MnUserParameterState.cxx:486
ROOT::Minuit2::MnUserParameterState::Fix
void Fix(unsigned int)
Definition: MnUserParameterState.cxx:297
ROOT::Minuit2::MnApplication::Name
const char * Name(unsigned int) const
Definition: MnApplication.cxx:200
ROOT::Minuit2::MnPrint
Definition: MnPrint.h:73
ROOT::Minuit2::MnApplication::MnApplication
MnApplication(const FCNBase &fcn, const MnUserParameterState &state, const MnStrategy &stra, unsigned int nfcn=0)
constructor from non-gradient functions
Definition: MnApplication.cxx:21
ROOT::Minuit2::ModularFunctionMinimizer::Minimize
virtual FunctionMinimum Minimize(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int stra=1, unsigned int maxfcn=0, double toler=0.1) const
Definition: ModularFunctionMinimizer.cxx:36