ROOT   Reference Guide
Searching...
No Matches
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
14#include "Minuit2/MnPrint.h"
15
16namespace ROOT {
17
18namespace Minuit2 {
19
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
34FunctionMinimum 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();
47
48 FunctionMinimum min =
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
78const std::vector<MinuitParameter> &MnApplication::MinuitParameters() const
79{
81 return fState.MinuitParameters();
82}
84std::vector<double> MnApplication::Params() const
85{
86 return fState.Params();
87}
88std::vector<double> MnApplication::Errors() const
89{
90 return fState.Errors();
91}
92
93const MinuitParameter &MnApplication::Parameter(unsigned int i) const
94{
96 return fState.Parameter(i);
97}
98
99void MnApplication::Add(const char *name, double val, double err)
100{
103}
104
105void MnApplication::Add(const char *name, double val, double err, double low, double up)
106{
108 fState.Add(name, val, err, low, up);
109}
110
111void MnApplication::Add(const char *name, double val)
112{
115}
116
117// interaction via external number of Parameter
118void MnApplication::Fix(unsigned int i)
119{
120 fState.Fix(i);
121}
122void MnApplication::Release(unsigned int i)
123{
124 fState.Release(i);
125}
126void MnApplication::SetValue(unsigned int i, double val)
127{
128 // set value for parameter i
129 fState.SetValue(i, val);
130}
131void MnApplication::SetError(unsigned int i, double val)
132{
133 // set parameter error
134 fState.SetError(i, val);
135}
136void MnApplication::SetLimits(unsigned int i, double low, double up)
137{
138 // set parameter limits
139 fState.SetLimits(i, low, up);
140}
141void MnApplication::RemoveLimits(unsigned int i)
142{
144}
145
146double MnApplication::Value(unsigned int i) const
147{
148 return fState.Value(i);
149}
150double MnApplication::Error(unsigned int i) const
151{
152 return fState.Error(i);
153}
154
155// interaction via Name of Parameter
156void MnApplication::Fix(const char *i)
157{
158 fState.Fix(i);
159}
160void MnApplication::Release(const char *i)
161{
162 fState.Release(i);
163}
164void MnApplication::SetValue(const char *i, double val)
165{
166 fState.SetValue(i, val);
167}
168void MnApplication::SetError(const char *i, double val)
169{
170 fState.SetError(i, val);
171}
172void MnApplication::SetLimits(const char *i, double low, double up)
173{
174 fState.SetLimits(i, low, up);
175}
177{
179}
181{
182 fState.SetPrecision(eps);
183}
184
185double MnApplication::Value(const char *i) const
186{
187 return fState.Value(i);
188}
189double MnApplication::Error(const char *i) const
190{
191 return fState.Error(i);
192}
193
194unsigned int MnApplication::Index(const char *name) const
195{
196 // convert name into external number of Parameter
197 return fState.Index(name);
198}
199
200const char *MnApplication::Name(unsigned int i) const
201{
202 // convert external number into name of Parameter
203 return fState.Name(i);
204}
205
206double MnApplication::Int2ext(unsigned int i, double val) const
207{
208 // transformation internal -> external
209 return fState.Int2ext(i, val);
210}
211double MnApplication::Ext2int(unsigned int e, double val) const
212{
213 // transformation external -> internal
214 return fState.Ext2int(e, val);
215}
216unsigned int MnApplication::IntOfExt(unsigned int ext) const
217{
218 // get internal index for external parameter with index ext
219 return fState.IntOfExt(ext);
220}
221unsigned 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
#define e(i)
Definition RSha256.hxx:103
char name[80]
Definition TGX11.cxx:110
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:45
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
const std::vector< MinimumState > & States() const
const MnUserParameterState & UserState() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MinimumError & Error() const
const MnAlgebraicVector & Vec() const
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
void SetError(unsigned int, double)
MnUserParameterState fState
double Int2ext(unsigned int, double) const
void Add(const char *Name, double val, double err)
std::vector< double > Errors() const
void RemoveLimits(unsigned int)
double Value(unsigned int) const
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
virtual ModularFunctionMinimizer & Minimizer()=0
unsigned int ExtOfInt(unsigned int) const
unsigned int Index(const char *) const
unsigned int IntOfExt(unsigned int) const
virtual FunctionMinimum operator()(unsigned int maxfcn=0, double tolerance=0.1)
Minimize the function.
virtual const FCNBase & Fcnbase() const
double Ext2int(unsigned int, double) const
const MinuitParameter & Parameter(unsigned int i) const
MnApplication(const FCNBase &fcn, const MnUserParameterState &state, const MnStrategy &stra, unsigned int nfcn=0)
const char * Name(unsigned int) const
std::vector< double > Params() const
void SetLimits(unsigned int, double, double)
double Error(unsigned int) const
void SetValue(unsigned int, double)
unsigned int VariableParameters() const
void Debug(const Ts &... args)
Definition MnPrint.h:147
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
Definition MnStrategy.h:27
class which holds the external user and/or internal Minuit representation of the parameters and error...
void SetLimits(unsigned int, double, double)
unsigned int Index(const std::string &) const
double Int2ext(unsigned int, double) const
const MinuitParameter & Parameter(unsigned int i) const
double Ext2int(unsigned int, double) const
void Add(const std::string &name, double val, double err)
unsigned int ExtOfInt(unsigned int) const
const char * Name(unsigned int) const
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
unsigned int IntOfExt(unsigned int) const
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 override
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...