Logo ROOT   6.13/01
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);}
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
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
unsigned int ExtOfInt(unsigned int) const
void Add(const std::string &name, double val, double err)
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
const MinuitParameter & Parameter(unsigned int i) const
std::vector< double > Params() const
unsigned int ExtOfInt(unsigned int) const
std::vector< double > Params() const
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
void SetLimits(unsigned int, double, double)
const MinuitParameter & Parameter(unsigned int i) const
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) ...
double Error(unsigned int) const
MnUserParameterState fState
Definition: MnApplication.h:74
double Int2ext(unsigned int, double) const
virtual const FCNBase & Fcnbase() const
Definition: MnApplication.h:67
const std::vector< ROOT::Minuit2::MinimumState > & States() const
std::vector< double > Errors() const
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:47
double Ext2int(unsigned int, double) const
void Add(const char *Name, double val, double err)
unsigned int IntOfExt(unsigned int) const
class which holds the external user and/or internal Minuit representation of the parameters and error...
double Value(unsigned int) const
std::vector< double > Errors() const
void RemoveLimits(unsigned int)
void SetLimits(unsigned int, double, double)
MnApplication(const FCNBase &fcn, const MnUserParameterState &state, const MnStrategy &stra, unsigned int nfcn=0)
constructor from non-gradient functions
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
void SetError(unsigned int, double)
const MinimumError & Error() const
Definition: MinimumState.h:62
const char * Name(unsigned int) const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
unsigned int Index(const std::string &) const
void SetValue(unsigned int, double)
const char * Name(unsigned int) const
unsigned int IntOfExt(unsigned int) const
double Ext2int(unsigned int, double) const
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
virtual FunctionMinimum operator()(unsigned int maxfcn=0, double tolerance=0.1)
Minimize the function.
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
double Int2ext(unsigned int, double) const
virtual const ModularFunctionMinimizer & Minimizer() const =0
const MnUserParameterState & UserState() const
unsigned int Index(const char *) const
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition: MnStrategy.h:27
unsigned int VariableParameters() const
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:59