Logo ROOT   6.08/07
Reference Guide
Minuit2Minimizer.cxx
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Author: L. Moneta Wed Oct 18 11:48:00 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Implementation file for class Minuit2Minimizer
12 
14 
15 #include "Math/IFunction.h"
16 #include "Math/IOptions.h"
17 
18 #include "Fit/ParameterSettings.h"
19 
20 #include "Minuit2/FCNAdapter.h"
22 #include "Minuit2/FCNGradAdapter.h"
24 #include "Minuit2/MnMigrad.h"
25 #include "Minuit2/MnMinos.h"
26 #include "Minuit2/MinosError.h"
27 #include "Minuit2/MnHesse.h"
29 #include "Minuit2/MnUserFcn.h"
30 #include "Minuit2/MnPrint.h"
35 #include "Minuit2/ScanMinimizer.h"
38 #include "Minuit2/MnContours.h"
39 #include "Minuit2/MnTraceObject.h"
40 #include "Minuit2/MinimumBuilder.h"
41 
42 #include <cassert>
43 #include <iostream>
44 #include <algorithm>
45 #include <functional>
46 
47 #ifdef USE_ROOT_ERROR
48 #include "TROOT.h"
49 #include "TMinuit2TraceObject.h"
50 #endif
51 
52 namespace ROOT {
53 
54 namespace Minuit2 {
55 
56 
57  // functions needed to control siwthc off of Minuit2 printing level
58 #ifdef USE_ROOT_ERROR
59  int TurnOffPrintInfoLevel() {
60  // switch off Minuit2 printing of INFO message (cut off is 1001)
61  int prevErrorIgnoreLevel = gErrorIgnoreLevel;
62  if (prevErrorIgnoreLevel < 1001) {
63  gErrorIgnoreLevel = 1001;
64  return prevErrorIgnoreLevel;
65  }
66  return -2; // no op in this case
67 }
68 
69 void RestoreGlobalPrintLevel(int value) {
70  gErrorIgnoreLevel = value;
71 }
72 #else
73  // dummy functions
74  int TurnOffPrintInfoLevel() { return -1; }
75  int ControlPrintLevel( ) { return -1;}
77 #endif
78 
79 
80 
81 
83  Minimizer(),
84  fDim(0),
85  fMinimizer(0),
86  fMinuitFCN(0),
87  fMinimum(0)
88 {
89  // Default constructor implementation depending on minimizer type
90  SetMinimizerType(type);
91 }
92 
94  Minimizer(),
95  fDim(0),
96  fMinimizer(0),
97  fMinuitFCN(0),
98  fMinimum(0)
99 {
100  // constructor from a string
101 
102  std::string algoname(type);
103  // tolower() is not an std function (Windows)
104  std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) tolower );
105 
106  EMinimizerType algoType = kMigrad;
107  if (algoname == "simplex") algoType = kSimplex;
108  if (algoname == "minimize" ) algoType = kCombined;
109  if (algoname == "scan" ) algoType = kScan;
110  if (algoname == "fumili" ) algoType = kFumili;
111 
112  SetMinimizerType(algoType);
113 }
114 
116  // Set minimizer algorithm type
117  fUseFumili = false;
118  switch (type) {
120  //std::cout << "Minuit2Minimizer: minimize using MIGRAD " << std::endl;
122  return;
124  //std::cout << "Minuit2Minimizer: minimize using SIMPLEX " << std::endl;
126  return;
129  return;
132  return;
135  fUseFumili = true;
136  return;
137  default:
138  //migrad minimizer
140 
141  }
142 }
143 
144 
146 {
147  // Destructor implementation.
148  if (fMinimizer) delete fMinimizer;
149  if (fMinuitFCN) delete fMinuitFCN;
150  if (fMinimum) delete fMinimum;
151 }
152 
154  ROOT::Math::Minimizer()
155 {
156  // Implementation of copy constructor.
157 }
158 
160 {
161  // Implementation of assignment operator.
162  if (this == &rhs) return *this; // time saving self-test
163  return *this;
164 }
165 
166 
168  // delete the state in case of consecutive minimizations
170  // clear also the function minimum
171  if (fMinimum) delete fMinimum;
172  fMinimum = 0;
173 }
174 
175 
176 // set variables
177 
178 bool Minuit2Minimizer::SetVariable(unsigned int ivar, const std::string & name, double val, double step) {
179  // set a free variable.
180  // Add the variable if not existing otherwise set value if exists already
181  // this is implemented in MnUserParameterState::Add
182  // if index is wrong (i.e. variable already exists but with a different index return false) but
183  // value is set for corresponding variable name
184 
185 // std::cout << " add parameter " << name << " " << val << " step " << step << std::endl;
186 
187  if (step <= 0) {
188  std::string txtmsg = "Parameter " + name + " has zero or invalid step size - consider it as constant ";
189  MN_INFO_MSG2("Minuit2Minimizer::SetVariable",txtmsg);
190  fState.Add(name.c_str(), val);
191  }
192  else
193  fState.Add(name.c_str(), val, step);
194 
195  unsigned int minuit2Index = fState.Index(name.c_str() );
196  if ( minuit2Index != ivar) {
197  std::string txtmsg("Wrong index used for the variable " + name);
198  MN_INFO_MSG2("Minuit2Minimizer::SetVariable",txtmsg);
199  MN_INFO_VAL2("Minuit2Minimizer::SetVariable",minuit2Index);
200  ivar = minuit2Index;
201  return false;
202  }
203  fState.RemoveLimits(ivar);
204 
205  return true;
206 }
207 
208 bool Minuit2Minimizer::SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) {
209  // add a lower bounded variable
210  if (!SetVariable(ivar, name, val, step) ) return false;
211  fState.SetLowerLimit(ivar, lower);
212  return true;
213 }
214 
215 bool Minuit2Minimizer::SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) {
216  // add a upper bounded variable
217  if (!SetVariable(ivar, name, val, step) ) return false;
218  fState.SetUpperLimit(ivar, upper);
219  return true;
220 }
221 
222 
223 
224 bool Minuit2Minimizer::SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower , double upper) {
225  // add a double bound variable
226  if (!SetVariable(ivar, name, val, step) ) return false;
227  fState.SetLimits(ivar, lower, upper);
228  return true;
229 }
230 
231 bool Minuit2Minimizer::SetFixedVariable(unsigned int ivar , const std::string & name , double val ) {
232  // add a fixed variable
233  // need a step size otherwise treated as a constant
234  // use 10%
235  double step = ( val != 0) ? 0.1 * std::abs(val) : 0.1;
236  if (!SetVariable(ivar, name, val, step ) ) {
237  ivar = fState.Index(name.c_str() );
238  }
239  fState.Fix(ivar);
240  return true;
241 }
242 
243 std::string Minuit2Minimizer::VariableName(unsigned int ivar) const {
244  // return the variable name
245  if (ivar >= fState.MinuitParameters().size() ) return std::string();
246  return fState.GetName(ivar);
247 }
248 
249 
250 int Minuit2Minimizer::VariableIndex(const std::string & name) const {
251  // return the variable index
252  // check if variable exist
253  return fState.Trafo().FindIndex(name);
254 }
255 
256 
257 bool Minuit2Minimizer::SetVariableValue(unsigned int ivar, double val) {
258  // set value for variable ivar (only for existing parameters)
259  if (ivar >= fState.MinuitParameters().size() ) return false;
260  fState.SetValue(ivar, val);
261  return true;
262 }
263 
265  // set value for variable ivar (only for existing parameters)
266  unsigned int n = fState.MinuitParameters().size();
267  if (n== 0) return false;
268  for (unsigned int ivar = 0; ivar < n; ++ivar)
269  fState.SetValue(ivar, x[ivar]);
270  return true;
271 }
272 
273 bool Minuit2Minimizer::SetVariableStepSize(unsigned int ivar, double step) {
274  // set the step-size of an existing variable
275  // parameter must exist or return false
276  if (ivar >= fState.MinuitParameters().size() ) return false;
277  fState.SetError(ivar, step);
278  return true;
279 }
280 
281 bool Minuit2Minimizer::SetVariableLowerLimit(unsigned int ivar, double lower) {
282  // set the limits of an existing variable
283  // parameter must exist or return false
284  if (ivar >= fState.MinuitParameters().size() ) return false;
285  fState.SetLowerLimit(ivar, lower);
286  return true;
287 }
288 bool Minuit2Minimizer::SetVariableUpperLimit(unsigned int ivar, double upper ) {
289  // set the limits of an existing variable
290  // parameter must exist or return false
291  if (ivar >= fState.MinuitParameters().size() ) return false;
292  fState.SetUpperLimit(ivar, upper);
293  return true;
294 }
295 
296 bool Minuit2Minimizer::SetVariableLimits(unsigned int ivar, double lower, double upper) {
297  // set the limits of an existing variable
298  // parameter must exist or return false
299  if (ivar >= fState.MinuitParameters().size() ) return false;
300  fState.SetLimits(ivar, lower,upper);
301  return true;
302 }
303 
304 bool Minuit2Minimizer::FixVariable(unsigned int ivar) {
305  // Fix an existing variable
306  if (ivar >= fState.MinuitParameters().size() ) return false;
307  fState.Fix(ivar);
308  return true;
309 }
310 
311 bool Minuit2Minimizer::ReleaseVariable(unsigned int ivar) {
312  // Release an existing variable
313  if (ivar >= fState.MinuitParameters().size() ) return false;
314  fState.Release(ivar);
315  return true;
316 }
317 
318 bool Minuit2Minimizer::IsFixedVariable(unsigned int ivar) const {
319  // query if variable is fixed
320  if (ivar >= fState.MinuitParameters().size() ) {
321  MN_ERROR_MSG2("Minuit2Minimizer","wrong variable index");
322  return false;
323  }
324  return (fState.Parameter(ivar).IsFixed() || fState.Parameter(ivar).IsConst() );
325 }
326 
328  // retrieve variable settings (all set info on the variable)
329  if (ivar >= fState.MinuitParameters().size() ) {
330  MN_ERROR_MSG2("Minuit2Minimizer","wrong variable index");
331  return false;
332  }
333  const MinuitParameter & par = fState.Parameter(ivar);
334  varObj.Set( par.Name(), par.Value(), par.Error() );
335  if (par.HasLowerLimit() ) varObj.SetLowerLimit(par.LowerLimit() );
336  else if (par.HasUpperLimit() ) varObj.SetUpperLimit(par.UpperLimit() );
337  else if (par.HasLimits() ) varObj.SetLimits(par.LowerLimit(), par.UpperLimit() );
338  if (par.IsConst() || par.IsFixed() ) varObj.Fix();
339  return true;
340 }
341 
342 
343 
345  // set function to be minimized
346  if (fMinuitFCN) delete fMinuitFCN;
347  fDim = func.NDim();
348  if (!fUseFumili) {
350  }
351  else {
352  // for Fumili the fit method function interface is required
353  const ROOT::Math::FitMethodFunction * fcnfunc = dynamic_cast<const ROOT::Math::FitMethodFunction *>(&func);
354  if (!fcnfunc) {
355  MN_ERROR_MSG("Minuit2Minimizer: Wrong Fit method function for Fumili");
356  return;
357  }
359  }
360 }
361 
363  // set function to be minimized
364  fDim = func.NDim();
365  if (fMinuitFCN) delete fMinuitFCN;
366  if (!fUseFumili) {
368  }
369  else {
370  // for Fumili the fit method function interface is required
371  const ROOT::Math::FitMethodGradFunction * fcnfunc = dynamic_cast<const ROOT::Math::FitMethodGradFunction*>(&func);
372  if (!fcnfunc) {
373  MN_ERROR_MSG("Minuit2Minimizer: Wrong Fit method function for Fumili");
374  return;
375  }
377  }
378 }
379 
381  // perform the minimization
382  // store a copy of FunctionMinimum
383  if (!fMinuitFCN) {
384  MN_ERROR_MSG2("Minuit2Minimizer::Minimize","FCN function has not been set");
385  return false;
386  }
387 
388  assert(GetMinimizer() != 0 );
389 
390  // delete result of previous minimization
391  if (fMinimum) delete fMinimum;
392  fMinimum = 0;
393 
394 
395  int maxfcn = MaxFunctionCalls();
396  double tol = Tolerance();
397  int strategyLevel = Strategy();
399 
400  int printLevel = PrintLevel();
401  if (printLevel >=1) {
402  // print the real number of maxfcn used (defined in ModularFuncitonMinimizer)
403  int maxfcn_used = maxfcn;
404  if (maxfcn_used == 0) {
405  int nvar = fState.VariableParameters();
406  maxfcn_used = 200 + 100*nvar + 5*nvar*nvar;
407  }
408  std::cout << "Minuit2Minimizer: Minimize with max-calls " << maxfcn_used
409  << " convergence for edm < " << tol << " strategy "
410  << strategyLevel << std::endl;
411  }
412 
413  // internal minuit messages
414  MnPrint::SetLevel(printLevel );
415  fMinimizer->Builder().SetPrintLevel(printLevel);
416 
417  // switch off Minuit2 printing
418  int prev_level = (printLevel <= 0 ) ? TurnOffPrintInfoLevel() : -2;
419 
420  // set the precision if needed
421  if (Precision() > 0) fState.SetPrecision(Precision());
422 
423  // set strategy and add extra options if needed
424  ROOT::Minuit2::MnStrategy strategy(strategyLevel);
426  if (minuit2Opt) {
427  // set extra options
428  int nGradCycles = strategy.GradientNCycles();
429  int nHessCycles = strategy.HessianNCycles();
430  int nHessGradCycles = strategy.HessianGradientNCycles();
431 
432  double gradTol = strategy.GradientTolerance();
433  double gradStepTol = strategy.GradientStepTolerance();
434  double hessStepTol = strategy.HessianStepTolerance();
435  double hessG2Tol = strategy.HessianG2Tolerance();
436 
437  minuit2Opt->GetValue("GradientNCycles",nGradCycles);
438  minuit2Opt->GetValue("HessianNCycles",nHessCycles);
439  minuit2Opt->GetValue("HessianGradientNCycles",nHessGradCycles);
440 
441  minuit2Opt->GetValue("GradientTolerance",gradTol);
442  minuit2Opt->GetValue("GradientStepTolerance",gradStepTol);
443  minuit2Opt->GetValue("HessianStepTolerance",hessStepTol);
444  minuit2Opt->GetValue("HessianG2Tolerance",hessG2Tol);
445 
446  strategy.SetGradientNCycles(nGradCycles);
447  strategy.SetHessianNCycles(nHessCycles);
448  strategy.SetHessianGradientNCycles(nHessGradCycles);
449 
450  strategy.SetGradientTolerance(gradTol);
451  strategy.SetGradientStepTolerance(gradStepTol);
452  strategy.SetHessianStepTolerance(hessStepTol);
453  strategy.SetHessianG2Tolerance(hessStepTol);
454 
455  int storageLevel = 1;
456  bool ret = minuit2Opt->GetValue("StorageLevel",storageLevel);
457  if (ret) SetStorageLevel(storageLevel);
458 
459  if (printLevel > 0) {
460  std::cout << "Minuit2Minimizer::Minuit - Changing default options" << std::endl;
461  minuit2Opt->Print();
462  }
463 
464 
465  }
466 
467  // set a minimizer tracer object (default for printlevel=10, from gROOT for printLevel=11)
468  // use some special print levels
469  MnTraceObject * traceObj = 0;
470 #ifdef USE_ROOT_ERROR
471  if (printLevel == 10 && gROOT) {
472  TObject * obj = gROOT->FindObject("Minuit2TraceObject");
473  traceObj = dynamic_cast<ROOT::Minuit2::MnTraceObject*>(obj);
474  if (traceObj) {
475  // need to remove from the list
476  gROOT->Remove(obj);
477  }
478  }
479  if (printLevel == 20 || printLevel == 30 || printLevel == 40 || (printLevel >= 20000 && printLevel < 30000) ) {
480  int parNumber = printLevel-20000;
481  if (printLevel == 20) parNumber = -1;
482  if (printLevel == 30) parNumber = -2;
483  if (printLevel == 40) parNumber = 0;
484  traceObj = new TMinuit2TraceObject(parNumber);
485  }
486 #endif
487  if (printLevel == 100 || (printLevel >= 10000 && printLevel < 20000)) {
488  int parNumber = printLevel-10000;
489  traceObj = new MnTraceObject(parNumber);
490  }
491  if (traceObj) {
492  traceObj->Init(fState);
493  SetTraceObject(*traceObj);
494  }
495 
496  const ROOT::Minuit2::FCNGradientBase * gradFCN = dynamic_cast<const ROOT::Minuit2::FCNGradientBase *>( fMinuitFCN );
497  if ( gradFCN != 0) {
498  // use gradient
499  //SetPrintLevel(3);
500  ROOT::Minuit2::FunctionMinimum min = GetMinimizer()->Minimize(*gradFCN, fState, strategy, maxfcn, tol);
502  }
503  else {
504  ROOT::Minuit2::FunctionMinimum min = GetMinimizer()->Minimize(*GetFCN(), fState, strategy, maxfcn, tol);
506  }
507 
508  // check if Hesse needs to be run
509  if (fMinimum->IsValid() && IsValidError() && fMinimum->State().Error().Dcovar() != 0 ) {
510  // run Hesse (Hesse will add results in the last state of fMinimum
511  ROOT::Minuit2::MnHesse hesse(strategy );
512  hesse( *fMinuitFCN, *fMinimum, maxfcn);
513  }
514 
515  // -2 is the highest low invalid value for gErrorIgnoreLevel
516  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
517 
519  bool ok = ExamineMinimum(*fMinimum);
520  //fMinimum = 0;
521 
522  // delete trace object if it was constructed
523  if (traceObj) { delete traceObj; }
524  return ok;
525 }
526 
528  /// study the function minimum
529 
530  // debug ( print all the states)
531  int debugLevel = PrintLevel();
532  if (debugLevel >= 3) {
533 
534  const std::vector<ROOT::Minuit2::MinimumState>& iterationStates = min.States();
535  std::cout << "Number of iterations " << iterationStates.size() << std::endl;
536  for (unsigned int i = 0; i < iterationStates.size(); ++i) {
537  //std::cout << iterationStates[i] << std::endl;
538  const ROOT::Minuit2::MinimumState & st = iterationStates[i];
539  std::cout << "----------> Iteration " << i << std::endl;
540  int pr = std::cout.precision(12);
541  std::cout << " FVAL = " << st.Fval() << " Edm = " << st.Edm() << " Nfcn = " << st.NFcn() << std::endl;
542  std::cout.precision(pr);
543  if (st.HasCovariance() )
544  std::cout << " Error matrix change = " << st.Error().Dcovar() << std::endl;
545  if (st.HasParameters() ) {
546  std::cout << " Parameters : ";
547  // need to transform from internal to external
548  for (int j = 0; j < st.size() ; ++j) std::cout << " p" << j << " = " << fState.Int2ext( j, st.Vec()(j) );
549  std::cout << std::endl;
550  }
551  }
552  }
553 
554  fStatus = 0;
555  std::string txt;
556  if (min.HasMadePosDefCovar() ) {
557  txt = "Covar was made pos def";
558  fStatus = 1;
559  }
560  if (min.HesseFailed() ) {
561  txt = "Hesse is not valid";
562  fStatus = 2;
563  }
564  if (min.IsAboveMaxEdm() ) {
565  txt = "Edm is above max";
566  fStatus = 3;
567  }
568  if (min.HasReachedCallLimit() ) {
569  txt = "Reached call limit";
570  fStatus = 4;
571  }
572 
573 
574  bool validMinimum = min.IsValid();
575  if (validMinimum) {
576  // print a warning message in case something is not ok
577  if (fStatus != 0 && debugLevel > 0) MN_INFO_MSG2("Minuit2Minimizer::Minimize",txt);
578  }
579  else {
580  // minimum is not valid when state is not valid and edm is over max or has passed call limits
581  if (fStatus == 0) {
582  // this should not happen
583  txt = "unknown failure";
584  fStatus = 5;
585  }
586  std::string msg = "Minimization did NOT converge, " + txt;
587  MN_INFO_MSG2("Minuit2Minimizer::Minimize",msg);
588  }
589 
590  if (debugLevel >= 1) PrintResults();
591  return validMinimum;
592 }
593 
594 
596  // print results of minimization
597  if (!fMinimum) return;
598  if (fMinimum->IsValid() ) {
599  // valid minimum
600  std::cout << "Minuit2Minimizer : Valid minimum - status = " << fStatus << std::endl;
601  int pr = std::cout.precision(18);
602  std::cout << "FVAL = " << fState.Fval() << std::endl;
603  std::cout << "Edm = " << fState.Edm() << std::endl;
604  std::cout.precision(pr);
605  std::cout << "Nfcn = " << fState.NFcn() << std::endl;
606  for (unsigned int i = 0; i < fState.MinuitParameters().size(); ++i) {
607  const MinuitParameter & par = fState.Parameter(i);
608  std::cout << par.Name() << "\t = " << par.Value() << "\t ";
609  if (par.IsFixed() ) std::cout << "(fixed)" << std::endl;
610  else if (par.IsConst() ) std::cout << "(const)" << std::endl;
611  else if (par.HasLimits() )
612  std::cout << "+/- " << par.Error() << "\t(limited)"<< std::endl;
613  else
614  std::cout << "+/- " << par.Error() << std::endl;
615  }
616  }
617  else {
618  std::cout << "Minuit2Minimizer : Invalid Minimum - status = " << fStatus << std::endl;
619  std::cout << "FVAL = " << fState.Fval() << std::endl;
620  std::cout << "Edm = " << fState.Edm() << std::endl;
621  std::cout << "Nfcn = " << fState.NFcn() << std::endl;
622  }
623 }
624 
625 const double * Minuit2Minimizer::X() const {
626  // return values at minimum
627  const std::vector<MinuitParameter> & paramsObj = fState.MinuitParameters();
628  if (paramsObj.size() == 0) return 0;
629  assert(fDim == paramsObj.size());
630  // be careful for multiple calls of this function. I will redo an allocation here
631  // only when size of vectors has changed (e.g. after a new minimization)
632  if (fValues.size() != fDim) fValues.resize(fDim);
633  for (unsigned int i = 0; i < fDim; ++i) {
634  fValues[i] = paramsObj[i].Value();
635  }
636 
637  return &fValues.front();
638 }
639 
640 
641 const double * Minuit2Minimizer::Errors() const {
642  // return error at minimum (set to zero for fixed and constant params)
643  const std::vector<MinuitParameter> & paramsObj = fState.MinuitParameters();
644  if (paramsObj.size() == 0) return 0;
645  assert(fDim == paramsObj.size());
646  // be careful for multiple calls of this function. I will redo an allocation here
647  // only when size of vectors has changed (e.g. after a new minimization)
648  if (fErrors.size() != fDim) fErrors.resize( fDim );
649  for (unsigned int i = 0; i < fDim; ++i) {
650  const MinuitParameter & par = paramsObj[i];
651  if (par.IsFixed() || par.IsConst() )
652  fErrors[i] = 0;
653  else
654  fErrors[i] = par.Error();
655  }
656 
657  return &fErrors.front();
658 }
659 
660 
661 double Minuit2Minimizer::CovMatrix(unsigned int i, unsigned int j) const {
662  // get value of covariance matrices (transform from external to internal indices)
663  if ( i >= fDim || i >= fDim) return 0;
664  if ( !fState.HasCovariance() ) return 0; // no info available when minimization has failed
665  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) return 0;
666  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() ) return 0;
667  unsigned int k = fState.IntOfExt(i);
668  unsigned int l = fState.IntOfExt(j);
669  return fState.Covariance()(k,l);
670 }
671 
672 bool Minuit2Minimizer::GetCovMatrix(double * cov) const {
673  // get value of covariance matrices
674  if ( !fState.HasCovariance() ) return false; // no info available when minimization has failed
675  for (unsigned int i = 0; i < fDim; ++i) {
676  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) {
677  for (unsigned int j = 0; j < fDim; ++j) { cov[i*fDim + j] = 0; }
678  }
679  else
680  {
681  unsigned int l = fState.IntOfExt(i);
682  for (unsigned int j = 0; j < fDim; ++j) {
683  // could probably speed up this loop (if needed)
684  int k = i*fDim + j;
685  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() )
686  cov[k] = 0;
687  else {
688  // need to transform from external to internal indices)
689  // for taking care of the removed fixed row/columns in the Minuit2 representation
690  unsigned int m = fState.IntOfExt(j);
691  cov[k] = fState.Covariance()(l,m);
692  }
693  }
694  }
695  }
696  return true;
697 }
698 
699 bool Minuit2Minimizer::GetHessianMatrix(double * hess) const {
700  // get value of Hessian matrix
701  // this is the second derivative matrices
702  if ( !fState.HasCovariance() ) return false; // no info available when minimization has failed
703  for (unsigned int i = 0; i < fDim; ++i) {
704  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) {
705  for (unsigned int j = 0; j < fDim; ++j) { hess[i*fDim + j] = 0; }
706  }
707  else {
708  unsigned int l = fState.IntOfExt(i);
709  for (unsigned int j = 0; j < fDim; ++j) {
710  // could probably speed up this loop (if needed)
711  int k = i*fDim + j;
712  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() )
713  hess[k] = 0;
714  else {
715  // need to transform from external to internal indices)
716  // for taking care of the removed fixed row/columns in the Minuit2 representation
717  unsigned int m = fState.IntOfExt(j);
718  hess[k] = fState.Hessian()(l,m);
719  }
720  }
721  }
722  }
723 
724  return true;
725 }
726 
727 
728 double Minuit2Minimizer::Correlation(unsigned int i, unsigned int j) const {
729  // get correlation between parameter i and j
730  if ( i >= fDim || i >= fDim) return 0;
731  if ( !fState.HasCovariance() ) return 0; // no info available when minimization has failed
732  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) return 0;
733  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() ) return 0;
734  unsigned int k = fState.IntOfExt(i);
735  unsigned int l = fState.IntOfExt(j);
736  double cij = fState.IntCovariance()(k,l);
737  double tmp = std::sqrt( std::abs ( fState.IntCovariance()(k,k) * fState.IntCovariance()(l,l) ) );
738  if (tmp > 0 ) return cij/tmp;
739  return 0;
740 }
741 
742 double Minuit2Minimizer::GlobalCC(unsigned int i) const {
743  // get global correlation coefficient for the parameter i. This is a number between zero and one which gives
744  // the correlation between the i-th parameter and that linear combination of all other parameters which
745  // is most strongly correlated with i.
746 
747  if ( i >= fDim || i >= fDim) return 0;
748  // no info available when minimization has failed or has some problems
749  if ( !fState.HasGlobalCC() ) return 0;
750  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) return 0;
751  unsigned int k = fState.IntOfExt(i);
752  return fState.GlobalCC().GlobalCC()[k];
753 }
754 
755 
756 bool Minuit2Minimizer::GetMinosError(unsigned int i, double & errLow, double & errUp, int runopt) {
757  // return the minos error for parameter i
758  // if a minimum does not exist an error is returned
759  // runopt is a flag which specifies if only lower or upper error needs to be run
760  // if runopt = 0 both, = 1 only lower, + 2 only upper errors
761  errLow = 0; errUp = 0;
762  bool runLower = runopt != 2;
763  bool runUpper = runopt != 1;
764 
765  assert( fMinuitFCN );
766 
767  // need to know if parameter is const or fixed
768  if ( fState.Parameter(i).IsConst() || fState.Parameter(i).IsFixed() ) {
769  return false;
770  }
771 
772  int debugLevel = PrintLevel();
773  // internal minuit messages
774  MnPrint::SetLevel( debugLevel );
775 
776  // to run minos I need function minimum class
777  // redo minimization from current state
778 // ROOT::Minuit2::FunctionMinimum min =
779 // GetMinimizer()->Minimize(*GetFCN(),fState, ROOT::Minuit2::MnStrategy(strategy), MaxFunctionCalls(), Tolerance());
780 // fState = min.UserState();
781  if (fMinimum == 0) {
782  MN_ERROR_MSG("Minuit2Minimizer::GetMinosErrors: failed - no function minimum existing");
783  return false;
784  }
785 
786  if (!fMinimum->IsValid() ) {
787  MN_ERROR_MSG("Minuit2Minimizer::MINOS failed due to invalid function minimum");
788  return false;
789  }
790 
792  // if error def has been changed update it in FunctionMinimum
793  if (ErrorDef() != fMinimum->Up() )
795 
796  // switch off Minuit2 printing
797  int prev_level = (PrintLevel() <= 0 ) ? TurnOffPrintInfoLevel() : -2;
798 
799  // set the precision if needed
800  if (Precision() > 0) fState.SetPrecision(Precision());
801 
802 
804 
805  // run MnCross
806  MnCross low;
807  MnCross up;
808  int maxfcn = MaxFunctionCalls();
809  double tol = Tolerance();
810 
811  const char * par_name = fState.Name(i);
812 
813  // now input tolerance for migrad calls inside Minos (MnFunctionCross)
814  // before it was fixed to 0.05
815  // cut off too small tolerance (they are not needed)
816  tol = std::max(tol, 0.01);
817 
818  if (PrintLevel() >=1) {
819  // print the real number of maxfcn used (defined in MnMinos)
820  int maxfcn_used = maxfcn;
821  if (maxfcn_used == 0) {
822  int nvar = fState.VariableParameters();
823  maxfcn_used = 2*(nvar+1)*(200 + 100*nvar + 5*nvar*nvar);
824  }
825  std::cout << "Minuit2Minimizer::GetMinosError for parameter " << i << " " << par_name
826  << " using max-calls " << maxfcn_used << ", tolerance " << tol << std::endl;
827  }
828 
829 
830  if (runLower) low = minos.Loval(i,maxfcn,tol);
831  if (runUpper) up = minos.Upval(i,maxfcn,tol);
832 
833  ROOT::Minuit2::MinosError me(i, fMinimum->UserState().Value(i),low, up);
834 
835  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
836 
837  // debug result of Minos
838  // print error message in Minos
839  // Note that the only invalid condition can happen when the (npar-1) minimization fails
840  // The error is also invalid when the maximum number of calls is reached or a new function minimum is found
841  // in case of the parameter at the limit the error is not ivalid.
842  // When the error is invalid the returned error is the Hessian error.
843 
844  if (debugLevel >= 1) {
845  if (runLower) {
846  if (!me.LowerValid() )
847  std::cout << "Minos: Invalid lower error for parameter " << par_name << std::endl;
848  if(me.AtLowerLimit())
849  std::cout << "Minos: Parameter : " << par_name << " is at Lower limit."<<std::endl;
850  if(me.AtLowerMaxFcn())
851  std::cout << "Minos: Maximum number of function calls exceeded when running for lower error" <<std::endl;
852  if(me.LowerNewMin() )
853  std::cout << "Minos: New Minimum found while running Minos for lower error" <<std::endl;
854 
855  if (debugLevel > 1) std::cout << "Minos: Lower error for parameter " << par_name << " : " << me.Lower() << std::endl;
856 
857  }
858  if (runUpper) {
859  if (!me.UpperValid() )
860  std::cout << "Minos: Invalid upper error for parameter " << par_name << std::endl;
861  if(me.AtUpperLimit())
862  std::cout << "Minos: Parameter " << par_name << " is at Upper limit."<<std::endl;
863  if(me.AtUpperMaxFcn())
864  std::cout << "Minos: Maximum number of function calls exceeded when running for upper error" <<std::endl;
865  if(me.UpperNewMin() )
866  std::cout << "Minos: New Minimum found while running Minos for upper error" <<std::endl;
867 
868  if (debugLevel > 1) std::cout << "Minos: Upper error for parameter " << par_name << " : " << me.Upper() << std::endl;
869  }
870 
871  }
872 
873  bool lowerInvalid = (runLower && !me.LowerValid() );
874  bool upperInvalid = (runUpper && !me.UpperValid() );
875  int mstatus = 0;
876  if (lowerInvalid || upperInvalid ) {
877  // set status accroding to bit
878  // bit 1: lower invalid Minos errors
879  // bit 2: uper invalid Minos error
880  // bit 3: invalid because max FCN
881  // bit 4 : invalid because a new minimum has been found
882  if (lowerInvalid) {
883  mstatus |= 1;
884  if (me.AtLowerMaxFcn() ) mstatus |= 4;
885  if (me.LowerNewMin() ) mstatus |= 8;
886  }
887  if(upperInvalid) {
888  mstatus |= 3;
889  if (me.AtUpperMaxFcn() ) mstatus |= 4;
890  if (me.UpperNewMin() ) mstatus |= 8;
891  }
892  //std::cout << "Error running Minos for parameter " << i << std::endl;
893  fStatus += 10*mstatus;
894  }
895 
896  errLow = me.Lower();
897  errUp = me.Upper();
898 
899  bool isValid = (runLower && me.LowerValid() ) || (runUpper && me.UpperValid() );
900  return isValid;
901 }
902 
903 bool Minuit2Minimizer::Scan(unsigned int ipar, unsigned int & nstep, double * x, double * y, double xmin, double xmax) {
904  // scan a parameter (variable) around the minimum value
905  // the parameters must have been set before
906  // if xmin=0 && xmax == 0 by default scan around 2 sigma of the error
907  // if the errors are also zero then scan from min and max of parameter range
908 
909  if (!fMinuitFCN) {
910  MN_ERROR_MSG2("Minuit2Minimizer::Scan"," Function must be set before using Scan");
911  return false;
912  }
913 
914  if ( ipar > fState.MinuitParameters().size() ) {
915  MN_ERROR_MSG2("Minuit2Minimizer::Scan"," Invalid number. Minimizer variables must be set before using Scan");
916  return false;
917  }
918 
919  // switch off Minuit2 printing
920  int prev_level = (PrintLevel() <= 0 ) ? TurnOffPrintInfoLevel() : -2;
921 
923 
924 
925  // set the precision if needed
926  if (Precision() > 0) fState.SetPrecision(Precision());
927 
929  double amin = scan.Fval(); // fcn value of the function before scan
930 
931  // first value is param value
932  std::vector<std::pair<double, double> > result = scan(ipar, nstep-1, xmin, xmax);
933 
934  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
935 
936  if (result.size() != nstep) {
937  MN_ERROR_MSG2("Minuit2Minimizer::Scan"," Invalid result from MnParameterScan");
938  return false;
939  }
940  // sort also the returned points in x
941  std::sort(result.begin(), result.end() );
942 
943 
944  for (unsigned int i = 0; i < nstep; ++i ) {
945  x[i] = result[i].first;
946  y[i] = result[i].second;
947  }
948 
949  // what to do if a new minimum has been found ?
950  // use that as new minimum
951  if (scan.Fval() < amin ) {
952  MN_INFO_MSG2("Minuit2Minimizer::Scan","A new minimum has been found");
953  fState.SetValue(ipar, scan.Parameters().Value(ipar) );
954 
955  }
956 
957 
958  return true;
959 }
960 
961 bool Minuit2Minimizer::Contour(unsigned int ipar, unsigned int jpar, unsigned int & npoints, double * x, double * y) {
962  // contour plot for parameter i and j
963  // need a valid FunctionMinimum otherwise exits
964  if (fMinimum == 0) {
965  MN_ERROR_MSG2("Minuit2Minimizer::Contour"," no function minimum existing. Must minimize function before");
966  return false;
967  }
968 
969  if (!fMinimum->IsValid() ) {
970  MN_ERROR_MSG2("Minuit2Minimizer::Contour","Invalid function minimum");
971  return false;
972  }
973  assert(fMinuitFCN);
974 
976  // if error def has been changed update it in FunctionMinimum
977  if (ErrorDef() != fMinimum->Up() ) {
979  }
980 
981  if ( PrintLevel() >= 1 )
982  MN_INFO_VAL2("Minuit2Minimizer::Contour - computing contours - ",ErrorDef());
983 
984  // switch off Minuit2 printing (for level of 0,1)
985  int prev_level = (PrintLevel() <= 1 ) ? TurnOffPrintInfoLevel() : -2;
986 
987  // decrease print-level to have too many messages
989 
990  // set the precision if needed
991  if (Precision() > 0) fState.SetPrecision(Precision());
992 
993  // eventually one should specify tolerance in contours
994  MnContours contour(*fMinuitFCN, *fMinimum, Strategy() );
995 
996  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
997 
998  // compute the contour
999  std::vector<std::pair<double,double> > result = contour(ipar,jpar, npoints);
1000  if (result.size() != npoints) {
1001  MN_ERROR_MSG2("Minuit2Minimizer::Contour"," Invalid result from MnContours");
1002  return false;
1003  }
1004  for (unsigned int i = 0; i < npoints; ++i ) {
1005  x[i] = result[i].first;
1006  y[i] = result[i].second;
1007  }
1008 
1009  // restore print level
1011 
1012 
1013  return true;
1014 
1015 
1016 }
1017 
1019  // find Hessian (full second derivative calculations)
1020  // the contained state will be updated with the Hessian result
1021  // in case a function minimum exists and is valid the result will be
1022  // appended in the function minimum
1023 
1024  if (!fMinuitFCN) {
1025  MN_ERROR_MSG2("Minuit2Minimizer::Hesse","FCN function has not been set");
1026  return false;
1027  }
1028 
1029  int strategy = Strategy();
1030  int maxfcn = MaxFunctionCalls();
1031 
1032  // switch off Minuit2 printing
1033  int prev_level = (PrintLevel() <= 0 ) ? TurnOffPrintInfoLevel() : -2;
1034 
1036 
1037  // set the precision if needed
1038  if (Precision() > 0) fState.SetPrecision(Precision());
1039 
1040  ROOT::Minuit2::MnHesse hesse( strategy );
1041 
1042 
1043  // case when function minimum exists
1044  if (fMinimum ) {
1045 
1046  // if (PrintLevel() >= 3) {
1047  // std::cout << "Minuit2Minimizer::Hesse - State before running Hesse " << std::endl;
1048  // std::cout << fState << std::endl;
1049  // }
1050 
1051  // run hesse and function minimum will be updated with Hesse result
1052  hesse( *fMinuitFCN, *fMinimum, maxfcn );
1053  // update user state
1054  fState = fMinimum->UserState();
1055  }
1056 
1057  else {
1058  // run Hesse on point stored in current state (independent of function minimum validity)
1059  // (x == 0)
1060  fState = hesse( *fMinuitFCN, fState, maxfcn);
1061  }
1062 
1063  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
1064 
1065  if (PrintLevel() >= 3) {
1066  std::cout << "Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1067  std::cout << fState << std::endl;
1068  }
1069 
1070  int covStatus = fState.CovarianceStatus();
1071  std::string covStatusType = "not valid";
1072  if (covStatus == 1) covStatusType = "approximate";
1073  if (covStatus == 2) covStatusType = "full but made positive defined";
1074  if (covStatus == 3) covStatusType = "accurate";
1075 
1076  if (!fState.HasCovariance() ) {
1077  // if false means error is not valid and this is due to a failure in Hesse
1078  // update minimizer error status
1079  int hstatus = 4;
1080  // information on error state can be retrieved only if fMinimum is available
1081  if (fMinimum) {
1082  if (fMinimum->Error().HesseFailed() ) hstatus = 1;
1083  if (fMinimum->Error().InvertFailed() ) hstatus = 2;
1084  else if (!(fMinimum->Error().IsPosDef()) ) hstatus = 3;
1085  }
1086  if (PrintLevel() > 0) {
1087  std::string msg = "Hesse failed - matrix is " + covStatusType;
1088  MN_INFO_MSG2("Minuit2Minimizer::Hesse",msg);
1089  MN_INFO_VAL2("MInuit2Minimizer::Hesse",hstatus);
1090  }
1091  fStatus += 100*hstatus;
1092  return false;
1093  }
1094  if (PrintLevel() > 0) {
1095  std::string msg = "Hesse is valid - matrix is " + covStatusType;
1096  MN_INFO_MSG2("Minuit2Minimizer::Hesse",msg);
1097  }
1098 
1099  return true;
1100 }
1101 
1103  // return status of covariance matrix
1104  //-1 - not available (inversion failed or Hesse failed)
1105  // 0 - available but not positive defined
1106  // 1 - covariance only approximate
1107  // 2 full matrix but forced pos def
1108  // 3 full accurate matrix
1109 
1110  if (fMinimum) {
1111  // case a function minimum is available
1112  if (fMinimum->HasAccurateCovar() ) return 3;
1113  else if (fMinimum->HasMadePosDefCovar() ) return 2;
1114  else if (fMinimum->HasValidCovariance() ) return 1;
1115  else if (fMinimum->HasCovariance() ) return 0;
1116  return -1;
1117  }
1118  else {
1119  // case fMinimum is not available - use state information
1120  return fState.CovarianceStatus();
1121  }
1122  return 0;
1123 }
1124 
1126  // set trace object
1127  if (!fMinimizer) return;
1129 }
1130 
1132  // set storage level
1133  if (!fMinimizer) return;
1135  }
1136 
1137 } // end namespace Minuit2
1138 
1139 } // end namespace ROOT
1140 
virtual bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0)
scan a parameter i around the minimum.
virtual const ROOT::Minuit2::ModularFunctionMinimizer * GetMinimizer() const
Minuit2Minimizer & operator=(const Minuit2Minimizer &rhs)
Assignment operator.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:322
#define MN_INFO_VAL2(loc, x)
Definition: MnPrint.h:130
double par[1]
Definition: unuranDistr.cxx:38
void SetHessianG2Tolerance(double toler)
Definition: MnStrategy.h:66
#define MN_ERROR_MSG(str)
Definition: MnPrint.h:113
int FindIndex(const std::string &) const
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set upper limit variable (override if minimizer supports them )
double ErrorDef() const
return the statistical scale used for calculate the error is typically 1 for Chi2 and 0...
Definition: Minimizer.h:442
float xmin
Definition: THbookFile.cxx:93
MnCross Upval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
Definition: MnMinos.cxx:205
const std::string & GetName(unsigned int) const
virtual void Init(const MnUserParameterState &state)
Definition: MnTraceObject.h:30
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
virtual void SetPrintLevel(int level)
void SetHessianNCycles(unsigned int n)
Definition: MnStrategy.h:64
double GradientTolerance() const
Definition: MnStrategy.h:43
virtual bool GetCovMatrix(double *cov) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
virtual void SetTraceObject(MnTraceObject &obj)
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:100
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
ROOT::Minuit2::FunctionMinimum * fMinimum
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double)
set upper/lower limited variable (override if minimizer supports them )
API class for Contours Error analysis (2-dim errors); minimization has to be done before and Minimum ...
Definition: MnContours.h:37
template wrapped class for adapting to FCNBase signature
Definition: FCNAdapter.h:33
double HessianStepTolerance() const
Definition: MnStrategy.h:46
#define gROOT
Definition: TROOT.h:364
unsigned int GradientNCycles() const
Definition: MnStrategy.h:41
Class implementing the required methods for a minimization using SCAN API is provided in the upper RO...
Definition: ScanMinimizer.h:30
void SetHessianGradientNCycles(unsigned int n)
Definition: MnStrategy.h:67
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
virtual double GlobalCC(unsigned int i) const
get global correlation coefficient for the variable i.
Minimizer()
Default constructor.
Definition: Minimizer.h:93
virtual bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj)
find the contour points (xi,xj) of the function for parameter i and j around the minimum The contour ...
void Add(const std::string &name, double val, double err)
virtual void SetMinimizer(ROOT::Minuit2::ModularFunctionMinimizer *m)
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
bool GetValue(const char *name, T &t) const
Definition: IOptions.h:75
int PrintLevel() const
minimizer configuration parameters
Definition: Minimizer.h:419
void SetGradientStepTolerance(double stp)
Definition: MnStrategy.h:61
const MinuitParameter & Parameter(unsigned int i) const
MnCross Loval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
Definition: MnMinos.cxx:210
void RestoreGlobalPrintLevel(int)
double sqrt(double)
void SetHessianStepTolerance(double stp)
Definition: MnStrategy.h:65
virtual const double * Errors() const
return errors at the minimum
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
template wrapped class for adapting to FCNBase signature a IGradFunction
void SetGradientTolerance(double toler)
Definition: MnStrategy.h:62
virtual bool SetVariableValue(unsigned int ivar, double val)
set variable
Double_t x[n]
Definition: legend1.C:17
double GradientStepTolerance() const
Definition: MnStrategy.h:42
void SetLimits(unsigned int, double, double)
Extension of the FCNBase for providing the analytical Gradient of the function.
ROOT::Minuit2::MnUserParameterState fState
bool IsValidError() const
return true if Minimizer has performed a detailed error validation (e.g. run Hesse for Minuit) ...
Definition: Minimizer.h:445
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
API class for calculating the numerical covariance matrix (== 2x Inverse Hessian == 2x Inverse 2nd de...
Definition: MnHesse.h:40
unsigned int HessianNCycles() const
Definition: MnStrategy.h:45
API class for Minos Error analysis (asymmetric errors); minimization has to be done before and Minimu...
Definition: MnMinos.h:34
void Fix()
fix the parameter
double HessianG2Tolerance() const
Definition: MnStrategy.h:47
const MinimumState & State() const
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
const std::vector< ROOT::Minuit2::MinimumState > & States() const
virtual void SetStorageLevel(int level)
double Tolerance() const
absolute tolerance
Definition: Minimizer.h:428
#define MN_INFO_MSG2(loc, str)
Definition: MnPrint.h:124
const MnUserTransformation & Trafo() const
void SetLowerLimit(double low)
set a single lower limit
virtual ~Minuit2Minimizer()
Destructor (no operations)
#define MN_ERROR_MSG2(loc, str)
Definition: MnPrint.h:127
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
bool minos
Definition: testMinim.cxx:33
const double tol
static ROOT::Math::IOptions * FindDefault(const char *name)
int Strategy() const
strategy
Definition: Minimizer.h:435
unsigned int IntOfExt(unsigned int) const
RooCmdArg Minimizer(const char *type, const char *alg=0)
Class holding the result of Minos (lower and upper values) for a specific parameter.
Definition: MinosError.h:25
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set lower limit variable (override if minimizer supports them )
virtual double Correlation(unsigned int i, unsigned int j) const
return correlation coefficient between variable i and j.
Instantiates the seed generator and Minimum builder for the Fumili minimization method.
void SetUpperLimit(unsigned int, double)
TMarker * m
Definition: textangle.C:8
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MnGlobalCorrelationCoeff & GlobalCC() const
double Precision() const
precision of minimizer in the evaluation of the objective function ( a value <=0 corresponds to the l...
Definition: Minimizer.h:432
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual bool SetVariableValues(const double *val)
set the values of all existing variables (array must be dimensioned to the size of the existing param...
virtual void PrintResults()
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;...
Instantiates the SeedGenerator and MinimumBuilder for Variable Metric Minimization method...
TLine * l
Definition: textangle.C:4
float xmax
Definition: THbookFile.cxx:93
virtual bool GetHessianMatrix(double *h) const
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
virtual void SetErrorDef(double)
add interface to set dynamically a new error definition Re-implement this function if needed...
Definition: FCNBase.h:114
void SetLowerLimit(unsigned int, double)
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
const std::vector< double > & GlobalCC() const
const MnUserCovariance & Covariance() 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
static int SetLevel(int level)
Definition: MnPrint.cxx:41
const MnUserParameters & Parameters() const
Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for Minuit2 minimization algo...
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Definition: Fitter.h:57
const MinimumError & Error() const
Definition: MinimumState.h:62
const char * Name(unsigned int) const
int type
Definition: TGX11.cxx:120
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
Double_t y[n]
Definition: legend1.C:17
double func(double *x, double *p)
Definition: stressTF1.cxx:213
virtual void Clear()
reset for consecutive minimizations - implement if needed
const MnUserCovariance & IntCovariance() const
virtual int CovMatrixStatus() const
return the status of the covariance matrix status = -1 : not available (inversion failed or Hesse fai...
Class implementing the required methods for a minimization using Simplex.
void SetMinimizerType(ROOT::Minuit2::EMinimizerType type)
unsigned int HessianGradientNCycles() const
Definition: MnStrategy.h:48
Namespace for new Math classes and functions.
unsigned int Index(const std::string &) const
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const ROOT::Minuit2::FCNBase * GetFCN() const
unsigned int MaxFunctionCalls() const
max number of function calls
Definition: Minimizer.h:422
Minuit2Minimizer(ROOT::Minuit2::EMinimizerType type=ROOT::Minuit2::kMigrad)
Default constructor.
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:32
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
template wrapped class for adapting to FumiliFCNBase signature
ROOT::Minuit2::ModularFunctionMinimizer * fMinimizer
void SetTraceObject(MnTraceObject &obj)
set an object to trace operation for each iteration The object muust implement operator() (unsigned i...
virtual bool Minimize()
method to perform the minimization.
virtual const double * X() const
return pointer to X values at the minimum
virtual double CovMatrix(unsigned int i, unsigned int j) const
return covariance matrix elements if the variable is fixed or const the value is zero The ordering of...
void SetUpperLimit(double up)
set a single upper limit
bool ExamineMinimum(const ROOT::Minuit2::FunctionMinimum &min)
examine the minimum result
void SetStorageLevel(int level)
set storage level = 1 : store all iteration states (default) = 0 : store only first and last state to...
ROOT::Minuit2::FCNBase * fMinuitFCN
void SetLimits(double low, double up)
set a double side limit, if low == up the parameter is fixed if low > up the limits are removed ...
Scans the values of FCN as a function of one Parameter and retains the best function and Parameter va...
double result[121]
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
double Int2ext(unsigned int, double) const
const int strategy
Definition: testNdimFit.cxx:46
virtual bool Hesse()
perform a full calculation of the Hessian matrix for error calculation If a valid minimum exists the ...
const MnUserParameterState & UserState() const
virtual bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0)
get the minos error for parameter i, return false if Minos failed A minimizaiton must be performed be...
Combined minimizer: combination of Migrad and Simplex.
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition: MnStrategy.h:27
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
const MinimumError & Error() const
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return -1 if variable is not found ...
void SetGradientNCycles(unsigned int n)
Definition: MnStrategy.h:60
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
const Int_t n
Definition: legend1.C:16
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
char name[80]
Definition: TGX11.cxx:109
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
virtual const MinimumBuilder & Builder() const =0
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:59