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