Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/MnPrint.h"
36#include "Minuit2/MnContours.h"
39
40#include <cassert>
41#include <iostream>
42#include <algorithm>
43#include <functional>
44
45#ifdef USE_ROOT_ERROR
46#include "TError.h"
47#include "TROOT.h"
48#include "TMinuit2TraceObject.h"
49#endif
50
51namespace ROOT {
52
53namespace Minuit2 {
54
55// functions needed to control siwthc off of Minuit2 printing level
56#ifdef USE_ROOT_ERROR
58{
59 // switch off Minuit2 printing of INFO message (cut off is 1001)
61 if (prevErrorIgnoreLevel < 1001) {
62 gErrorIgnoreLevel = 1001;
64 }
65 return -2; // no op in this case
66}
67
69{
71}
72#else
73// dummy functions
75{
76 return -1;
77}
79{
80 return -1;
81}
83#endif
84
86 : fDim(0), fMinimizer(nullptr), fMinuitFCN(nullptr), fMinimum(nullptr)
87{
88 // Default constructor implementation depending on minimizer type
90}
91
92Minuit2Minimizer::Minuit2Minimizer(const char *type) : fDim(0), fMinimizer(nullptr), fMinuitFCN(nullptr), fMinimum(nullptr)
93{
94 // constructor from a string
95
96 std::string algoname(type);
97 // tolower() is not an std function (Windows)
98 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int (*)(int))tolower);
99
101 if (algoname == "simplex")
103 if (algoname == "minimize")
105 if (algoname == "scan")
106 algoType = kScan;
107 if (algoname == "fumili" || algoname == "fumili2")
109 if (algoname == "bfgs")
111
113}
114
116{
117 // Set minimizer algorithm type
118 fUseFumili = false;
119 switch (type) {
121 // std::cout << "Minuit2Minimizer: minimize using MIGRAD " << std::endl;
123 return;
125 // std::cout << "Minuit2Minimizer: minimize using MIGRAD " << std::endl;
127 return;
129 // std::cout << "Minuit2Minimizer: minimize using SIMPLEX " << std::endl;
131 return;
136 fUseFumili = true;
137 return;
138 default:
139 // migrad minimizer
141 }
142}
143
145{
146 // Destructor implementation.
147 if (fMinimizer)
148 delete fMinimizer;
149 if (fMinuitFCN)
150 delete fMinuitFCN;
151 if (fMinimum)
152 delete fMinimum;
153}
154
156{
157 // delete the state in case of consecutive minimizations
159 // clear also the function minimum
160 if (fMinimum)
161 delete fMinimum;
162 fMinimum = nullptr;
163}
164
165// set variables
166
167bool Minuit2Minimizer::SetVariable(unsigned int ivar, const std::string &name, double val, double step)
168{
169 // set a free variable.
170 // Add the variable if not existing otherwise set value if exists already
171 // this is implemented in MnUserParameterState::Add
172 // if index is wrong (i.e. variable already exists but with a different index return false) but
173 // value is set for corresponding variable name
174
175 // std::cout << " add parameter " << name << " " << val << " step " << step << std::endl;
176 MnPrint print("Minuit2Minimizer::SetVariable", PrintLevel());
177
178 if (step <= 0) {
179 print.Info("Parameter", name, "has zero or invalid step size - consider it as constant");
180 fState.Add(name, val);
181 } else
182 fState.Add(name, val, step);
183
184 unsigned int minuit2Index = fState.Index(name);
185 if (minuit2Index != ivar) {
186 print.Warn("Wrong index", minuit2Index, "used for the variable", name);
188 return false;
189 }
191
192 return true;
193}
194
195/** set initial second derivatives
196 */
197bool Minuit2Minimizer::SetCovarianceDiag(std::span<const double> d2, unsigned int n)
198{
199 MnPrint print("Minuit2Minimizer::SetCovarianceDiag", PrintLevel());
200
201 std::vector<double> cov(n * (n + 1) / 2);
202
203 for (unsigned int i = 0; i < n; i++) {
204 for (unsigned int j = i; j < n; j++)
205 cov[i + j * (j + 1) / 2] = (i == j) ? d2[i] : 0.;
206 }
207
209}
210
211bool Minuit2Minimizer::SetCovariance(std::span<const double> cov, unsigned int nrow)
212{
213 MnPrint print("Minuit2Minimizer::SetCovariance", PrintLevel());
214
216
217 return true;
218}
219
220bool Minuit2Minimizer::SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step,
221 double lower)
222{
223 // add a lower bounded variable
224 if (!SetVariable(ivar, name, val, step))
225 return false;
227 return true;
228}
229
230bool Minuit2Minimizer::SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step,
231 double upper)
232{
233 // add a upper bounded variable
234 if (!SetVariable(ivar, name, val, step))
235 return false;
237 return true;
238}
239
240bool Minuit2Minimizer::SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step,
241 double lower, double upper)
242{
243 // add a double bound variable
244 if (!SetVariable(ivar, name, val, step))
245 return false;
247 return true;
248}
249
250bool Minuit2Minimizer::SetFixedVariable(unsigned int ivar, const std::string &name, double val)
251{
252 // add a fixed variable
253 // need a step size otherwise treated as a constant
254 // use 10%
255 double step = (val != 0) ? 0.1 * std::abs(val) : 0.1;
256 if (!SetVariable(ivar, name, val, step)) {
258 }
259 fState.Fix(ivar);
260 return true;
261}
262
263std::string Minuit2Minimizer::VariableName(unsigned int ivar) const
264{
265 // return the variable name
266 if (ivar >= fState.MinuitParameters().size())
267 return std::string();
268 return fState.GetName(ivar);
269}
270
271int Minuit2Minimizer::VariableIndex(const std::string &name) const
272{
273 // return the variable index
274 // check if variable exist
275 return fState.Trafo().FindIndex(name);
276}
277
278bool Minuit2Minimizer::SetVariableValue(unsigned int ivar, double val)
279{
280 // set value for variable ivar (only for existing parameters)
281 if (ivar >= fState.MinuitParameters().size())
282 return false;
283 fState.SetValue(ivar, val);
284 return true;
285}
286
288{
289 // set value for variable ivar (only for existing parameters)
290 unsigned int n = fState.MinuitParameters().size();
291 if (n == 0)
292 return false;
293 for (unsigned int ivar = 0; ivar < n; ++ivar)
295 return true;
296}
297
298bool Minuit2Minimizer::SetVariableStepSize(unsigned int ivar, double step)
299{
300 // set the step-size of an existing variable
301 // parameter must exist or return false
302 if (ivar >= fState.MinuitParameters().size())
303 return false;
304 fState.SetError(ivar, step);
305 return true;
306}
307
309{
310 // set the limits of an existing variable
311 // parameter must exist or return false
312 if (ivar >= fState.MinuitParameters().size())
313 return false;
315 return true;
316}
318{
319 // set the limits of an existing variable
320 // parameter must exist or return false
321 if (ivar >= fState.MinuitParameters().size())
322 return false;
324 return true;
325}
326
327bool Minuit2Minimizer::SetVariableLimits(unsigned int ivar, double lower, double upper)
328{
329 // set the limits of an existing variable
330 // parameter must exist or return false
331 if (ivar >= fState.MinuitParameters().size())
332 return false;
334 return true;
335}
336
338{
339 // Fix an existing variable
340 if (ivar >= fState.MinuitParameters().size())
341 return false;
342 fState.Fix(ivar);
343 return true;
344}
345
347{
348 // Release an existing variable
349 if (ivar >= fState.MinuitParameters().size())
350 return false;
352 return true;
353}
354
356{
357 // query if variable is fixed
358 if (ivar >= fState.MinuitParameters().size()) {
359 MnPrint print("Minuit2Minimizer", PrintLevel());
360 print.Error("Wrong variable index");
361 return false;
362 }
363 return (fState.Parameter(ivar).IsFixed() || fState.Parameter(ivar).IsConst());
364}
365
367{
368 // retrieve variable settings (all set info on the variable)
369 if (ivar >= fState.MinuitParameters().size()) {
370 MnPrint print("Minuit2Minimizer", PrintLevel());
371 print.Error("Wrong variable index");
372 return false;
373 }
374 const MinuitParameter &par = fState.Parameter(ivar);
375 varObj.Set(par.Name(), par.Value(), par.Error());
376 if (par.HasLowerLimit()) {
377 if (par.HasUpperLimit()) {
378 varObj.SetLimits(par.LowerLimit(), par.UpperLimit());
379 } else {
380 varObj.SetLowerLimit(par.LowerLimit());
381 }
382 } else if (par.HasUpperLimit()) {
383 varObj.SetUpperLimit(par.UpperLimit());
384 }
385 if (par.IsConst() || par.IsFixed())
386 varObj.Fix();
387 return true;
388}
389
391{
392 // set function to be minimized
393 if (fMinuitFCN)
394 delete fMinuitFCN;
395 fDim = func.NDim();
396 const bool hasGrad = func.HasGradient();
397 if (!fUseFumili) {
400 } else {
401 if(hasGrad) {
402 // for Fumili the fit method function interface is required
403 auto fcnfunc = dynamic_cast<const ROOT::Math::FitMethodGradFunction *>(&func);
404 if (!fcnfunc) {
405 MnPrint print("Minuit2Minimizer", PrintLevel());
406 print.Error("Wrong Fit method function for Fumili");
407 return;
408 }
410 } else {
411 // for Fumili the fit method function interface is required
412 auto fcnfunc = dynamic_cast<const ROOT::Math::FitMethodFunction *>(&func);
413 if (!fcnfunc) {
414 MnPrint print("Minuit2Minimizer", PrintLevel());
415 print.Error("Wrong Fit method function for Fumili");
416 return;
417 }
419 }
420 }
421}
422
423void Minuit2Minimizer::SetHessianFunction(std::function<bool(std::span<const double>, double *)> hfunc)
424{
425 // for Fumili not supported for the time being
426 if (fUseFumili) return;
428 if (!fcn) return;
429 fcn->SetHessianFunction(hfunc);
430}
431
432namespace {
433
435{
437 // set strategy and add extra options if needed
439 if (!minuit2Opt) {
441 }
442 if (!minuit2Opt) {
443 return st;
444 }
445 auto customize = [&minuit2Opt](const char *name, auto val) {
446 minuit2Opt->GetValue(name, val);
447 return val;
448 };
449 // set extra options
450 st.SetGradientNCycles(customize("GradientNCycles", int(st.GradientNCycles())));
451 st.SetHessianNCycles(customize("HessianNCycles", int(st.HessianNCycles())));
452 st.SetHessianGradientNCycles(customize("HessianGradientNCycles", int(st.HessianGradientNCycles())));
453
454 st.SetGradientTolerance(customize("GradientTolerance", st.GradientTolerance()));
455 st.SetGradientStepTolerance(customize("GradientStepTolerance", st.GradientStepTolerance()));
456 st.SetHessianStepTolerance(customize("HessianStepTolerance", st.HessianStepTolerance()));
457 st.SetHessianG2Tolerance(customize("HessianG2Tolerance", st.HessianG2Tolerance()));
458
459 return st;
460}
461
462} // namespace
463
465{
466 // perform the minimization
467 // store a copy of FunctionMinimum
468
469 MnPrint print("Minuit2Minimizer::Minimize", PrintLevel());
470
471 if (!fMinuitFCN) {
472 print.Error("FCN function has not been set");
473 return false;
474 }
475
476 assert(GetMinimizer() != nullptr);
477
478 // delete result of previous minimization
479 if (fMinimum)
480 delete fMinimum;
481 fMinimum = nullptr;
482
483 const int maxfcn = MaxFunctionCalls();
484 const double tol = Tolerance();
485 const int strategyLevel = Strategy();
487
488 const int printLevel = PrintLevel();
489 if (PrintLevel() >= 1) {
490 // print the real number of maxfcn used (defined in ModularFunctionMinimizer)
491 int maxfcn_used = maxfcn;
492 if (maxfcn_used == 0) {
493 int nvar = fState.VariableParameters();
494 maxfcn_used = 200 + 100 * nvar + 5 * nvar * nvar;
495 }
496 std::cout << "Minuit2Minimizer: Minimize with max-calls " << maxfcn_used << " convergence for edm < " << tol
497 << " strategy " << strategyLevel << std::endl;
498 }
499
500 // internal minuit messages
501 fMinimizer->Builder().SetPrintLevel(printLevel);
502
503 // switch off Minuit2 printing
504 const int prev_level = (printLevel <= 0) ? TurnOffPrintInfoLevel() : -2;
506
507 // set the precision if needed
508 if (Precision() > 0)
510
511 // add extra options if needed
513 if (!minuit2Opt) {
515 }
516 if (minuit2Opt) {
517 // set extra options
518 int storageLevel = 1;
519 bool ret = minuit2Opt->GetValue("StorageLevel", storageLevel);
520 if (ret)
522
523 if (printLevel > 0) {
524 std::cout << "Minuit2Minimizer::Minuit - Changing default options" << std::endl;
525 minuit2Opt->Print();
526 }
527 }
528
529 // set a minimizer tracer object (default for printlevel=10, from gROOT for printLevel=11)
530 // use some special print levels
531 MnTraceObject *traceObj = nullptr;
532#ifdef USE_ROOT_ERROR
533 if (printLevel == 10 && gROOT) {
534 TObject *obj = gROOT->FindObject("Minuit2TraceObject");
535 traceObj = dynamic_cast<ROOT::Minuit2::MnTraceObject *>(obj);
536 if (traceObj) {
537 // need to remove from the list
538 gROOT->Remove(obj);
539 }
540 }
541 if (printLevel == 20 || printLevel == 30 || printLevel == 40 || (printLevel >= 20000 && printLevel < 30000)) {
542 int parNumber = printLevel - 20000;
543 if (printLevel == 20)
544 parNumber = -1;
545 if (printLevel == 30)
546 parNumber = -2;
547 if (printLevel == 40)
548 parNumber = 0;
550 }
551#endif
552 if (printLevel == 100 || (printLevel >= 10000 && printLevel < 20000)) {
553 int parNumber = printLevel - 10000;
555 }
556 if (traceObj) {
557 traceObj->Init(fState);
559 }
560
562
565
566 // check if Hesse needs to be run. We do it when is requested (IsValidError() == true , set by SetParabError(true) in fitConfig)
567 // (IsValidError() means the flag to get correct error from the Minimizer is set (Minimizer::SetValidError())
568 // AND when we have a valid minimum,
569 // AND when the the current covariance matrix is estimated using the iterative approximation (Dcovar != 0 , i.e. Hesse has not computed before)
570 if (fMinimum->IsValid() && IsValidError() && fMinimum->State().Error().Dcovar() != 0) {
571 // run Hesse (Hesse will add results in the last state of fMinimum
573 hesse(*fMinuitFCN, *fMinimum, maxfcn);
574 }
575
576 // -2 is the highest low invalid value for gErrorIgnoreLevel
577 if (prev_level > -2)
580
581 // copy minimum state (parameter values and errors)
583 bool ok = ExamineMinimum(*fMinimum);
584 // fMinimum = 0;
585
586 // delete trace object if it was constructed
587 if (traceObj) {
588 delete traceObj;
589 }
590 return ok;
591}
592
594{
595 /// study the function minimum
596
597 // debug ( print all the states)
598 int debugLevel = PrintLevel();
599 if (debugLevel >= 3) {
600
601 std::span<const ROOT::Minuit2::MinimumState> iterationStates = min.States();
602 std::cout << "Number of iterations " << iterationStates.size() << std::endl;
603 for (unsigned int i = 0; i < iterationStates.size(); ++i) {
604 // std::cout << iterationStates[i] << std::endl;
606 std::cout << "----------> Iteration " << i << std::endl;
607 int pr = std::cout.precision(12);
608 std::cout << " FVAL = " << st.Fval() << " Edm = " << st.Edm() << " Nfcn = " << st.NFcn()
609 << std::endl;
610 std::cout.precision(pr);
611 if (st.HasCovariance())
612 std::cout << " Error matrix change = " << st.Error().Dcovar() << std::endl;
613 if (st.HasParameters()) {
614 std::cout << " Parameters : ";
615 // need to transform from internal to external
616 for (int j = 0; j < st.size(); ++j)
617 std::cout << " p" << j << " = " << fState.Int2ext(j, st.Vec()(j));
618 std::cout << std::endl;
619 }
620 }
621 }
622
623 fStatus = 0;
624 std::string txt;
625 if (!min.HasPosDefCovar()) {
626 // this happens normally when Hesse failed
627 // it can happen in case MnSeed failed (see ROOT-9522)
628 txt = "Covar is not pos def";
629 fStatus = 5;
630 }
631 if (min.HasMadePosDefCovar()) {
632 txt = "Covar was made pos def";
633 fStatus = 1;
634 }
635 if (min.HesseFailed()) {
636 txt = "Hesse is not valid";
637 fStatus = 2;
638 }
639 if (min.IsAboveMaxEdm()) {
640 txt = "Edm is above max";
641 fStatus = 3;
642 }
643 if (min.HasReachedCallLimit()) {
644 txt = "Reached call limit";
645 fStatus = 4;
646 }
647
648 MnPrint print("Minuit2Minimizer::Minimize", debugLevel);
649 bool validMinimum = min.IsValid();
650 if (validMinimum) {
651 // print a warning message in case something is not ok
652 // this for example is case when Covar was made posdef and fStatus=3
653 if (fStatus != 0 && debugLevel > 0)
654 print.Warn(txt);
655 } else {
656 // minimum is not valid when state is not valid and edm is over max or has passed call limits
657 if (fStatus == 0) {
658 // this should not happen
659 txt = "unknown failure";
660 fStatus = 6;
661 }
662 print.Warn("Minimization did NOT converge,", txt);
663 }
664
665 if (debugLevel >= 1)
666 PrintResults();
667
668 // set the minimum values in the fValues vector
669 std::span<const MinuitParameter> paramsObj = fState.MinuitParameters();
670 if (paramsObj.empty())
671 return false;
672 assert(fDim == paramsObj.size());
673 // re-size vector if it has changed after a new minimization
674 if (fValues.size() != fDim)
675 fValues.resize(fDim);
676 for (unsigned int i = 0; i < fDim; ++i) {
677 fValues[i] = paramsObj[i].Value();
678 }
679
680 return validMinimum;
681}
682
684{
685 // print results of minimization
686 if (!fMinimum)
687 return;
688 if (fMinimum->IsValid()) {
689 // valid minimum
690 std::cout << "Minuit2Minimizer : Valid minimum - status = " << fStatus << std::endl;
691 int pr = std::cout.precision(18);
692 std::cout << "FVAL = " << fState.Fval() << std::endl;
693 std::cout << "Edm = " << fState.Edm() << std::endl;
694 std::cout.precision(pr);
695 std::cout << "Nfcn = " << fState.NFcn() << std::endl;
696 for (unsigned int i = 0; i < fState.MinuitParameters().size(); ++i) {
697 const MinuitParameter &par = fState.Parameter(i);
698 std::cout << par.Name() << "\t = " << par.Value() << "\t ";
699 if (par.IsFixed())
700 std::cout << "(fixed)" << std::endl;
701 else if (par.IsConst())
702 std::cout << "(const)" << std::endl;
703 else if (par.HasLimits())
704 std::cout << "+/- " << par.Error() << "\t(limited)" << std::endl;
705 else
706 std::cout << "+/- " << par.Error() << std::endl;
707 }
708 } else {
709 std::cout << "Minuit2Minimizer : Invalid minimum - status = " << fStatus << std::endl;
710 std::cout << "FVAL = " << fState.Fval() << std::endl;
711 std::cout << "Edm = " << fState.Edm() << std::endl;
712 std::cout << "Nfcn = " << fState.NFcn() << std::endl;
713 }
714}
715
716const double *Minuit2Minimizer::Errors() const
717{
718 // return error at minimum (set to zero for fixed and constant params)
719 std::span<const MinuitParameter> paramsObj = fState.MinuitParameters();
720 if (paramsObj.empty())
721 return nullptr;
722 assert(fDim == paramsObj.size());
723 // be careful for multiple calls of this function. I will redo an allocation here
724 // only when size of vectors has changed (e.g. after a new minimization)
725 if (fErrors.size() != fDim)
726 fErrors.resize(fDim);
727 for (unsigned int i = 0; i < fDim; ++i) {
728 const MinuitParameter &par = paramsObj[i];
729 if (par.IsFixed() || par.IsConst())
730 fErrors[i] = 0;
731 else
732 fErrors[i] = par.Error();
733 }
734
735 return &fErrors.front();
736}
737
738double Minuit2Minimizer::CovMatrix(unsigned int i, unsigned int j) const
739{
740 // get value of covariance matrices (transform from external to internal indices)
741 if (i >= fDim || j >= fDim)
742 return 0;
743 if (!fState.HasCovariance())
744 return 0; // no info available when minimization has failed
745 if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst())
746 return 0;
747 if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst())
748 return 0;
749 unsigned int k = fState.IntOfExt(i);
750 unsigned int l = fState.IntOfExt(j);
751 return fState.Covariance()(k, l);
752}
753
755{
756 // get value of covariance matrices
757 if (!fState.HasCovariance())
758 return false; // no info available when minimization has failed
759 for (unsigned int i = 0; i < fDim; ++i) {
760 if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst()) {
761 for (unsigned int j = 0; j < fDim; ++j) {
762 cov[i * fDim + j] = 0;
763 }
764 } else {
765 unsigned int l = fState.IntOfExt(i);
766 for (unsigned int j = 0; j < fDim; ++j) {
767 // could probably speed up this loop (if needed)
768 int k = i * fDim + j;
769 if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst())
770 cov[k] = 0;
771 else {
772 // need to transform from external to internal indices)
773 // for taking care of the removed fixed row/columns in the Minuit2 representation
774 unsigned int m = fState.IntOfExt(j);
775 cov[k] = fState.Covariance()(l, m);
776 }
777 }
778 }
779 }
780 return true;
781}
782
784{
785 // get value of Hessian matrix
786 // this is the second derivative matrices
787 if (!fState.HasCovariance())
788 return false; // no info available when minimization has failed
789 for (unsigned int i = 0; i < fDim; ++i) {
790 if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst()) {
791 for (unsigned int j = 0; j < fDim; ++j) {
792 hess[i * fDim + j] = 0;
793 }
794 } else {
795 unsigned int l = fState.IntOfExt(i);
796 for (unsigned int j = 0; j < fDim; ++j) {
797 // could probably speed up this loop (if needed)
798 int k = i * fDim + j;
799 if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst())
800 hess[k] = 0;
801 else {
802 // need to transform from external to internal indices)
803 // for taking care of the removed fixed row/columns in the Minuit2 representation
804 unsigned int m = fState.IntOfExt(j);
805 hess[k] = fState.Hessian()(l, m);
806 }
807 }
808 }
809 }
810
811 return true;
812}
813
814double Minuit2Minimizer::Correlation(unsigned int i, unsigned int j) const
815{
816 // get correlation between parameter i and j
817 if (i >= fDim || j >= fDim)
818 return 0;
819 if (!fState.HasCovariance())
820 return 0; // no info available when minimization has failed
821 if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst())
822 return 0;
823 if (fState.Parameter(j).IsFixed() || fState.Parameter(j).IsConst())
824 return 0;
825 unsigned int k = fState.IntOfExt(i);
826 unsigned int l = fState.IntOfExt(j);
827 double cij = fState.IntCovariance()(k, l);
828 double tmp = std::sqrt(std::abs(fState.IntCovariance()(k, k) * fState.IntCovariance()(l, l)));
829 if (tmp > 0)
830 return cij / tmp;
831 return 0;
832}
833
834double Minuit2Minimizer::GlobalCC(unsigned int i) const
835{
836 // get global correlation coefficient for the parameter i. This is a number between zero and one which gives
837 // the correlation between the i-th parameter and that linear combination of all other parameters which
838 // is most strongly correlated with i.
839
840 if (i >= fDim)
841 return 0;
842 // no info available when minimization has failed or has some problems
843 if (!fState.HasGlobalCC())
844 return 0;
845 if (fState.Parameter(i).IsFixed() || fState.Parameter(i).IsConst())
846 return 0;
847 unsigned int k = fState.IntOfExt(i);
848 return fState.GlobalCC().GlobalCC()[k];
849}
850
851bool Minuit2Minimizer::GetMinosError(unsigned int i, double &errLow, double &errUp, int runopt)
852{
853 // return the minos error for parameter i
854 // if a minimum does not exist an error is returned
855 // runopt is a flag which specifies if only lower or upper error needs to be run
856 // if runopt = 0 both, = 1 only lower, + 2 only upper errors
857 errLow = 0;
858 errUp = 0;
859
861
862 // need to know if parameter is const or fixed
863 if (fState.Parameter(i).IsConst() || fState.Parameter(i).IsFixed()) {
864 return false;
865 }
866
867 MnPrint print("Minuit2Minimizer::GetMinosError", PrintLevel());
868
869 // to run minos I need function minimum class
870 // redo minimization from current state
871 // ROOT::Minuit2::FunctionMinimum min =
872 // GetMinimizer()->Minimize(*GetFCN(),fState, ROOT::Minuit2::MnStrategy(strategy), MaxFunctionCalls(),
873 // Tolerance());
874 // fState = min.UserState();
875 if (fMinimum == nullptr) {
876 print.Error("Failed - no function minimum existing");
877 return false;
878 }
879
880 if (!fMinimum->IsValid()) {
881 print.Error("Failed - invalid function minimum");
882 return false;
883 }
884
886 // if error def has been changed update it in FunctionMinimum
887 if (ErrorDef() != fMinimum->Up())
889
891
892 // run again the Minimization in case of a new minimum
893 // bit 8 is set
894 if ((mstatus & 8) != 0) {
895 print.Info([&](std::ostream &os) {
896 os << "Found a new minimum: run again the Minimization starting from the new point";
897 os << "\nFVAL = " << fState.Fval();
898 for (auto &par : fState.MinuitParameters()) {
899 os << '\n' << par.Name() << "\t = " << par.Value();
900 }
901 });
902 // release parameter that was fixed in the returned state from Minos
904 bool ok = Minimize();
905 if (!ok)
906 return false;
907 // run again Minos from new Minimum (also lower error needs to be re-computed)
908 print.Info("Run now again Minos from the new found Minimum");
910
911 // do not reset new minimum bit to flag for other parameters
912 mstatus |= 8;
913 }
914
915 fStatus += 10 * mstatus;
917
918 bool isValid = ((mstatus & 1) == 0) && ((mstatus & 2) == 0);
919 return isValid;
920}
921
922int Minuit2Minimizer::RunMinosError(unsigned int i, double &errLow, double &errUp, int runopt)
923{
924
925 bool runLower = runopt != 2;
926 bool runUpper = runopt != 1;
927
928 const int debugLevel = PrintLevel();
929 // switch off Minuit2 printing
930 const int prev_level = (debugLevel <= 0) ? TurnOffPrintInfoLevel() : -2;
932
933 // set the precision if needed
934 if (Precision() > 0)
936
938
939 // run MnCross
940 MnCross low;
941 MnCross up;
942 int maxfcn = MaxFunctionCalls();
943 double tol = Tolerance();
944
945 const char *par_name = fState.Name(i);
946
947 // now input tolerance for migrad calls inside Minos (MnFunctionCross)
948 // before it was fixed to 0.05
949 // cut off too small tolerance (they are not needed)
950 tol = std::max(tol, 0.01);
951
952 // get the real number of maxfcn used (defined in MnMinos) to be printed
953 int maxfcn_used = maxfcn;
954 if (maxfcn_used == 0) {
955 int nvar = fState.VariableParameters();
956 maxfcn_used = 2 * (nvar + 1) * (200 + 100 * nvar + 5 * nvar * nvar);
957 }
958
959 if (runLower) {
960 if (debugLevel >= 1) {
961 std::cout << "************************************************************************************************"
962 "******\n";
963 std::cout << "Minuit2Minimizer::GetMinosError - Run MINOS LOWER error for parameter #" << i << " : "
964 << par_name << " using max-calls " << maxfcn_used << ", tolerance " << tol << std::endl;
965 }
966 low = minos.Loval(i, maxfcn, tol);
967 }
968 if (runUpper) {
969 if (debugLevel >= 1) {
970 std::cout << "************************************************************************************************"
971 "******\n";
972 std::cout << "Minuit2Minimizer::GetMinosError - Run MINOS UPPER error for parameter #" << i << " : "
973 << par_name << " using max-calls " << maxfcn_used << ", tolerance " << tol << std::endl;
974 }
975 up = minos.Upval(i, maxfcn, tol);
976 }
977
978 ROOT::Minuit2::MinosError me(i, fMinimum->UserState().Value(i), low, up);
979
980 // restore global print level
981 if (prev_level > -2)
984
985 // debug result of Minos
986 // print error message in Minos
987 // Note that the only invalid condition can happen when the (npar-1) minimization fails
988 // The error is also invalid when the maximum number of calls is reached or a new function minimum is found
989 // in case of the parameter at the limit the error is not invalid.
990 // When the error is invalid the returned error is the Hessian error.
991
992 if (debugLevel > 0) {
993 if (runLower) {
994 if (!me.LowerValid())
995 std::cout << "Minos: Invalid lower error for parameter " << par_name << std::endl;
996 if (me.AtLowerLimit())
997 std::cout << "Minos: Parameter : " << par_name << " is at Lower limit; error is " << me.Lower()
998 << std::endl;
999 if (me.AtLowerMaxFcn())
1000 std::cout << "Minos: Maximum number of function calls exceeded when running for lower error for parameter "
1001 << par_name << std::endl;
1002 if (me.LowerNewMin())
1003 std::cout << "Minos: New Minimum found while running Minos for lower error for parameter " << par_name
1004 << std::endl;
1005
1006 if (debugLevel >= 1 && me.LowerValid())
1007 std::cout << "Minos: Lower error for parameter " << par_name << " : " << me.Lower() << std::endl;
1008 }
1009 if (runUpper) {
1010 if (!me.UpperValid())
1011 std::cout << "Minos: Invalid upper error for parameter " << par_name << std::endl;
1012 if (me.AtUpperLimit())
1013 std::cout << "Minos: Parameter " << par_name << " is at Upper limit; error is " << me.Upper() << std::endl;
1014 if (me.AtUpperMaxFcn())
1015 std::cout << "Minos: Maximum number of function calls exceeded when running for upper error for parameter "
1016 << par_name << std::endl;
1017 if (me.UpperNewMin())
1018 std::cout << "Minos: New Minimum found while running Minos for upper error for parameter " << par_name
1019 << std::endl;
1020
1021 if (debugLevel >= 1 && me.UpperValid())
1022 std::cout << "Minos: Upper error for parameter " << par_name << " : " << me.Upper() << std::endl;
1023 }
1024 }
1025
1026 MnPrint print("RunMinosError", PrintLevel());
1027 bool lowerInvalid = (runLower && !me.LowerValid());
1028 bool upperInvalid = (runUpper && !me.UpperValid());
1029 // print message in case of invalid error also in printLevel0
1030 if (lowerInvalid) {
1031 print.Warn("Invalid lower error for parameter", fMinimum->UserState().Name(i));
1032 }
1033 if (upperInvalid) {
1034 print.Warn("Invalid upper error for parameter", fMinimum->UserState().Name(i));
1035 }
1036 // print also case it is lower/upper limit
1037 if (me.AtLowerLimit()) {
1038 print.Warn("Lower error for parameter", fMinimum->UserState().Name(i), "is at the Lower limit!");
1039 }
1040 if (me.AtUpperLimit()) {
1041 print.Warn("Upper error for parameter", fMinimum->UserState().Name(i), "is at the Upper limit!");
1042 }
1043
1044 int mstatus = 0;
1045 if (lowerInvalid || upperInvalid) {
1046 // set status according to bit
1047 // bit 1: lower invalid Minos errors
1048 // bit 2: upper invalid Minos error
1049 // bit 3: invalid because max FCN
1050 // bit 4 : invalid because a new minimum has been found
1051 if (lowerInvalid) {
1052 mstatus |= 1;
1053 if (me.AtLowerMaxFcn())
1054 mstatus |= 4;
1055 if (me.LowerNewMin())
1056 mstatus |= 8;
1057 }
1058 if (upperInvalid) {
1059 mstatus |= 2;
1060 if (me.AtUpperMaxFcn())
1061 mstatus |= 4;
1062 if (me.UpperNewMin())
1063 mstatus |= 8;
1064 }
1065 }
1066 // case upper/lower limit
1067 if (me.AtUpperLimit() || me.AtLowerLimit())
1068 mstatus |= 16;
1069
1070 if (runLower)
1071 errLow = me.Lower();
1072 if (runUpper)
1073 errUp = me.Upper();
1074
1075 // in case of new minimum found update also the minimum state
1076 if ((runLower && me.LowerNewMin()) && (runUpper && me.UpperNewMin())) {
1077 // take state with lower function value
1078 fState = (low.State().Fval() < up.State().Fval()) ? low.State() : up.State();
1079 } else if (runLower && me.LowerNewMin()) {
1080 fState = low.State();
1081 } else if (runUpper && me.UpperNewMin()) {
1082 fState = up.State();
1083 }
1084
1085 return mstatus;
1086}
1087
1088bool Minuit2Minimizer::Scan(unsigned int ipar, unsigned int &nstep, double *x, double *y, double xmin, double xmax)
1089{
1090 // scan a parameter (variable) around the minimum value
1091 // the parameters must have been set before
1092 // if xmin=0 && xmax == 0 by default scan around 2 sigma of the error
1093 // if the errors are also zero then scan from min and max of parameter range
1094
1095 MnPrint print("Minuit2Minimizer::Scan", PrintLevel());
1096 if (!fMinuitFCN) {
1097 print.Error("Function must be set before using Scan");
1098 return false;
1099 }
1100
1101 if (ipar > fState.MinuitParameters().size()) {
1102 print.Error("Invalid number; minimizer variables must be set before using Scan");
1103 return false;
1104 }
1105
1106 // switch off Minuit2 printing
1107 const int prev_level = (PrintLevel() <= 0) ? TurnOffPrintInfoLevel() : -2;
1109
1110 // set the precision if needed
1111 if (Precision() > 0)
1113
1115 double amin = scan.Fval(); // fcn value of the function before scan
1116
1117 // first value is param value
1118 std::vector<std::pair<double, double>> result = scan(ipar, nstep - 1, xmin, xmax);
1119
1120 // restore global print level
1121 if (prev_level > -2)
1124
1125 if (result.size() != nstep) {
1126 print.Error("Invalid result from MnParameterScan");
1127 return false;
1128 }
1129 // sort also the returned points in x
1130 std::sort(result.begin(), result.end());
1131
1132 for (unsigned int i = 0; i < nstep; ++i) {
1133 x[i] = result[i].first;
1134 y[i] = result[i].second;
1135 }
1136
1137 // what to do if a new minimum has been found ?
1138 // use that as new minimum
1139 if (scan.Fval() < amin) {
1140 print.Info("A new minimum has been found");
1141 fState.SetValue(ipar, scan.Parameters().Value(ipar));
1142 }
1143
1144 return true;
1145}
1146
1147bool Minuit2Minimizer::Contour(unsigned int ipar, unsigned int jpar, unsigned int &npoints, double *x, double *y)
1148{
1149 // contour plot for parameter i and j
1150 // need a valid FunctionMinimum otherwise exits
1151
1152 MnPrint print("Minuit2Minimizer::Contour", PrintLevel());
1153
1154 if (fMinimum == nullptr) {
1155 print.Error("No function minimum existing; must minimize function before");
1156 return false;
1157 }
1158
1159 if (!fMinimum->IsValid()) {
1160 print.Error("Invalid function minimum");
1161 return false;
1162 }
1164
1166 // if error def has been changed update it in FunctionMinimum
1167 if (ErrorDef() != fMinimum->Up()) {
1169 }
1170
1171 print.Info("Computing contours -", ErrorDef());
1172
1173 // switch off Minuit2 printing (for level of 0,1)
1174 const int prev_level = (PrintLevel() <= 1) ? TurnOffPrintInfoLevel() : -2;
1176
1177 // set the precision if needed
1178 if (Precision() > 0)
1180
1181 // eventually one should specify tolerance in contours
1182 MnContours contour(*fMinuitFCN, *fMinimum, Strategy());
1183
1184 // restore global print level
1185 if (prev_level > -2)
1188
1189 // compute the contour
1190 std::vector<std::pair<double, double>> result = contour(ipar, jpar, npoints);
1191 if (result.size() != npoints) {
1192 print.Error("Invalid result from MnContours");
1193 return false;
1194 }
1195 for (unsigned int i = 0; i < npoints; ++i) {
1196 x[i] = result[i].first;
1197 y[i] = result[i].second;
1198 }
1199
1200 return true;
1201}
1202
1204{
1205 // find Hessian (full second derivative calculations)
1206 // the contained state will be updated with the Hessian result
1207 // in case a function minimum exists and is valid the result will be
1208 // appended in the function minimum
1209
1210 MnPrint print("Minuit2Minimizer::Hesse", PrintLevel());
1211
1212 if (!fMinuitFCN) {
1213 print.Error("FCN function has not been set");
1214 return false;
1215 }
1216
1217 const int maxfcn = MaxFunctionCalls();
1218 print.Info("Using max-calls", maxfcn);
1219
1220 // switch off Minuit2 printing
1221 const int prev_level = (PrintLevel() <= 0) ? TurnOffPrintInfoLevel() : -2;
1223
1224 // set the precision if needed
1225 if (Precision() > 0)
1227
1229
1230 // case when function minimum exists
1231 if (fMinimum) {
1232
1233 // if (PrintLevel() >= 3) {
1234 // std::cout << "Minuit2Minimizer::Hesse - State before running Hesse " << std::endl;
1235 // std::cout << fState << std::endl;
1236 // }
1237
1238 // run hesse and function minimum will be updated with Hesse result
1239 hesse(*fMinuitFCN, *fMinimum, maxfcn);
1240 // update user state
1242 }
1243
1244 else {
1245 // run Hesse on point stored in current state (independent of function minimum validity)
1246 // (x == 0)
1247 fState = hesse(*fMinuitFCN, fState, maxfcn);
1248 }
1249
1250 // restore global print level
1251 if (prev_level > -2)
1254
1255 if (PrintLevel() >= 3) {
1256 std::cout << "Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1257 std::cout << fState << std::endl;
1258 }
1259
1261 std::string covStatusType = "not valid";
1262 if (covStatus == 1)
1263 covStatusType = "approximate";
1264 if (covStatus == 2)
1265 covStatusType = "full but made positive defined";
1266 if (covStatus == 3)
1267 covStatusType = "accurate";
1268 if (covStatus == 0)
1269 covStatusType = "full but not positive defined";
1270
1271 if (!fState.HasCovariance()) {
1272 // if false means error is not valid and this is due to a failure in Hesse
1273 // update minimizer error status
1274 int hstatus = 4;
1275 // information on error state can be retrieved only if fMinimum is available
1276 if (fMinimum) {
1277 if (fMinimum->Error().HesseFailed())
1278 hstatus = 1;
1279 if (fMinimum->Error().InvertFailed())
1280 hstatus = 2;
1281 else if (!(fMinimum->Error().IsPosDef()))
1282 hstatus = 3;
1283 }
1284
1285 print.Warn("Hesse failed - matrix is", covStatusType);
1286 print.Warn(hstatus);
1287
1288 fStatus += 100 * hstatus;
1289 return false;
1290 }
1291
1292 print.Info("Hesse is valid - matrix is", covStatusType);
1293
1294 return true;
1295}
1296
1298{
1299 // return status of covariance matrix
1300 //-1 - not available (inversion failed or Hesse failed)
1301 // 0 - available but not positive defined
1302 // 1 - covariance only approximate
1303 // 2 full matrix but forced pos def
1304 // 3 full accurate matrix
1305
1306 if (fMinimum) {
1307 // case a function minimum is available
1309 return 3;
1310 else if (fMinimum->HasMadePosDefCovar())
1311 return 2;
1312 else if (fMinimum->HasValidCovariance())
1313 return 1;
1314 else if (fMinimum->HasCovariance())
1315 return 0;
1316 return -1;
1317 } else {
1318 // case fMinimum is not available - use state information
1319 return fState.CovarianceStatus();
1320 }
1321 return 0;
1322}
1323
1325{
1326 // set trace object
1327 if (fMinimizer)
1328 fMinimizer->Builder().SetTraceObject(obj);
1329}
1330
1332{
1333 // set storage level
1334 if (fMinimizer)
1335 fMinimizer->Builder().SetStorageLevel(level);
1336}
1337
1338} // end namespace Minuit2
1339
1340} // end namespace ROOT
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Int_t gErrorIgnoreLevel
Error handling routines.
Definition TError.cxx:31
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
#define gROOT
Definition TROOT.h:406
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:63
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:170
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:28
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
static ROOT::Math::IOptions * FindDefault(const char *name)
Find an extra options and return a nullptr if it is not existing.
double Tolerance() const
Absolute tolerance.
Definition Minimizer.h:314
unsigned int MaxFunctionCalls() const
Max number of function calls.
Definition Minimizer.h:308
double Precision() const
Precision of minimizer in the evaluation of the objective function.
Definition Minimizer.h:318
int fStatus
status of minimizer
Definition Minimizer.h:385
int Strategy() const
Strategy.
Definition Minimizer.h:321
double ErrorDef() const
Definition Minimizer.h:331
MinimizerOptions fOptions
minimizer options
Definition Minimizer.h:384
bool IsValidError() const
Definition Minimizer.h:334
int PrintLevel() const
Set print level.
Definition Minimizer.h:305
Combined minimizer: combination of Migrad and Simplex.
template wrapped class for adapting to FCNBase signature
Definition FCNAdapter.h:35
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:51
virtual void SetErrorDef(double)
add interface to set dynamically a new error definition Re-implement this function if needed.
Definition FCNBase.h:111
template wrapped class for adapting to FCNBase signature a IGradFunction
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 MinimumError & Error() const
const MnUserParameterState & UserState() const
const MinimumState & State() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Class holding the result of Minos (lower and upper values) for a specific parameter.
Definition MinosError.h:25
bool AtUpperLimit() const
Definition MinosError.h:92
bool AtLowerMaxFcn() const
Definition MinosError.h:93
bool AtUpperMaxFcn() const
Definition MinosError.h:94
bool AtLowerLimit() const
Definition MinosError.h:91
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...
bool SetCovariance(std::span< const double > cov, unsigned int nrow) override
set initial covariance matrix
bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double) override
set upper/lower limited variable (override if minimizer supports them )
bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj) override
find the contour points (xi,xj) of the function for parameter i and j around the minimum The contour ...
virtual bool SetCovarianceDiag(std::span< const double > d2, unsigned int n) override
set initial second derivatives
bool IsFixedVariable(unsigned int ivar) const override
query if an existing variable is fixed (i.e.
bool SetVariableUpperLimit(unsigned int ivar, double upper) override
set the upper-limit of an already existing variable
double GlobalCC(unsigned int i) const override
get global correlation coefficient for the variable i.
bool SetVariableValues(const double *val) override
Set the values of all existing variables (array must be dimensioned to the size of the existing param...
bool SetVariable(unsigned int ivar, const std::string &name, double val, double step) override
set free variable
const double * Errors() const override
return errors at the minimum
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
bool SetVariableStepSize(unsigned int ivar, double step) override
set the step size of an already existing variable
bool GetCovMatrix(double *cov) const override
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
bool ReleaseVariable(unsigned int ivar) override
release an existing variable
bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const override
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
bool Hesse() override
perform a full calculation of the Hessian matrix for error calculation If a valid minimum exists the ...
ROOT::Minuit2::ModularFunctionMinimizer * fMinimizer
bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0) override
get the minos error for parameter i, return false if Minos failed A minimizaiton must be performed be...
std::string VariableName(unsigned int ivar) const override
get name of variables (override if minimizer support storing of variable names)
int RunMinosError(unsigned int i, double &errLow, double &errUp, int runopt)
bool SetVariableLimits(unsigned int ivar, double lower, double upper) override
set the limits of an already existing variable
double Correlation(unsigned int i, unsigned int j) const override
return correlation coefficient between variable i and j.
bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower) override
set lower limit variable (override if minimizer supports them )
void SetTraceObject(MnTraceObject &obj)
set an object to trace operation for each iteration The object must be a (or inherit from) ROOT::Minu...
virtual const ROOT::Minuit2::ModularFunctionMinimizer * GetMinimizer() const
double CovMatrix(unsigned int i, unsigned int j) const override
return covariance matrix elements if the variable is fixed or const the value is zero The ordering of...
void SetMinimizerType(ROOT::Minuit2::EMinimizerType type)
bool SetVariableValue(unsigned int ivar, double val) override
set variable
bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0) override
scan a parameter i around the minimum.
int VariableIndex(const std::string &name) const override
get index of variable given a variable given a name return -1 if variable is not found
bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper) override
set upper limit variable (override if minimizer supports them )
ROOT::Minuit2::MnUserParameterState fState
bool SetVariableLowerLimit(unsigned int ivar, double lower) override
set the lower-limit of an already existing variable
bool FixVariable(unsigned int ivar) override
fix an existing variable
virtual void SetMinimizer(ROOT::Minuit2::ModularFunctionMinimizer *m)
void SetHessianFunction(std::function< bool(std::span< const double >, double *)> hfunc) override
set the function implementing Hessian computation
bool Minimize() override
method to perform the minimization.
ROOT::Minuit2::FunctionMinimum * fMinimum
bool SetFixedVariable(unsigned int, const std::string &, double) override
set fixed variable (override if minimizer supports them )
bool GetHessianMatrix(double *h) const override
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
ROOT::Minuit2::FCNBase * fMinuitFCN
void PrintResults() override
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;
void Clear() override
Reset for consecutive minimization - implement if needed.
~Minuit2Minimizer() override
Destructor (no operations)
int CovMatrixStatus() const override
return the status of the covariance matrix status = -1 : not available (inversion failed or Hesse fai...
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:35
const MnUserParameterState & State() const
Definition MnCross.h:90
API class for calculating the numerical covariance matrix (== 2x Inverse Hessian == 2x Inverse 2nd de...
Definition MnHesse.h:41
API class for Minos Error analysis (asymmetric errors); minimization has to be done before and Minimu...
Definition MnMinos.h:33
MnCross Loval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
Definition MnMinos.cxx:205
MnCross Upval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
Definition MnMinos.cxx:199
Scans the values of FCN as a function of one Parameter and retains the best function and Parameter va...
const MnUserParameters & Parameters() const
void Error(const Ts &... args)
Definition MnPrint.h:115
void Info(const Ts &... args)
Definition MnPrint.h:127
static int SetGlobalLevel(int level)
Definition MnPrint.cxx:111
void Warn(const Ts &... args)
Definition MnPrint.h:121
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
Definition MnStrategy.h:27
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
void AddCovariance(const MnUserCovariance &)
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
const MnUserCovariance & IntCovariance() const
const MnUserCovariance & Covariance() const
virtual const MinimumBuilder & Builder() const =0
Class implementing the required methods for a minimization using SCAN API is provided in the upper RO...
Class implementing the required methods for a minimization using Simplex.
Instantiates the SeedGenerator and MinimumBuilder for Variable Metric Minimization method.
const_iterator begin() const
const_iterator end() const
Mother of all ROOT objects.
Definition TObject.h:41
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:421
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
void RestoreGlobalPrintLevel(int)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4