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 
15 
16 #ifdef DEBUG
17 #include "Minuit2/MnPrint.h"
18 #endif
19 
20 namespace ROOT {
21 
22  namespace Minuit2 {
23 
24 
25 // constructor from non-gradient functions
26 MnApplication::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
31 MnApplication::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 
36 FunctionMinimum 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 
92 const 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
97 std::vector<double> MnApplication::Params() const {return fState.Params();}
98 std::vector<double> MnApplication::Errors() const {return fState.Errors();}
99 
100 
101 const MinuitParameter& MnApplication::Parameter(unsigned int i) const {
102  //access to single Parameter
103  return fState.Parameter(i);
104 }
105 
106 
107 void MnApplication::Add(const char* name, double val, double err) {
108  //add free Parameter
109  fState.Add(name, val, err);
110 }
111 
112 void 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 
117 void 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
123 void MnApplication::Fix(unsigned int i) {fState.Fix(i);}
124 void MnApplication::Release(unsigned int i) {fState.Release(i);}
125 void MnApplication::SetValue(unsigned int i, double val) {
126  // set value for parameter i
127  fState.SetValue(i, val);
128 }
129 void MnApplication::SetError(unsigned int i, double val) {
130  // set parameter error
131  fState.SetError(i, val);
132 }
133 void MnApplication::SetLimits(unsigned int i, double low, double up) {
134  // set parameter limits
135  fState.SetLimits(i, low, up);
136 }
138 
139 double MnApplication::Value(unsigned int i) const {return fState.Value(i);}
140 double MnApplication::Error(unsigned int i) const {return fState.Error(i);}
141 
142 //interaction via Name of Parameter
143 void MnApplication::Fix(const char* i) {fState.Fix(i);}
144 void MnApplication::Release(const char* i) {fState.Release(i);}
145 void MnApplication::SetValue(const char* i, double val) {fState.SetValue(i, val);}
146 void MnApplication::SetError(const char* i, double val) {fState.SetError(i, val);}
147 void MnApplication::SetLimits(const char* i, double low, double up) { fState.SetLimits(i, low, up);}
149 void MnApplication::SetPrecision(double eps) {fState.SetPrecision(eps);}
150 
151 double MnApplication::Value(const char* i) const {return fState.Value(i);}
152 double MnApplication::Error(const char* i) const {return fState.Error(i);}
153 
154 
155 unsigned int MnApplication::Index(const char* name) const {
156  //convert name into external number of Parameter
157  return fState.Index(name);
158 }
159 
160 const char* MnApplication::Name(unsigned int i) const {
161  //convert external number into name of Parameter
162  return fState.Name(i);
163 }
164 
165 
166 double MnApplication::Int2ext(unsigned int i, double val) const {
167  // transformation internal -> external
168  return fState.Int2ext(i, val);
169 }
170 double MnApplication::Ext2int(unsigned int e, double val) const {
171  // transformation external -> internal
172  return fState.Ext2int(e, val);
173 }
174 unsigned int MnApplication::IntOfExt(unsigned int ext) const {
175  // get internal index for external parameter with index ext
176  return fState.IntOfExt(ext);
177 }
178 unsigned int MnApplication::ExtOfInt(unsigned int internal) const {
179  // get external index for internal parameter with index internal
180  return fState.ExtOfInt(internal);
181 }
182 unsigned int MnApplication::VariableParameters() const {
183  // get number of variable parameters
184  return fState.VariableParameters();
185 }
186 
187 
188  } // namespace Minuit2
189 
190 } // 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:41
ROOT::Minuit2::MnApplication::Fix
void Fix(unsigned int)
Definition: MnApplication.cxx:131
ROOT::Minuit2::MinimumState::Edm
double Edm() const
Definition: MinimumState.h:73
ROOT::Minuit2::MnApplication::RemoveLimits
void RemoveLimits(unsigned int)
Definition: MnApplication.cxx:145
e
#define e(i)
Definition: RSha256.hxx:121
ROOT::Minuit2::MnApplication::SetError
void SetError(unsigned int, double)
Definition: MnApplication.cxx:137
ROOT::Minuit2::MnUserParameterState::Error
double Error(unsigned int) const
Definition: MnUserParameterState.cxx:373
ROOT::Minuit2::MnApplication::Add
void Add(const char *Name, double val, double err)
Definition: MnApplication.cxx:115
ROOT::Minuit2::MnApplication::fUseGrad
bool fUseGrad
Definition: MnApplication.h:87
ROOT::Minuit2::MinimumState
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:37
ROOT::Minuit2::MnUserParameterState::MinuitParameters
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
Definition: MnUserParameterState.cxx:193
ROOT::Minuit2::MnApplication::SetLimits
void SetLimits(unsigned int, double, double)
Definition: MnApplication.cxx:141
ROOT::Minuit2::MnUserParameterState::RemoveLimits
void RemoveLimits(unsigned int)
Definition: MnUserParameterState.cxx:360
FunctionMinimum.h
ROOT::Minuit2::FCNBase
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:55
ROOT::Minuit2::MnApplication::Ext2int
double Ext2int(unsigned int, double) const
Definition: MnApplication.cxx:178
ROOT::Minuit2::MnApplication::Error
double Error(unsigned int) const
Definition: MnApplication.cxx:148
ModularFunctionMinimizer.h
ROOT::Minuit2::MnApplication::Release
void Release(unsigned int)
Definition: MnApplication.cxx:132
ROOT::Minuit2::MnUserParameterState::SetError
void SetError(unsigned int, double)
Definition: MnUserParameterState.cxx:311
ROOT::Minuit2::MnApplication::MinuitParameters
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
Definition: MnApplication.cxx:100
ROOT::Minuit2::MnApplication::Fcnbase
virtual const FCNBase & Fcnbase() const
Definition: MnApplication.h:77
ROOT::Minuit2::MnApplication::Value
double Value(unsigned int) const
Definition: MnApplication.cxx:147
ROOT::Minuit2::MinimumState::NFcn
int NFcn() const
Definition: MinimumState.h:74
ROOT::Minuit2::MnApplication::SetPrecision
void SetPrecision(double)
Definition: MnApplication.cxx:157
ROOT::Minuit2::MnUserParameterState::VariableParameters
unsigned int VariableParameters() const
Definition: MnUserParameterState.cxx:433
ROOT::Minuit2::MnApplication::IntOfExt
unsigned int IntOfExt(unsigned int) const
Definition: MnApplication.cxx:182
ROOT::Minuit2::MnUserParameterState::SetPrecision
void SetPrecision(double eps)
Definition: MnUserParameterState.cxx:442
ROOT::Minuit2::MnUserParameterState::SetLimits
void SetLimits(unsigned int, double, double)
Definition: MnUserParameterState.cxx:316
ROOT::Minuit2::MnUserParameterState::IsValid
bool IsValid() const
Definition: MnUserParameterState.h:111
ROOT::Minuit2::FunctionMinimum::UserState
const MnUserParameterState & UserState() const
Definition: FunctionMinimum.h:86
MnApplication.h
ROOT::Minuit2::MnApplication::operator()
virtual FunctionMinimum operator()(unsigned int maxfcn=0, double tolerance=0.1)
Minimize the function.
Definition: MnApplication.cxx:44
ROOT::Minuit2::MinimumState::Error
const MinimumError & Error() const
Definition: MinimumState.h:70
ROOT::Minuit2::MnApplication::Params
std::vector< double > Params() const
Definition: MnApplication.cxx:105
ROOT::Minuit2::MnApplication::ExtOfInt
unsigned int ExtOfInt(unsigned int) const
Definition: MnApplication.cxx:186
ROOT::Minuit2::MnUserParameterState::Name
const char * Name(unsigned int) const
Definition: MnUserParameterState.cxx:406
FCNGradientBase.h
ROOT::Minuit2::MnApplication::fStrategy
MnStrategy fStrategy
Definition: MnApplication.h:85
ROOT::Minuit2::MnApplication::VariableParameters
unsigned int VariableParameters() const
Definition: MnApplication.cxx:190
ROOT::Minuit2::MnUserParameterState::SetValue
void SetValue(unsigned int, double)
Definition: MnUserParameterState.cxx:299
ROOT::Minuit2::MinimumState::Fval
double Fval() const
Definition: MinimumState.h:72
ROOT::Minuit2::MnUserParameterState::Params
std::vector< double > Params() const
Definition: MnUserParameterState.cxx:198
ROOT::Minuit2::MnUserParameterState::Errors
std::vector< double > Errors() const
Definition: MnUserParameterState.cxx:202
ROOT::Minuit2::MnApplication::Index
unsigned int Index(const char *) const
Definition: MnApplication.cxx:163
ROOT::Minuit2::MinimumError::Dcovar
double Dcovar() const
Definition: MinimumError.h:76
ROOT::Minuit2::MnApplication::Minimizer
virtual ModularFunctionMinimizer & Minimizer()=0
ROOT::Minuit2::MnApplication::SetValue
void SetValue(unsigned int, double)
Definition: MnApplication.cxx:133
ROOT::Minuit2::MnUserParameterState::ExtOfInt
unsigned int ExtOfInt(unsigned int) const
Definition: MnUserParameterState.cxx:429
ROOT::Minuit2::MinimumState::size
int size() const
Definition: MinimumState.h:68
ROOT::Minuit2::MinimumState::Vec
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:67
ROOT::Minuit2::MnUserParameterState::Add
void Add(const std::string &name, double val, double err)
Definition: MnUserParameterState.cxx:212
ROOT::Minuit2::MnApplication::fState
MnUserParameterState fState
Definition: MnApplication.h:84
ROOT::Minuit2::FunctionMinimum
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
Definition: FunctionMinimum.h:40
ROOT::Minuit2::FCNGradientBase
Extension of the FCNBase for providing the analytical Gradient of the function.
Definition: FCNGradientBase.h:42
ROOT::Minuit2::MnUserParameterState::Parameter
const MinuitParameter & Parameter(unsigned int i) const
Definition: MnUserParameterState.cxx:207
ROOT::Minuit2::MnUserParameterState::IntOfExt
unsigned int IntOfExt(unsigned int) const
Definition: MnUserParameterState.cxx:425
ROOT::Minuit2::FunctionMinimum::NFcn
int NFcn() const
Definition: FunctionMinimum.h:103
ROOT::Minuit2::MnApplication::Errors
std::vector< double > Errors() const
Definition: MnApplication.cxx:106
ROOT::Minuit2::MnUserParameterState::Index
unsigned int Index(const std::string &) const
Definition: MnUserParameterState.cxx:401
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Minuit2::MnUserParameterState::Release
void Release(unsigned int)
Definition: MnUserParameterState.cxx:285
ROOT::Minuit2::MnUserParameterState::Ext2int
double Ext2int(unsigned int, double) const
Definition: MnUserParameterState.cxx:421
ROOT::Minuit2::MnUserParameterState::Value
double Value(unsigned int) const
Definition: MnUserParameterState.cxx:369
MnPrint.h
ROOT::Minuit2::FunctionMinimum::States
const std::vector< ROOT::Minuit2::MinimumState > & States() const
Definition: FunctionMinimum.h:83
ROOT::Minuit2::MnApplication::fNumCall
unsigned int fNumCall
Definition: MnApplication.h:86
ROOT::Minuit2::MnApplication::Parameter
const MinuitParameter & Parameter(unsigned int i) const
Definition: MnApplication.cxx:109
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Minuit2::MnApplication::Int2ext
double Int2ext(unsigned int, double) const
Definition: MnApplication.cxx:174
ROOT::Minuit2::MnUserParameterState::Int2ext
double Int2ext(unsigned int, double) const
Definition: MnUserParameterState.cxx:417
ROOT::Minuit2::MnUserParameterState::Fix
void Fix(unsigned int)
Definition: MnUserParameterState.cxx:271
ROOT::Minuit2::MnApplication::Name
const char * Name(unsigned int) const
Definition: MnApplication.cxx:168
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:34
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:49