Logo ROOT   6.21/01
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
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 
529  // copy minimum state (parameter values and errors)
531  bool ok = ExamineMinimum(*fMinimum);
532  //fMinimum = 0;
533 
534  // delete trace object if it was constructed
535  if (traceObj) { delete traceObj; }
536  return ok;
537 }
538 
540  /// study the function minimum
541 
542  // debug ( print all the states)
543  int debugLevel = PrintLevel();
544  if (debugLevel >= 3) {
545 
546  const std::vector<ROOT::Minuit2::MinimumState>& iterationStates = min.States();
547  std::cout << "Number of iterations " << iterationStates.size() << std::endl;
548  for (unsigned int i = 0; i < iterationStates.size(); ++i) {
549  //std::cout << iterationStates[i] << std::endl;
550  const ROOT::Minuit2::MinimumState & st = iterationStates[i];
551  std::cout << "----------> Iteration " << i << std::endl;
552  int pr = std::cout.precision(12);
553  std::cout << " FVAL = " << st.Fval() << " Edm = " << st.Edm() << " Nfcn = " << st.NFcn() << std::endl;
554  std::cout.precision(pr);
555  if (st.HasCovariance() )
556  std::cout << " Error matrix change = " << st.Error().Dcovar() << std::endl;
557  if (st.HasParameters() ) {
558  std::cout << " Parameters : ";
559  // need to transform from internal to external
560  for (int j = 0; j < st.size() ; ++j) std::cout << " p" << j << " = " << fState.Int2ext( j, st.Vec()(j) );
561  std::cout << std::endl;
562  }
563  }
564  }
565 
566  fStatus = 0;
567  std::string txt;
568  if (!min.HasPosDefCovar() ) {
569  // this happens normally when Hesse failed
570  // it can happen in case MnSeed failed (see ROOT-9522)
571  txt = "Covar is not pos def";
572  fStatus = 5;
573  }
574  if (min.HasMadePosDefCovar() ) {
575  txt = "Covar was made pos def";
576  fStatus = 1;
577  }
578  if (min.HesseFailed() ) {
579  txt = "Hesse is not valid";
580  fStatus = 2;
581  }
582  if (min.IsAboveMaxEdm() ) {
583  txt = "Edm is above max";
584  fStatus = 3;
585  }
586  if (min.HasReachedCallLimit() ) {
587  txt = "Reached call limit";
588  fStatus = 4;
589  }
590 
591 
592  bool validMinimum = min.IsValid();
593  if (validMinimum) {
594  // print a warning message in case something is not ok
595  if (fStatus != 0 && debugLevel > 0) MN_INFO_MSG2("Minuit2Minimizer::Minimize",txt);
596  }
597  else {
598  // minimum is not valid when state is not valid and edm is over max or has passed call limits
599  if (fStatus == 0) {
600  // this should not happen
601  txt = "unknown failure";
602  fStatus = 6;
603  }
604  std::string msg = "Minimization did NOT converge, " + txt;
605  MN_INFO_MSG2("Minuit2Minimizer::Minimize",msg);
606  }
607 
608  if (debugLevel >= 1) PrintResults();
609  return validMinimum;
610 }
611 
612 
614  // print results of minimization
615  if (!fMinimum) return;
616  if (fMinimum->IsValid() ) {
617  // valid minimum
618  std::cout << "Minuit2Minimizer : Valid minimum - status = " << fStatus << std::endl;
619  int pr = std::cout.precision(18);
620  std::cout << "FVAL = " << fState.Fval() << std::endl;
621  std::cout << "Edm = " << fState.Edm() << std::endl;
622  std::cout.precision(pr);
623  std::cout << "Nfcn = " << fState.NFcn() << std::endl;
624  for (unsigned int i = 0; i < fState.MinuitParameters().size(); ++i) {
625  const MinuitParameter & par = fState.Parameter(i);
626  std::cout << par.Name() << "\t = " << par.Value() << "\t ";
627  if (par.IsFixed() ) std::cout << "(fixed)" << std::endl;
628  else if (par.IsConst() ) std::cout << "(const)" << std::endl;
629  else if (par.HasLimits() )
630  std::cout << "+/- " << par.Error() << "\t(limited)"<< std::endl;
631  else
632  std::cout << "+/- " << par.Error() << std::endl;
633  }
634  }
635  else {
636  std::cout << "Minuit2Minimizer : Invalid Minimum - status = " << fStatus << std::endl;
637  std::cout << "FVAL = " << fState.Fval() << std::endl;
638  std::cout << "Edm = " << fState.Edm() << std::endl;
639  std::cout << "Nfcn = " << fState.NFcn() << std::endl;
640  }
641 }
642 
643 const double * Minuit2Minimizer::X() const {
644  // return values at minimum
645  const std::vector<MinuitParameter> & paramsObj = fState.MinuitParameters();
646  if (paramsObj.size() == 0) return 0;
647  assert(fDim == paramsObj.size());
648  // be careful for multiple calls of this function. I will redo an allocation here
649  // only when size of vectors has changed (e.g. after a new minimization)
650  if (fValues.size() != fDim) fValues.resize(fDim);
651  for (unsigned int i = 0; i < fDim; ++i) {
652  fValues[i] = paramsObj[i].Value();
653  }
654 
655  return &fValues.front();
656 }
657 
658 
659 const double * Minuit2Minimizer::Errors() const {
660  // return error at minimum (set to zero for fixed and constant params)
661  const std::vector<MinuitParameter> & paramsObj = fState.MinuitParameters();
662  if (paramsObj.size() == 0) return 0;
663  assert(fDim == paramsObj.size());
664  // be careful for multiple calls of this function. I will redo an allocation here
665  // only when size of vectors has changed (e.g. after a new minimization)
666  if (fErrors.size() != fDim) fErrors.resize( fDim );
667  for (unsigned int i = 0; i < fDim; ++i) {
668  const MinuitParameter & par = paramsObj[i];
669  if (par.IsFixed() || par.IsConst() )
670  fErrors[i] = 0;
671  else
672  fErrors[i] = par.Error();
673  }
674 
675  return &fErrors.front();
676 }
677 
678 
679 double Minuit2Minimizer::CovMatrix(unsigned int i, unsigned int j) const {
680  // get value of covariance matrices (transform from external to internal indices)
681  if ( i >= fDim || j >= fDim) return 0;
682  if ( !fState.HasCovariance() ) return 0; // no info available when minimization has failed
683  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) return 0;
684  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() ) return 0;
685  unsigned int k = fState.IntOfExt(i);
686  unsigned int l = fState.IntOfExt(j);
687  return fState.Covariance()(k,l);
688 }
689 
690 bool Minuit2Minimizer::GetCovMatrix(double * cov) const {
691  // get value of covariance matrices
692  if ( !fState.HasCovariance() ) return false; // no info available when minimization has failed
693  for (unsigned int i = 0; i < fDim; ++i) {
694  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) {
695  for (unsigned int j = 0; j < fDim; ++j) { cov[i*fDim + j] = 0; }
696  }
697  else
698  {
699  unsigned int l = fState.IntOfExt(i);
700  for (unsigned int j = 0; j < fDim; ++j) {
701  // could probably speed up this loop (if needed)
702  int k = i*fDim + j;
703  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() )
704  cov[k] = 0;
705  else {
706  // need to transform from external to internal indices)
707  // for taking care of the removed fixed row/columns in the Minuit2 representation
708  unsigned int m = fState.IntOfExt(j);
709  cov[k] = fState.Covariance()(l,m);
710  }
711  }
712  }
713  }
714  return true;
715 }
716 
717 bool Minuit2Minimizer::GetHessianMatrix(double * hess) const {
718  // get value of Hessian matrix
719  // this is the second derivative matrices
720  if ( !fState.HasCovariance() ) return false; // no info available when minimization has failed
721  for (unsigned int i = 0; i < fDim; ++i) {
722  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) {
723  for (unsigned int j = 0; j < fDim; ++j) { hess[i*fDim + j] = 0; }
724  }
725  else {
726  unsigned int l = fState.IntOfExt(i);
727  for (unsigned int j = 0; j < fDim; ++j) {
728  // could probably speed up this loop (if needed)
729  int k = i*fDim + j;
730  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() )
731  hess[k] = 0;
732  else {
733  // need to transform from external to internal indices)
734  // for taking care of the removed fixed row/columns in the Minuit2 representation
735  unsigned int m = fState.IntOfExt(j);
736  hess[k] = fState.Hessian()(l,m);
737  }
738  }
739  }
740  }
741 
742  return true;
743 }
744 
745 
746 double Minuit2Minimizer::Correlation(unsigned int i, unsigned int j) const {
747  // get correlation between parameter i and j
748  if ( i >= fDim || j >= fDim) return 0;
749  if ( !fState.HasCovariance() ) return 0; // no info available when minimization has failed
750  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) return 0;
751  if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst() ) return 0;
752  unsigned int k = fState.IntOfExt(i);
753  unsigned int l = fState.IntOfExt(j);
754  double cij = fState.IntCovariance()(k,l);
755  double tmp = std::sqrt( std::abs ( fState.IntCovariance()(k,k) * fState.IntCovariance()(l,l) ) );
756  if (tmp > 0 ) return cij/tmp;
757  return 0;
758 }
759 
760 double Minuit2Minimizer::GlobalCC(unsigned int i) const {
761  // get global correlation coefficient for the parameter i. This is a number between zero and one which gives
762  // the correlation between the i-th parameter and that linear combination of all other parameters which
763  // is most strongly correlated with i.
764 
765  if ( i >= fDim ) return 0;
766  // no info available when minimization has failed or has some problems
767  if ( !fState.HasGlobalCC() ) return 0;
768  if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst() ) return 0;
769  unsigned int k = fState.IntOfExt(i);
770  return fState.GlobalCC().GlobalCC()[k];
771 }
772 
773 
774 bool Minuit2Minimizer::GetMinosError(unsigned int i, double & errLow, double & errUp, int runopt) {
775  // return the minos error for parameter i
776  // if a minimum does not exist an error is returned
777  // runopt is a flag which specifies if only lower or upper error needs to be run
778  // if runopt = 0 both, = 1 only lower, + 2 only upper errors
779  errLow = 0; errUp = 0;
780  bool runLower = runopt != 2;
781  bool runUpper = runopt != 1;
782 
783  assert( fMinuitFCN );
784 
785  // need to know if parameter is const or fixed
786  if ( fState.Parameter(i).IsConst() || fState.Parameter(i).IsFixed() ) {
787  return false;
788  }
789 
790  int debugLevel = PrintLevel();
791  // internal minuit messages
792  MnPrint::SetLevel( debugLevel );
793 
794  // to run minos I need function minimum class
795  // redo minimization from current state
796 // ROOT::Minuit2::FunctionMinimum min =
797 // GetMinimizer()->Minimize(*GetFCN(),fState, ROOT::Minuit2::MnStrategy(strategy), MaxFunctionCalls(), Tolerance());
798 // fState = min.UserState();
799  if (fMinimum == 0) {
800  MN_ERROR_MSG("Minuit2Minimizer::GetMinosErrors: failed - no function minimum existing");
801  return false;
802  }
803 
804  if (!fMinimum->IsValid() ) {
805  MN_ERROR_MSG("Minuit2Minimizer::MINOS failed due to invalid function minimum");
806  return false;
807  }
808 
810  // if error def has been changed update it in FunctionMinimum
811  if (ErrorDef() != fMinimum->Up() )
813 
814  // switch off Minuit2 printing
815  int prev_level = (PrintLevel() <= 0 ) ? TurnOffPrintInfoLevel() : -2;
816 
817  // set the precision if needed
818  if (Precision() > 0) fState.SetPrecision(Precision());
819 
820 
822 
823  // run MnCross
824  MnCross low;
825  MnCross up;
826  int maxfcn = MaxFunctionCalls();
827  double tol = Tolerance();
828 
829  const char * par_name = fState.Name(i);
830 
831  // now input tolerance for migrad calls inside Minos (MnFunctionCross)
832  // before it was fixed to 0.05
833  // cut off too small tolerance (they are not needed)
834  tol = std::max(tol, 0.01);
835 
836  if (PrintLevel() >=1) {
837  // print the real number of maxfcn used (defined in MnMinos)
838  int maxfcn_used = maxfcn;
839  if (maxfcn_used == 0) {
840  int nvar = fState.VariableParameters();
841  maxfcn_used = 2*(nvar+1)*(200 + 100*nvar + 5*nvar*nvar);
842  }
843  // print an empty line above
844  std::cout << "******************************************************************************************************\n";
845  std::string txt = (runLower) ? "lower" : "upper";
846  if (runLower && runUpper) txt = "lower and upper";
847  std::cout << "Minuit2Minimizer::GetMinosError - Run MINOS " << txt << " error for parameter #" << i << " : " << par_name
848  << " using max-calls " << maxfcn_used << ", tolerance " << tol << std::endl;
849  }
850 
851 
852  if (runLower) low = minos.Loval(i,maxfcn,tol);
853  if (runUpper) up = minos.Upval(i,maxfcn,tol);
854 
855  ROOT::Minuit2::MinosError me(i, fMinimum->UserState().Value(i),low, up);
856 
857  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
858 
859  // debug result of Minos
860  // print error message in Minos
861  // Note that the only invalid condition can happen when the (npar-1) minimization fails
862  // The error is also invalid when the maximum number of calls is reached or a new function minimum is found
863  // in case of the parameter at the limit the error is not ivalid.
864  // When the error is invalid the returned error is the Hessian error.
865 
866  if (debugLevel >= 1) {
867  if (runLower) {
868  if (!me.LowerValid() )
869  std::cout << "Minos: Invalid lower error for parameter " << par_name << std::endl;
870  if(me.AtLowerLimit())
871  std::cout << "Minos: Parameter : " << par_name << " is at Lower limit."<<std::endl;
872  if(me.AtLowerMaxFcn())
873  std::cout << "Minos: Maximum number of function calls exceeded when running for lower error for parameter " << par_name << std::endl;
874  if(me.LowerNewMin() )
875  std::cout << "Minos: New Minimum found while running Minos for lower error for parameter " << par_name << std::endl;
876 
877  if (debugLevel > 1 && me.LowerValid())
878  std::cout << "Minos: Lower error for parameter " << par_name << " : " << me.Lower() << std::endl;
879  }
880  if (runUpper) {
881  if (!me.UpperValid() )
882  std::cout << "Minos: Invalid upper error for parameter " << par_name << std::endl;
883  if(me.AtUpperLimit())
884  std::cout << "Minos: Parameter " << par_name << " is at Upper limit."<<std::endl;
885  if(me.AtUpperMaxFcn())
886  std::cout << "Minos: Maximum number of function calls exceeded when running for upper error for parameter " << par_name << std::endl;
887  if(me.UpperNewMin() )
888  std::cout << "Minos: New Minimum found while running Minos for upper error for parameter " << par_name << std::endl;
889 
890  if (debugLevel > 1 && me.UpperValid())
891  std::cout << "Minos: Upper error for parameter " << par_name << " : " << me.Upper() << std::endl;
892  }
893 
894  }
895 
896  bool lowerInvalid = (runLower && !me.LowerValid() );
897  bool upperInvalid = (runUpper && !me.UpperValid() );
898  int mstatus = 0;
899  if (lowerInvalid || upperInvalid ) {
900  // set status accroding to bit
901  // bit 1: lower invalid Minos errors
902  // bit 2: uper invalid Minos error
903  // bit 3: invalid because max FCN
904  // bit 4 : invalid because a new minimum has been found
905  if (lowerInvalid) {
906  mstatus |= 1;
907  if (me.AtLowerMaxFcn() ) mstatus |= 4;
908  if (me.LowerNewMin() ) mstatus |= 8;
909  }
910  if(upperInvalid) {
911  mstatus |= 3;
912  if (me.AtUpperMaxFcn() ) mstatus |= 4;
913  if (me.UpperNewMin() ) mstatus |= 8;
914  }
915  //std::cout << "Error running Minos for parameter " << i << std::endl;
916  fStatus += 10*mstatus;
917  }
918 
919  if (runLower) errLow = me.Lower();
920  if (runUpper) errUp = me.Upper();
921 
922  // in case of new minimum update minimum state
923  int iflagNewMinimum = 0;
924  if ( ( runLower && me.LowerNewMin()) && (runUpper && me.UpperNewMin() ) ) {
925  iflagNewMinimum = 3;
926  // take state with lower function value
927  fState = (low.State().Fval() < up.State().Fval()) ? low.State() : up.State();
928  } else if ( runLower && me.LowerNewMin() ) {
929  iflagNewMinimum = 1;
930  fState = low.State();
931  } else if ( runUpper && me.UpperNewMin() ) {
932  iflagNewMinimum = 2;
933  fState = up.State();
934  }
935 
936  // run gain the Minimization
937  if (iflagNewMinimum > 0) {
938  MN_INFO_MSG2("Minuit2Minimizer::GetMinosError",
939  "Found a new minimum: run again the Minimization starting from the new point ");
940  if (debugLevel > 1) {
941  std::cout << "New minimum point found by Minos : " << std::endl;
942  std::cout << "FVAL = " << fState.Fval() << std::endl;
943  for (auto & par : fState.MinuitParameters() ) {
944  std::cout << par.Name() << "\t = " << par.Value() << std::endl;
945  }
946  }
947  // release parameter that was fixed in the returned state from Minos
948  ReleaseVariable(i);
949  bool ok = Minimize();
950  if (!ok) return false;
951  // run again Minos from new Minimum (also lower error needs to be re-computed)
952  MN_INFO_MSG2("Minuit2Minimizer::GetMinosError", "Run now again Minos from the new found Minimum");
953  GetMinosError(i, errLow, errUp, runopt);
954  }
955 
956  bool isValid = (runLower && me.LowerValid() ) || (runUpper && me.UpperValid() );
957  return isValid;
958 }
959 
960 bool Minuit2Minimizer::Scan(unsigned int ipar, unsigned int & nstep, double * x, double * y, double xmin, double xmax) {
961  // scan a parameter (variable) around the minimum value
962  // the parameters must have been set before
963  // if xmin=0 && xmax == 0 by default scan around 2 sigma of the error
964  // if the errors are also zero then scan from min and max of parameter range
965 
966  if (!fMinuitFCN) {
967  MN_ERROR_MSG2("Minuit2Minimizer::Scan"," Function must be set before using Scan");
968  return false;
969  }
970 
971  if ( ipar > fState.MinuitParameters().size() ) {
972  MN_ERROR_MSG2("Minuit2Minimizer::Scan"," Invalid number. Minimizer variables must be set before using Scan");
973  return false;
974  }
975 
976  // switch off Minuit2 printing
977  int prev_level = (PrintLevel() <= 0 ) ? TurnOffPrintInfoLevel() : -2;
978 
980 
981 
982  // set the precision if needed
983  if (Precision() > 0) fState.SetPrecision(Precision());
984 
986  double amin = scan.Fval(); // fcn value of the function before scan
987 
988  // first value is param value
989  std::vector<std::pair<double, double> > result = scan(ipar, nstep-1, xmin, xmax);
990 
991  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
992 
993  if (result.size() != nstep) {
994  MN_ERROR_MSG2("Minuit2Minimizer::Scan"," Invalid result from MnParameterScan");
995  return false;
996  }
997  // sort also the returned points in x
998  std::sort(result.begin(), result.end() );
999 
1000 
1001  for (unsigned int i = 0; i < nstep; ++i ) {
1002  x[i] = result[i].first;
1003  y[i] = result[i].second;
1004  }
1005 
1006  // what to do if a new minimum has been found ?
1007  // use that as new minimum
1008  if (scan.Fval() < amin ) {
1009  MN_INFO_MSG2("Minuit2Minimizer::Scan","A new minimum has been found");
1010  fState.SetValue(ipar, scan.Parameters().Value(ipar) );
1011 
1012  }
1013 
1014 
1015  return true;
1016 }
1017 
1018 bool Minuit2Minimizer::Contour(unsigned int ipar, unsigned int jpar, unsigned int & npoints, double * x, double * y) {
1019  // contour plot for parameter i and j
1020  // need a valid FunctionMinimum otherwise exits
1021  if (fMinimum == 0) {
1022  MN_ERROR_MSG2("Minuit2Minimizer::Contour"," no function minimum existing. Must minimize function before");
1023  return false;
1024  }
1025 
1026  if (!fMinimum->IsValid() ) {
1027  MN_ERROR_MSG2("Minuit2Minimizer::Contour","Invalid function minimum");
1028  return false;
1029  }
1030  assert(fMinuitFCN);
1031 
1033  // if error def has been changed update it in FunctionMinimum
1034  if (ErrorDef() != fMinimum->Up() ) {
1036  }
1037 
1038  if ( PrintLevel() >= 1 )
1039  MN_INFO_VAL2("Minuit2Minimizer::Contour - computing contours - ",ErrorDef());
1040 
1041  // switch off Minuit2 printing (for level of 0,1)
1042  int prev_level = (PrintLevel() <= 1 ) ? TurnOffPrintInfoLevel() : -2;
1043 
1044  // decrease print-level to have too many messages
1045  MnPrint::SetLevel( PrintLevel() -1 );
1046 
1047  // set the precision if needed
1048  if (Precision() > 0) fState.SetPrecision(Precision());
1049 
1050  // eventually one should specify tolerance in contours
1051  MnContours contour(*fMinuitFCN, *fMinimum, Strategy() );
1052 
1053  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
1054 
1055  // compute the contour
1056  std::vector<std::pair<double,double> > result = contour(ipar,jpar, npoints);
1057  if (result.size() != npoints) {
1058  MN_ERROR_MSG2("Minuit2Minimizer::Contour"," Invalid result from MnContours");
1059  return false;
1060  }
1061  for (unsigned int i = 0; i < npoints; ++i ) {
1062  x[i] = result[i].first;
1063  y[i] = result[i].second;
1064  }
1065 
1066  // restore print level
1068 
1069 
1070  return true;
1071 
1072 
1073 }
1074 
1076  // find Hessian (full second derivative calculations)
1077  // the contained state will be updated with the Hessian result
1078  // in case a function minimum exists and is valid the result will be
1079  // appended in the function minimum
1080 
1081  if (!fMinuitFCN) {
1082  MN_ERROR_MSG2("Minuit2Minimizer::Hesse","FCN function has not been set");
1083  return false;
1084  }
1085 
1086  int strategy = Strategy();
1087  int maxfcn = MaxFunctionCalls();
1088 
1089  // switch off Minuit2 printing
1090  int prev_level = (PrintLevel() <= 0 ) ? TurnOffPrintInfoLevel() : -2;
1091 
1093 
1094  // set the precision if needed
1095  if (Precision() > 0) fState.SetPrecision(Precision());
1096 
1097  ROOT::Minuit2::MnHesse hesse( strategy );
1098 
1099  if (PrintLevel() >= 1)
1100  std::cout << "Minuit2Minimizer::Hesse using max-calls " << maxfcn << std::endl;
1101 
1102  // case when function minimum exists
1103  if (fMinimum) {
1104 
1105  // if (PrintLevel() >= 3) {
1106  // std::cout << "Minuit2Minimizer::Hesse - State before running Hesse " << std::endl;
1107  // std::cout << fState << std::endl;
1108  // }
1109 
1110  // run hesse and function minimum will be updated with Hesse result
1111  hesse( *fMinuitFCN, *fMinimum, maxfcn );
1112  // update user state
1113  fState = fMinimum->UserState();
1114  }
1115 
1116  else {
1117  // run Hesse on point stored in current state (independent of function minimum validity)
1118  // (x == 0)
1119  fState = hesse( *fMinuitFCN, fState, maxfcn);
1120  }
1121 
1122  if (prev_level > -2) RestoreGlobalPrintLevel(prev_level);
1123 
1124  if (PrintLevel() >= 3) {
1125  std::cout << "Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1126  std::cout << fState << std::endl;
1127  }
1128 
1129  int covStatus = fState.CovarianceStatus();
1130  std::string covStatusType = "not valid";
1131  if (covStatus == 1) covStatusType = "approximate";
1132  if (covStatus == 2) covStatusType = "full but made positive defined";
1133  if (covStatus == 3) covStatusType = "accurate";
1134 
1135  if (!fState.HasCovariance() ) {
1136  // if false means error is not valid and this is due to a failure in Hesse
1137  // update minimizer error status
1138  int hstatus = 4;
1139  // information on error state can be retrieved only if fMinimum is available
1140  if (fMinimum) {
1141  if (fMinimum->Error().HesseFailed() ) hstatus = 1;
1142  if (fMinimum->Error().InvertFailed() ) hstatus = 2;
1143  else if (!(fMinimum->Error().IsPosDef()) ) hstatus = 3;
1144  }
1145  if (PrintLevel() > 0) {
1146  std::string msg = "Hesse failed - matrix is " + covStatusType;
1147  MN_INFO_MSG2("Minuit2Minimizer::Hesse",msg);
1148  MN_INFO_VAL2("MInuit2Minimizer::Hesse",hstatus);
1149  }
1150  fStatus += 100*hstatus;
1151  return false;
1152  }
1153  if (PrintLevel() > 0) {
1154  std::string msg = "Hesse is valid - matrix is " + covStatusType;
1155  MN_INFO_MSG2("Minuit2Minimizer::Hesse",msg);
1156  }
1157 
1158  return true;
1159 }
1160 
1162  // return status of covariance matrix
1163  //-1 - not available (inversion failed or Hesse failed)
1164  // 0 - available but not positive defined
1165  // 1 - covariance only approximate
1166  // 2 full matrix but forced pos def
1167  // 3 full accurate matrix
1168 
1169  if (fMinimum) {
1170  // case a function minimum is available
1171  if (fMinimum->HasAccurateCovar() ) return 3;
1172  else if (fMinimum->HasMadePosDefCovar() ) return 2;
1173  else if (fMinimum->HasValidCovariance() ) return 1;
1174  else if (fMinimum->HasCovariance() ) return 0;
1175  return -1;
1176  }
1177  else {
1178  // case fMinimum is not available - use state information
1179  return fState.CovarianceStatus();
1180  }
1181  return 0;
1182 }
1183 
1185  // set trace object
1186  if (!fMinimizer) return;
1188 }
1189 
1191  // set storage level
1192  if (!fMinimizer) return;
1194  }
1195 
1196 } // end namespace Minuit2
1197 
1198 } // end namespace ROOT
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
Returns the available number of logical cores.
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:415
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.
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
virtual unsigned int NDim() const=0
Retrieve the dimension of the function.
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
const MnUserParameterState & State() const
Definition: MnCross.h:62
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 must be a (or inherit from) ROOT::Minu...
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