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
14
15
16#ifdef DEBUG
17#include "Minuit2/MnPrint.h"
18#endif
19
20namespace ROOT {
21
22 namespace Minuit2 {
23
24
25// constructor from non-gradient functions
26MnApplication::MnApplication(const FCNBase& fcn, const MnUserParameterState& state, const MnStrategy& stra, unsigned int nfcn) :
27 fFCN(fcn), fState(state), fStrategy(stra), fNumCall(nfcn), fUseGrad(false)
28{}
29
30// constructor from functions
31MnApplication::MnApplication(const FCNGradientBase& fcn, const MnUserParameterState& state, const MnStrategy& stra, unsigned int nfcn) :
32 fFCN(fcn), fState(state), fStrategy(stra), fNumCall(nfcn), fUseGrad(true)
33{}
34
35
36FunctionMinimum MnApplication::operator()(unsigned int maxfcn, double toler) {
37 // constructor from macfcn calls and tolerance
38
39 assert(fState.IsValid());
40 unsigned int npar = VariableParameters();
41 // assert(npar > 0);
42 if(maxfcn == 0) maxfcn = 200 + 100*npar + 5*npar*npar;
43
44 const FCNBase * fcn = &(Fcnbase());
45 if (fUseGrad) {
46 // case of Gradient FCN implemented via the FCNGradientBase interface
47 const FCNGradientBase * gfcn = dynamic_cast<const FCNGradientBase *>(fcn);
48 assert (gfcn != 0);
49 // case of gradient
50 FunctionMinimum min = Minimizer().Minimize( *gfcn, fState, fStrategy, maxfcn, toler);
51 fNumCall += min.NFcn();
52 fState = min.UserState();
53 return min;
54 }
55 else {
56 // no gradient
57 FunctionMinimum min = Minimizer().Minimize( *fcn, fState, fStrategy, maxfcn, toler);
58 fNumCall += min.NFcn();
59 fState = min.UserState();
60
61#ifdef DEBUG
62// std::cout << "Initial MIGRAD state is " << MnUserParameterState( min.States()[0], min.Up(), min.Seed().Trafo() ) << std::endl;
63 std::cout << "State resulting from Migrad. Total Function calls " << fNumCall << fState << std::endl;
64 const std::vector<ROOT::Minuit2::MinimumState>& iterationStates = min.States();
65 std::cout << "Number of iterations " << iterationStates.size() << std::endl;
66 for (unsigned int i = 0; i < iterationStates.size(); ++i) {
67 //std::cout << iterationStates[i] << std::endl;
68 const ROOT::Minuit2::MinimumState & st = iterationStates[i];
69 std::cout << "----------> Iteration " << i << std::endl;
70 int pr = std::cout.precision(18);
71 std::cout << " FVAL = " << st.Fval()
72 << " Edm = " << st.Edm() << " Nfcn = " << st.NFcn() << std::endl;
73 std::cout.precision(pr);
74 std::cout << " Error matrix change = " << st.Error().Dcovar()
75 << std::endl;
76 std::cout << " Internal parameters : ";
77 for (int j = 0; j < st.size() ; ++j)
78 std::cout << " p" << j << " = " << st.Vec()(j);
79 std::cout << std::endl;
80 }
81#endif
82
83 return min;
84 }
85
86}
87
88// facade: forward interface of MnUserParameters and MnUserTransformation
89// via MnUserParameterState
90
91
92const std::vector<MinuitParameter>& MnApplication::MinuitParameters() const {
93 //access to parameters (row-wise)
94 return fState.MinuitParameters();
95}
96//access to parameters and errors in column-wise representation
97std::vector<double> MnApplication::Params() const {return fState.Params();}
98std::vector<double> MnApplication::Errors() const {return fState.Errors();}
99
100
101const MinuitParameter& MnApplication::Parameter(unsigned int i) const {
102 //access to single Parameter
103 return fState.Parameter(i);
104}
105
106
107void MnApplication::Add(const char* name, double val, double err) {
108 //add free Parameter
109 fState.Add(name, val, err);
110}
111
112void MnApplication::Add(const char* name, double val, double err, double low, double up) {
113 //add limited Parameter
114 fState.Add(name, val, err, low, up);
115}
116
117void MnApplication::Add(const char* name, double val) {
118 //add const Parameter
119 fState.Add(name, val);
120}
121
122//interaction via external number of Parameter
123void MnApplication::Fix(unsigned int i) {fState.Fix(i);}
124void MnApplication::Release(unsigned int i) {fState.Release(i);}
125void MnApplication::SetValue(unsigned int i, double val) {
126 // set value for parameter i
127 fState.SetValue(i, val);
128}
129void MnApplication::SetError(unsigned int i, double val) {
130 // set parameter error
131 fState.SetError(i, val);
132}
133void MnApplication::SetLimits(unsigned int i, double low, double up) {
134 // set parameter limits
135 fState.SetLimits(i, low, up);
136}
138
139double MnApplication::Value(unsigned int i) const {return fState.Value(i);}
140double MnApplication::Error(unsigned int i) const {return fState.Error(i);}
141
142//interaction via Name of Parameter
143void MnApplication::Fix(const char* i) {fState.Fix(i);}
144void MnApplication::Release(const char* i) {fState.Release(i);}
145void MnApplication::SetValue(const char* i, double val) {fState.SetValue(i, val);}
146void MnApplication::SetError(const char* i, double val) {fState.SetError(i, val);}
147void MnApplication::SetLimits(const char* i, double low, double up) { fState.SetLimits(i, low, up);}
150
151double MnApplication::Value(const char* i) const {return fState.Value(i);}
152double MnApplication::Error(const char* i) const {return fState.Error(i);}
153
154
155unsigned int MnApplication::Index(const char* name) const {
156 //convert name into external number of Parameter
157 return fState.Index(name);
158}
159
160const char* MnApplication::Name(unsigned int i) const {
161 //convert external number into name of Parameter
162 return fState.Name(i);
163}
164
165
166double MnApplication::Int2ext(unsigned int i, double val) const {
167 // transformation internal -> external
168 return fState.Int2ext(i, val);
169}
170double MnApplication::Ext2int(unsigned int e, double val) const {
171 // transformation external -> internal
172 return fState.Ext2int(e, val);
173}
174unsigned int MnApplication::IntOfExt(unsigned int ext) const {
175 // get internal index for external parameter with index ext
176 return fState.IntOfExt(ext);
177}
178unsigned int MnApplication::ExtOfInt(unsigned int internal) const {
179 // get external index for internal parameter with index internal
180 return fState.ExtOfInt(internal);
181}
183 // get number of variable parameters
184 return fState.VariableParameters();
185}
186
187
188 } // namespace Minuit2
189
190} // namespace ROOT
#define e(i)
Definition: RSha256.hxx:103
char name[80]
Definition: TGX11.cxx:109
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:47
Extension of the FCNBase for providing the analytical Gradient of the function.
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
const std::vector< ROOT::Minuit2::MinimumState > & States() const
const MnUserParameterState & UserState() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
const MinimumError & Error() const
Definition: MinimumState.h:62
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:59
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
void SetError(unsigned int, double)
MnUserParameterState fState
Definition: MnApplication.h:75
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
Definition: MnApplication.h:68
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)
constructor from non-gradient functions
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
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
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
std::vector< double > Errors() const
std::vector< double > Params() const
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
VSD Structures.
Definition: StringConv.hxx:21