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