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