Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooMinimizer.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * AL, Alfio Lazzaro, INFN Milan, alfio.lazzaro@mi.infn.it *
9 * PB, Patrick Bos, NL eScience Center, p.bos@esciencecenter.nl *
10 * *
11 * Redistribution and use in source and binary forms, *
12 * with or without modification, are permitted according to the terms *
13 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
14 *****************************************************************************/
15
16/**
17\file RooMinimizer.cxx
18\class RooMinimizer
19\ingroup Roofitcore
20
21Wrapper class around ROOT::Math::Minimizer that
22provides a seamless interface between the minimizer functionality
23and the native RooFit interface.
24By default the Minimizer is Minuit 2.
25RooMinimizer can minimize any RooAbsReal function with respect to
26its parameters. Usual choices for minimization are the object returned by
27RooAbsPdf::createNLL() or RooAbsReal::createChi2().
28RooMinimizer has methods corresponding to MINUIT functions like
29hesse(), migrad(), minos() etc. In each of these function calls
30the state of the MINUIT engine is synchronized with the state
31of the RooFit variables: any change in variables, change
32in the constant status etc is forwarded to MINUIT prior to
33execution of the MINUIT call. Afterwards the RooFit objects
34are resynchronized with the output state of MINUIT: changes
35parameter values, errors are propagated.
36Various methods are available to control verbosity, profiling,
37automatic PDF optimization.
38**/
39
40#include "RooMinimizer.h"
41
42#include "RooAbsMinimizerFcn.h"
43#include "RooArgSet.h"
44#include "RooArgList.h"
45#include "RooAbsReal.h"
46#include "RooDataSet.h"
47#include "RooRealVar.h"
48#include "RooSentinel.h"
49#include "RooMsgService.h"
50#include "RooPlot.h"
51#include "RooMinimizerFcn.h"
52#include "RooFitResult.h"
56#ifdef ROOFIT_MULTIPROCESS
59#endif
60
61#include <Fit/BasicFCN.h>
62#include <Math/Minimizer.h>
63#include <TClass.h>
64#include <TGraph.h>
65#include <TMarker.h>
66
67#include <fstream>
68#include <iostream>
69#include <stdexcept> // logic_error
70
72
73////////////////////////////////////////////////////////////////////////////////
74/// Construct MINUIT interface to given function. Function can be anything,
75/// but is typically a -log(likelihood) implemented by RooNLLVar or a chi^2
76/// (implemented by RooChi2Var). Other frequent use cases are a RooAddition
77/// of a RooNLLVar plus a penalty or constraint term. This class propagates
78/// all RooFit information (floating parameters, their values and errors)
79/// to MINUIT before each MINUIT call and propagates all MINUIT information
80/// back to the RooFit object at the end of each call (updated parameter
81/// values, their (asymmetric errors) etc. The default MINUIT error level
82/// for HESSE and MINOS error analysis is taken from the defaultErrorLevel()
83/// value of the input function.
84
85/// Constructor that accepts all configuration in struct with RooAbsReal likelihood
86RooMinimizer::RooMinimizer(RooAbsReal &function, Config const &cfg) : _cfg(cfg)
87{
89 auto nll_real = dynamic_cast<RooFit::TestStatistics::RooRealL *>(&function);
90 if (nll_real != nullptr) {
91 if (_cfg.parallelize != 0) { // new test statistic with multiprocessing library with
92 // parallel likelihood or parallel gradient
93#ifdef ROOFIT_MULTIPROCESS
95 // Note that this is necessary because there is currently no serial-mode LikelihoodGradientWrapper.
96 // We intend to repurpose RooGradMinimizerFcn to build such a LikelihoodGradientSerial class.
97 coutI(InputArguments) << "Modular likelihood detected and likelihood parallelization requested, "
98 << "also setting parallel gradient calculation mode." << std::endl;
100 }
101 // If _cfg.parallelize is larger than zero set the number of workers to that value. Otherwise do not do
102 // anything and let RooFit::MultiProcess handle the number of workers
103 if (_cfg.parallelize > 0)
106
107 _fcn = std::make_unique<RooFit::TestStatistics::MinuitFcnGrad>(
108 nll_real->getRooAbsL(), this, _config.ParamsSettings(),
110 static_cast<RooFit::TestStatistics::LikelihoodMode>(int(_cfg.enableParallelDescent))},
112#else
113 throw std::logic_error(
114 "Parallel minimization requested, but ROOT was not compiled with multiprocessing enabled, "
115 "please recompile with -Droofit_multiprocess=ON for parallel evaluation");
116#endif
117 } else { // modular test statistic non parallel
118 coutW(InputArguments)
119 << "Requested modular likelihood without gradient parallelization, some features such as offsetting "
120 << "may not work yet. Non-modular likelihoods are more reliable without parallelization." << std::endl;
121 // The RooRealL that is used in the case where the modular likelihood is being passed to a RooMinimizerFcn does
122 // not have offsetting implemented. Therefore, offsetting will not work in this case. Other features might also
123 // not work since the RooRealL was not intended for minimization. Further development is required to make the
124 // MinuitFcnGrad also handle serial gradient minimization. The MinuitFcnGrad accepts a RooAbsL and has
125 // offsetting implemented, thus omitting the need for RooRealL minimization altogether.
126 _fcn = std::make_unique<RooMinimizerFcn>(&function, this);
127 }
128 } else {
129 if (_cfg.parallelize != 0) { // Old test statistic with parallel likelihood or gradient
130 throw std::logic_error("In RooMinimizer constructor: Selected likelihood evaluation but a "
131 "non-modular likelihood was given. Please supply ModularL(true) as an "
132 "argument to createNLL for modular likelihoods to use likelihood "
133 "or gradient parallelization.");
134 }
135 _fcn = std::make_unique<RooMinimizerFcn>(&function, this);
136 }
137 initMinimizerFcnDependentPart(function.defaultErrorLevel());
138};
139
140/// Initialize the part of the minimizer that is independent of the function to be minimized
142{
143 RooSentinel::activate();
145
147 setEps(1.0); // default tolerance
148}
149
150/// Initialize the part of the minimizer that is dependent on the function to be minimized
152{
153 // default max number of calls
154 _config.MinimizerOptions().SetMaxIterations(500 * _fcn->getNDim());
156
157 // Shut up for now
158 setPrintLevel(-1);
159
160 // Use +0.5 for 1-sigma errors
161 setErrorLevel(defaultErrorLevel);
162
163 // Declare our parameters to MINUIT
164 _fcn->Synchronize(_config.ParamsSettings());
165
166 // Now set default verbosity
167 setPrintLevel(RooMsgService::instance().silentMode() ? -1 : 1);
168
169 // Set user defined and default _fcn config
171
172 // Likelihood holds information on offsetting in old style, so do not set here unless explicitly set by user
173 if (_cfg.offsetting != -1) {
175 }
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Destructor
180
182
183////////////////////////////////////////////////////////////////////////////////
184/// Change MINUIT strategy to istrat. Accepted codes
185/// are 0,1,2 and represent MINUIT strategies for dealing
186/// most efficiently with fast FCNs (0), expensive FCNs (2)
187/// and 'intermediate' FCNs (1)
188
190{
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Change maximum number of MINUIT iterations
196/// (RooMinimizer default 500 * #%parameters)
197
199{
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Change maximum number of likelihood function class from MINUIT
205/// (RooMinimizer default 500 * #%parameters)
206
208{
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Set the level for MINUIT error analysis to the given
214/// value. This function overrides the default value
215/// that is taken in the RooMinimizer constructor from
216/// the defaultErrorLevel() method of the input function
217
219{
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Change MINUIT epsilon
225
226void RooMinimizer::setEps(double eps)
227{
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Enable internal likelihood offsetting for enhanced numeric precision
233
235{
236 _cfg.offsetting = flag;
237 _fcn->setOffsetting(_cfg.offsetting);
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Choose the minimizer algorithm.
242///
243/// Passing an empty string selects the default minimizer type returned by
244/// ROOT::Math::MinimizerOptions::DefaultMinimizerType().
245
246void RooMinimizer::setMinimizerType(std::string const &type)
247{
249
250 if ((_cfg.parallelize != 0) && _cfg.minimizerType != "Minuit2") {
251 std::stringstream ss;
252 ss << "In RooMinimizer::setMinimizerType: only Minuit2 is supported when not using classic function mode!";
253 if (type.empty()) {
254 ss << "\nPlease set it as your default minimizer via "
255 "ROOT::Math::MinimizerOptions::SetDefaultMinimizer(\"Minuit2\").";
256 }
257 throw std::invalid_argument(ss.str());
258 }
259}
260
261void RooMinimizer::determineStatus(bool fitterReturnValue)
262{
263 // Minuit-given status:
264 _status = fitterReturnValue ? _result->fStatus : -1;
265
266 // RooFit-based additional failed state information:
267 if (evalCounter() <= _fcn->GetNumInvalidNLL()) {
268 coutE(Minimization) << "RooMinimizer: all function calls during minimization gave invalid NLL values!"
269 << std::endl;
270 }
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Minimise the function passed in the constructor.
275/// \param[in] type Type of fitter to use, e.g. "Minuit" "Minuit2". Passing an
276/// empty string will select the default minimizer type of the
277/// RooMinimizer, as returned by
278/// ROOT::Math::MinimizerOptions::DefaultMinimizerType().
279/// \attention This overrides the default fitter of this RooMinimizer.
280/// \param[in] alg Fit algorithm to use. (Optional)
281int RooMinimizer::minimize(const char *type, const char *alg)
282{
283 if (_cfg.timingAnalysis) {
284#ifdef ROOFIT_MULTIPROCESS
286#else
287 throw std::logic_error("ProcessTimer, but ROOT was not compiled with multiprocessing enabled, "
288 "please recompile with -Droofit_multiprocess=ON for logging with the "
289 "ProcessTimer.");
290#endif
291 }
292 _fcn->Synchronize(_config.ParamsSettings());
293
296
297 profileStart();
298 {
299 auto ctx = makeEvalErrorContext();
300
301 bool ret = fitFCN(*_fcn->getMultiGenFcn());
302 determineStatus(ret);
303 }
304 profileStop();
305 _fcn->BackProp();
306
307 saveStatus("MINIMIZE", _status);
308
309 return _status;
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Execute MIGRAD. Changes in parameter values
314/// and calculated errors are automatically
315/// propagated back the RooRealVars representing
316/// the floating parameters in the MINUIT operation.
317
319{
320 return exec("migrad", "MIGRAD");
321}
322
323int RooMinimizer::exec(std::string const &algoName, std::string const &statusName)
324{
325 _fcn->Synchronize(_config.ParamsSettings());
326 profileStart();
327 {
328 auto ctx = makeEvalErrorContext();
329
330 bool ret = false;
331 if (algoName == "hesse") {
332 // HESSE has a special entry point in the ROOT::Math::Fitter
334 ret = calculateHessErrors();
335 } else if (algoName == "minos") {
336 // MINOS has a special entry point in the ROOT::Math::Fitter
338 ret = calculateMinosErrors();
339 } else {
340 _config.SetMinimizer(_cfg.minimizerType.c_str(), algoName.c_str());
341 ret = fitFCN(*_fcn->getMultiGenFcn());
342 }
343 determineStatus(ret);
344 }
345 profileStop();
346 _fcn->BackProp();
347
348 saveStatus(statusName.c_str(), _status);
349
350 return _status;
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Execute HESSE. Changes in parameter values
355/// and calculated errors are automatically
356/// propagated back the RooRealVars representing
357/// the floating parameters in the MINUIT operation.
358
360{
361 if (_minimizer == nullptr) {
362 coutW(Minimization) << "RooMinimizer::hesse: Error, run Migrad before Hesse!" << std::endl;
363 _status = -1;
364 return _status;
365 }
366
367 return exec("hesse", "HESSE");
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Execute MINOS. Changes in parameter values
372/// and calculated errors are automatically
373/// propagated back the RooRealVars representing
374/// the floating parameters in the MINUIT operation.
375
377{
378 if (_minimizer == nullptr) {
379 coutW(Minimization) << "RooMinimizer::minos: Error, run Migrad before Minos!" << std::endl;
380 _status = -1;
381 return _status;
382 }
383
384 return exec("minos", "MINOS");
385}
386
387////////////////////////////////////////////////////////////////////////////////
388/// Execute MINOS for given list of parameters. Changes in parameter values
389/// and calculated errors are automatically
390/// propagated back the RooRealVars representing
391/// the floating parameters in the MINUIT operation.
392
393int RooMinimizer::minos(const RooArgSet &minosParamList)
394{
395 if (_minimizer == nullptr) {
396 coutW(Minimization) << "RooMinimizer::minos: Error, run Migrad before Minos!" << std::endl;
397 _status = -1;
398 } else if (!minosParamList.empty()) {
399
400 _fcn->Synchronize(_config.ParamsSettings());
401 profileStart();
402 {
403 auto ctx = makeEvalErrorContext();
404
405 // get list of parameters for Minos
406 std::vector<unsigned int> paramInd;
407 for (RooAbsArg *arg : minosParamList) {
408 RooAbsArg *par = _fcn->GetFloatParamList()->find(arg->GetName());
409 if (par && !par->isConstant()) {
410 int index = _fcn->GetFloatParamList()->index(par);
411 paramInd.push_back(index);
412 }
413 }
414
415 if (!paramInd.empty()) {
416 // set the parameter indices
417 _config.SetMinosErrors(paramInd);
418
420 bool ret = calculateMinosErrors();
421 determineStatus(ret);
422 // to avoid that following minimization computes automatically the Minos errors
423 _config.SetMinosErrors(false);
424 }
425 }
426 profileStop();
427 _fcn->BackProp();
428
429 saveStatus("MINOS", _status);
430 }
431
432 return _status;
433}
434
435////////////////////////////////////////////////////////////////////////////////
436/// Execute SEEK. Changes in parameter values
437/// and calculated errors are automatically
438/// propagated back the RooRealVars representing
439/// the floating parameters in the MINUIT operation.
440
442{
443 return exec("seek", "SEEK");
444}
445
446////////////////////////////////////////////////////////////////////////////////
447/// Execute SIMPLEX. Changes in parameter values
448/// and calculated errors are automatically
449/// propagated back the RooRealVars representing
450/// the floating parameters in the MINUIT operation.
451
453{
454 return exec("simplex", "SIMPLEX");
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// Execute IMPROVE. Changes in parameter values
459/// and calculated errors are automatically
460/// propagated back the RooRealVars representing
461/// the floating parameters in the MINUIT operation.
462
464{
465 return exec("migradimproved", "IMPROVE");
466}
467
468////////////////////////////////////////////////////////////////////////////////
469/// Change the MINUIT internal printing level
470
472{
473 _config.MinimizerOptions().SetPrintLevel(newLevel + 1);
474}
475
476////////////////////////////////////////////////////////////////////////////////
477/// Get the MINUIT internal printing level
478
480{
481 return _config.MinimizerOptions().PrintLevel() + 1;
482}
483
484////////////////////////////////////////////////////////////////////////////////
485/// If flag is true, perform constant term optimization on
486/// function being minimized.
487
489{
490 _fcn->setOptimizeConst(flag);
491}
492
493////////////////////////////////////////////////////////////////////////////////
494/// Save and return a RooFitResult snapshot of current minimizer status.
495/// This snapshot contains the values of all constant parameters,
496/// the value of all floating parameters at RooMinimizer construction and
497/// after the last MINUIT operation, the MINUIT status, variance quality,
498/// EDM setting, number of calls with evaluation problems, the minimized
499/// function value and the full correlation matrix.
500
501RooFit::OwningPtr<RooFitResult> RooMinimizer::save(const char *userName, const char *userTitle)
502{
503 if (_minimizer == nullptr) {
504 coutW(Minimization) << "RooMinimizer::save: Error, run minimization before!" << std::endl;
505 return nullptr;
506 }
507
508 TString name = userName ? userName : Form("%s", _fcn->getFunctionName().c_str());
509 TString title = userTitle ? userTitle : Form("%s", _fcn->getFunctionTitle().c_str());
510 auto fitRes = std::make_unique<RooFitResult>(name, title);
511
512 // Move eventual fixed parameters in floatList to constList
513 RooArgList saveConstList(*(_fcn->GetConstParamList()));
514 RooArgList saveFloatInitList(*(_fcn->GetInitFloatParamList()));
515 RooArgList saveFloatFinalList(*(_fcn->GetFloatParamList()));
516 for (std::size_t i = 0; i < _fcn->GetFloatParamList()->size(); i++) {
517 RooAbsArg *par = _fcn->GetFloatParamList()->at(i);
518 if (par->isConstant()) {
519 saveFloatInitList.remove(*saveFloatInitList.find(par->GetName()), true);
520 saveFloatFinalList.remove(*par);
521 saveConstList.add(*par);
522 }
523 }
524 saveConstList.sort();
525
526 fitRes->setConstParList(saveConstList);
527 fitRes->setInitParList(saveFloatInitList);
528
529 double removeOffset = 0.;
530 fitRes->setNumInvalidNLL(_fcn->GetNumInvalidNLL());
531 removeOffset = -_fcn->getOffset();
532
533 fitRes->setStatus(_status);
534 fitRes->setCovQual(_minimizer->CovMatrixStatus());
535 fitRes->setMinNLL(_result->fVal + removeOffset);
536 fitRes->setEDM(_result->fEdm);
537 fitRes->setFinalParList(saveFloatFinalList);
538 if (!_extV) {
539 fillCorrMatrix(*fitRes);
540 } else {
541 fitRes->setCovarianceMatrix(*_extV);
542 }
543
544 fitRes->setStatusHistory(_statusHistory);
545
546 return RooFit::makeOwningPtr(std::move(fitRes));
547}
548
549namespace {
550
551/// retrieve covariance matrix element
552double covMatrix(std::vector<double> const &covMat, unsigned int i, unsigned int j)
553{
554 if (covMat.empty())
555 return 0; // no matrix is available in case of non-valid fits
556 return j < i ? covMat[j + i * (i + 1) / 2] : covMat[i + j * (j + 1) / 2];
557}
558
559/// retrieve correlation elements
560double correlation(std::vector<double> const &covMat, unsigned int i, unsigned int j)
561{
562 if (covMat.empty())
563 return 0; // no matrix is available in case of non-valid fits
564 double tmp = covMatrix(covMat, i, i) * covMatrix(covMat, j, j);
565 return tmp > 0 ? covMatrix(covMat, i, j) / std::sqrt(tmp) : 0;
566}
567
568} // namespace
569
571{
572 const std::size_t nParams = _fcn->getNDim();
573 std::vector<double> globalCC;
574 TMatrixDSym corrs(nParams);
575 TMatrixDSym covs(nParams);
576 for (std::size_t ic = 0; ic < nParams; ic++) {
577 globalCC.push_back(_result->fGlobalCC[ic]);
578 for (std::size_t ii = 0; ii < nParams; ii++) {
579 corrs(ic, ii) = correlation(_result->fCovMatrix, ic, ii);
580 covs(ic, ii) = covMatrix(_result->fCovMatrix, ic, ii);
581 }
582 }
583 fitRes.fillCorrMatrix(globalCC, corrs, covs);
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Create and draw a TH2 with the error contours in the parameters `var1` and `var2`.
588/// \param[in] var1 The first parameter (x axis).
589/// \param[in] var2 The second parameter (y axis).
590/// \param[in] n1 First contour.
591/// \param[in] n2 Optional contour. 0 means don't draw.
592/// \param[in] n3 Optional contour. 0 means don't draw.
593/// \param[in] n4 Optional contour. 0 means don't draw.
594/// \param[in] n5 Optional contour. 0 means don't draw.
595/// \param[in] n6 Optional contour. 0 means don't draw.
596/// \param[in] npoints Number of points for evaluating the contour.
597///
598/// Up to six contours can be drawn using the arguments `n1` to `n6` to request the desired
599/// coverage in units of \f$ \sigma = n^2 \cdot \mathrm{ErrorDef} \f$.
600/// See ROOT::Math::Minimizer::ErrorDef().
601
602RooPlot *RooMinimizer::contour(RooRealVar &var1, RooRealVar &var2, double n1, double n2, double n3, double n4,
603 double n5, double n6, unsigned int npoints)
604{
605 RooArgList *params = _fcn->GetFloatParamList();
606 RooArgList paramSave;
607 params->snapshot(paramSave);
608
609 // Verify that both variables are floating parameters of PDF
610 int index1 = _fcn->GetFloatParamList()->index(&var1);
611 if (index1 < 0) {
612 coutE(Minimization) << "RooMinimizer::contour(" << GetName() << ") ERROR: " << var1.GetName()
613 << " is not a floating parameter of " << _fcn->getFunctionName() << std::endl;
614 return nullptr;
615 }
616
617 int index2 = _fcn->GetFloatParamList()->index(&var2);
618 if (index2 < 0) {
619 coutE(Minimization) << "RooMinimizer::contour(" << GetName() << ") ERROR: " << var2.GetName()
620 << " is not a floating parameter of PDF " << _fcn->getFunctionName() << std::endl;
621 return nullptr;
622 }
623
624 // create and draw a frame
625 RooPlot *frame = new RooPlot(var1, var2);
626
627 // draw a point at the current parameter values
628 TMarker *point = new TMarker(var1.getVal(), var2.getVal(), 8);
629 frame->addObject(point);
630
631 // check first if a inimizer is available. If not means
632 // the minimization is not done , so do it
633 if (_minimizer == nullptr) {
634 coutW(Minimization) << "RooMinimizer::contour: Error, run Migrad before contours!" << std::endl;
635 return frame;
636 }
637
638 // remember our original value of ERRDEF
639 double errdef = _minimizer->ErrorDef();
640
641 double n[6];
642 n[0] = n1;
643 n[1] = n2;
644 n[2] = n3;
645 n[3] = n4;
646 n[4] = n5;
647 n[5] = n6;
648
649 for (int ic = 0; ic < 6; ic++) {
650 if (n[ic] > 0) {
651
652 // set the value corresponding to an n1-sigma contour
653 _minimizer->SetErrorDef(n[ic] * n[ic] * errdef);
654
655 // calculate and draw the contour
656 std::vector<double> xcoor(npoints + 1);
657 std::vector<double> ycoor(npoints + 1);
658 bool ret = _minimizer->Contour(index1, index2, npoints, xcoor.data(), ycoor.data());
659
660 if (!ret) {
661 coutE(Minimization) << "RooMinimizer::contour(" << GetName()
662 << ") ERROR: MINUIT did not return a contour graph for n=" << n[ic] << std::endl;
663 } else {
664 xcoor[npoints] = xcoor[0];
665 ycoor[npoints] = ycoor[0];
666 TGraph *graph = new TGraph(npoints + 1, xcoor.data(), ycoor.data());
667
668 graph->SetName(Form("contour_%s_n%f", _fcn->getFunctionName().c_str(), n[ic]));
669 graph->SetLineStyle(ic + 1);
670 graph->SetLineWidth(2);
671 graph->SetLineColor(kBlue);
672 frame->addObject(graph, "L");
673 }
674 }
675 }
676
677 // restore the original ERRDEF
678 _minimizer->SetErrorDef(errdef);
679
680 // restore parameter values
681 params->assign(paramSave);
682
683 return frame;
684}
685
686////////////////////////////////////////////////////////////////////////////////
687/// Add parameters in metadata field to process timer
688
690{
691#ifdef ROOFIT_MULTIPROCESS
692 // parameter indices for use in timing heat matrix
693 std::vector<std::string> parameter_names;
694 for (auto &&parameter : *_fcn->GetFloatParamList()) {
695 parameter_names.push_back(parameter->GetName());
696 if (_cfg.verbose) {
697 coutI(Minimization) << "parameter name: " << parameter_names.back() << std::endl;
698 }
699 }
701#else
702 coutI(Minimization) << "Not adding parameters to processtimer because multiprocessing is not enabled." << std::endl;
703#endif
704}
705
706////////////////////////////////////////////////////////////////////////////////
707/// Start profiling timer
708
710{
711 if (_cfg.profile) {
712 _timer.Start();
713 _cumulTimer.Start(_profileStart ? false : true);
714 _profileStart = true;
715 }
716}
717
718////////////////////////////////////////////////////////////////////////////////
719/// Stop profiling timer and report results of last session
720
722{
723 if (_cfg.profile) {
724 _timer.Stop();
726 coutI(Minimization) << "Command timer: ";
727 _timer.Print();
728 coutI(Minimization) << "Session timer: ";
730 }
731}
732
734{
735 return _fcn->getMultiGenFcn();
736}
737
738////////////////////////////////////////////////////////////////////////////////
739/// Apply results of given external covariance matrix. i.e. propagate its errors
740/// to all RRV parameter representations and give this matrix instead of the
741/// HESSE matrix at the next save() call
742
744{
745 _extV.reset(static_cast<TMatrixDSym *>(V.Clone()));
746 _fcn->ApplyCovarianceMatrix(*_extV);
747}
748
750{
751 // Import the results of the last fit performed, interpreting
752 // the fit parameters as the given varList of parameters.
753
754 if (_minimizer == nullptr) {
755 oocoutE(nullptr, InputArguments) << "RooMinimizer::save: Error, run minimization before!" << std::endl;
756 return nullptr;
757 }
758
759 auto res = std::make_unique<RooFitResult>("lastMinuitFit", "Last MINUIT fit");
760
761 // Extract names of fit parameters
762 // and construct corresponding RooRealVars
763 RooArgList constPars("constPars");
764 RooArgList floatPars("floatPars");
765
766 for (unsigned int i = 0; i < _fcn->getNDim(); ++i) {
767
768 TString varName(_fcn->GetFloatParamList()->at(i)->GetName());
769 bool isConst(_result->isParameterFixed(i));
770
771 double xlo = _config.ParSettings(i).LowerLimit();
772 double xhi = _config.ParSettings(i).UpperLimit();
773 double xerr = _result->error(i);
774 double xval = _result->fParams[i];
775
776 std::unique_ptr<RooRealVar> var;
777
778 if ((xlo < xhi) && !isConst) {
779 var = std::make_unique<RooRealVar>(varName, varName, xval, xlo, xhi);
780 } else {
781 var = std::make_unique<RooRealVar>(varName, varName, xval);
782 }
783 var->setConstant(isConst);
784
785 if (isConst) {
786 constPars.addOwned(std::move(var));
787 } else {
788 var->setError(xerr);
789 floatPars.addOwned(std::move(var));
790 }
791 }
792
793 res->setConstParList(constPars);
794 res->setInitParList(floatPars);
795 res->setFinalParList(floatPars);
796 res->setMinNLL(_result->fVal);
797 res->setEDM(_result->fEdm);
798 res->setCovQual(_minimizer->CovMatrixStatus());
799 res->setStatus(_result->fStatus);
800 fillCorrMatrix(*res);
801
802 return RooFit::makeOwningPtr(std::move(res));
803}
804
805/// Try to recover from invalid function values. When invalid function values
806/// are encountered, a penalty term is returned to the minimiser to make it
807/// back off. This sets the strength of this penalty. \note A strength of zero
808/// is equivalent to a constant penalty (= the gradient vanishes, ROOT < 6.24).
809/// Positive values lead to a gradient pointing away from the undefined
810/// regions. Use ~10 to force the minimiser away from invalid function values.
812{
813 _cfg.recoverFromNaN = strength;
814}
815
816bool RooMinimizer::setLogFile(const char *logf)
817{
818 _cfg.logf = logf;
819 return _cfg.logf ? _fcn->SetLogFile(_cfg.logf) : false;
820}
821
823{
824 return _fcn->evalCounter();
825}
827{
828 _fcn->zeroEvalCount();
829}
830
832{
833 return _fcn->getNDim();
834}
835
836std::ofstream *RooMinimizer::logfile()
837{
838 return _fcn->GetLogFile();
839}
841{
842 return _fcn->GetMaxFCN();
843}
845{
846 return _fcn->getOffset();
847}
848
849std::unique_ptr<RooAbsReal::EvalErrorContext> RooMinimizer::makeEvalErrorContext() const
850{
852 // If evaluation error printing is disabled, we don't need to collect the
853 // errors and only need to count them. This significantly reduces the
854 // performance overhead when having evaluation errors.
856 return std::make_unique<RooAbsReal::EvalErrorContext>(m);
857}
858
860{
861 // fit a user provided FCN function
862 // create fit parameter settings
863 unsigned int npar = fcn.NDim();
864 if (npar == 0) {
865 coutE(Minimization) << "RooMinimizer::fitFCN(): FCN function has zero parameters" << std::endl;
866 return false;
867 }
868
869 // init the minimizer
871 // perform the minimization
872
873 // perform the minimization (assume we have already initialized the minimizer)
874
875 bool isValid = _minimizer->Minimize();
876
877 if (!_result)
878 _result = std::make_unique<FitResult>();
879
880 fillResult(isValid);
881
882 // set also new parameter values and errors in FitConfig
883 if (isValid)
885
886 return isValid;
887}
888
890{
891 // compute the Hesse errors according to configuration
892 // set in the parameters and append value in fit result
893
894 // update minimizer (recreate if not done or if name has changed
895 if (!updateMinimizerOptions()) {
896 coutE(Minimization) << "RooMinimizer::calculateHessErrors() Error re-initializing the minimizer" << std::endl;
897 return false;
898 }
899
900 // run Hesse
901 bool ret = _minimizer->Hesse();
902 if (!ret)
903 coutE(Minimization) << "RooMinimizer::calculateHessErrors() Error when calculating Hessian" << std::endl;
904
905 // update minimizer results with what comes out from Hesse
906 // in case is empty - create from a FitConfig
907 if (_result->fParams.empty())
908 _result = std::make_unique<FitResult>(_config);
909
910 // re-give a minimizer instance in case it has been changed
911 ret |= update(ret);
912
913 // set also new errors in FitConfig
914 if (ret)
916
917 return ret;
918}
919
921{
922 // compute the Minos errors according to configuration
923 // set in the parameters and append value in fit result
924 // normally Minos errors are computed just after the minimization
925 // (in DoMinimization) aftewr minimizing if the
926 // FitConfig::MinosErrors() flag is set
927
928 // update minimizer (but cannot re-create in this case). Must use an existing one
929 if (!updateMinimizerOptions(false)) {
930 coutE(Minimization) << "RooMinimizer::calculateHessErrors() Error re-initializing the minimizer" << std::endl;
931 return false;
932 }
933
934 const std::vector<unsigned int> &ipars = _config.MinosParams();
935 unsigned int n = (!ipars.empty()) ? ipars.size() : _fcn->getNDim();
936 bool ok = false;
937
938 int iparNewMin = 0;
939 int iparMax = n;
940 int iter = 0;
941 // rerun minos for the parameters run before a new Minimum has been found
942 do {
943 if (iparNewMin > 0)
944 coutI(Minimization) << "RooMinimizer::calculateMinosErrors() Run again Minos for some parameters because a "
945 "new Minimum has been found"
946 << std::endl;
947 iparNewMin = 0;
948 for (int i = 0; i < iparMax; ++i) {
949 double elow, eup;
950 unsigned int index = (!ipars.empty()) ? ipars[i] : i;
951 bool ret = _minimizer->GetMinosError(index, elow, eup);
952 // flags case when a new minimum has been found
953 if ((_minimizer->MinosStatus() & 8) != 0) {
954 iparNewMin = i;
955 }
956 if (ret)
957 _result->fMinosErrors.emplace(index, std::make_pair(elow, eup));
958 ok |= ret;
959 }
960
961 iparMax = iparNewMin;
962 iter++; // to avoid infinite looping
963 } while (iparNewMin > 0 && iter < 10);
964 if (!ok) {
965 coutE(Minimization)
966 << "RooMinimizer::calculateMinosErrors() Minos error calculation failed for all the selected parameters"
967 << std::endl;
968 }
969
970 // re-give a minimizer instance in case it has been changed
971 // but maintain previous valid status. Do not set result to false if minos failed
972 ok &= update(_result->fValid);
973
974 return ok;
975}
976
978{
979 _minimizer = std::unique_ptr<ROOT::Math::Minimizer>(_config.CreateMinimizer());
980 _minimizer->SetFunction(*getMultiGenFcn());
981 _minimizer->SetVariables(_config.ParamsSettings().begin(), _config.ParamsSettings().end());
982}
983
984bool RooMinimizer::updateMinimizerOptions(bool canDifferentMinim)
985{
986 // update minimizer options when re-doing a Fit or computing Hesse or Minos errors
987
988 // create a new minimizer if it is different type
989 // minimizer type string stored in FitResult is "minimizer name" + " / " + minimizer algo
990 std::string newMinimType = _config.MinimizerName();
991 if (_minimizer && _result && newMinimType != _result->fMinimType) {
992 // if a different minimizer is allowed (e.g. when calling Hesse)
993 if (canDifferentMinim) {
994 std::string msg = "Using now " + newMinimType;
995 coutI(Minimization) << "RooMinimizer::updateMinimizerOptions(): " << msg << std::endl;
997 } else {
998 std::string msg = "Cannot change minimizer. Continue using " + _result->fMinimType;
999 coutW(Minimization) << "RooMinimizer::updateMinimizerOptions() " << msg << std::endl;
1000 }
1001 }
1002
1003 // create minimizer if it was not done before
1004 if (!_minimizer) {
1005 initMinimizer();
1006 }
1007
1008 // set new minimizer options (but not functions and parameters)
1009 _minimizer->SetOptions(_config.MinimizerOptions());
1010 return true;
1011}
1012
1014{
1015 // update the fit configuration after a fit using the obtained result
1016 if (_result->fParams.empty() || !_result->fValid)
1017 return;
1018 for (unsigned int i = 0; i < _config.NPar(); ++i) {
1020 par.SetValue(_result->fParams[i]);
1021 if (_result->error(i) > 0)
1022 par.SetStepSize(_result->error(i));
1023 }
1024}
1025
1027 : fStatus(-99), // use this special convention to flag it when printing result
1028 fCovStatus(0),
1029 fParams(fconfig.NPar()),
1030 fErrors(fconfig.NPar())
1031{
1032 // create a Fit result from a fit config (i.e. with initial parameter values
1033 // and errors equal to step values
1034 // The model function is NULL in this case
1035
1036 // set minimizer type and algorithm
1037 fMinimType = fconfig.MinimizerType();
1038 // append algorithm name for minimizer that support it
1039 if ((fMinimType.find("Fumili") == std::string::npos) && (fMinimType.find("GSLMultiFit") == std::string::npos)) {
1040 if (!fconfig.MinimizerAlgoType().empty())
1041 fMinimType += " / " + fconfig.MinimizerAlgoType();
1042 }
1043
1044 // get parameter values and errors (step sizes)
1045 for (unsigned int i = 0; i < fconfig.NPar(); ++i) {
1046 const ROOT::Fit::ParameterSettings &par = fconfig.ParSettings(i);
1047 fParams[i] = par.Value();
1048 fErrors[i] = par.StepSize();
1049 if (par.IsFixed())
1050 fFixedParams[i] = true;
1051 }
1052}
1053
1055{
1057 ROOT::Fit::FitConfig const &fconfig = _config;
1058
1059 // Fill the FitResult after minimization using result from Minimizers
1060
1061 _result->fValid = isValid;
1062 _result->fStatus = min.Status();
1063 _result->fCovStatus = min.CovMatrixStatus();
1064 _result->fVal = min.MinValue();
1065 _result->fEdm = min.Edm();
1066
1067 _result->fMinimType = fconfig.MinimizerName();
1068
1069 const unsigned int npar = min.NDim();
1070 if (npar == 0)
1071 return;
1072
1073 if (min.X())
1074 _result->fParams = std::vector<double>(min.X(), min.X() + npar);
1075 else {
1076 // case minimizer does not provide minimum values (it failed) take from configuration
1077 _result->fParams.resize(npar);
1078 for (unsigned int i = 0; i < npar; ++i) {
1079 _result->fParams[i] = (fconfig.ParSettings(i).Value());
1080 }
1081 }
1082
1083 // check for fixed or limited parameters
1084 for (unsigned int ipar = 0; ipar < npar; ++ipar) {
1085 if (fconfig.ParSettings(ipar).IsFixed())
1086 _result->fFixedParams[ipar] = true;
1087 }
1088
1089 // fill error matrix
1090 // if minimizer provides error provides also error matrix
1091 // clear in case of re-filling an existing result
1092 _result->fCovMatrix.clear();
1093 _result->fGlobalCC.clear();
1094
1095 if (min.Errors() != nullptr) {
1096 updateErrors();
1097 }
1098}
1099
1100bool RooMinimizer::update(bool isValid)
1101{
1103 ROOT::Fit::FitConfig const &fconfig = _config;
1104
1105 // update fit result with new status from minimizer
1106 // ncalls if it is not zero is used instead of value from minimizer
1107
1108 // in case minimizer changes
1109 _result->fMinimType = fconfig.MinimizerName();
1110
1111 const std::size_t npar = _result->fParams.size();
1112
1113 _result->fValid = isValid;
1114 // update minimum value
1115 _result->fVal = min.MinValue();
1116 _result->fEdm = min.Edm();
1117 _result->fStatus = min.Status();
1118 _result->fCovStatus = min.CovMatrixStatus();
1119
1120 // copy parameter value and errors
1121 std::copy(min.X(), min.X() + npar, _result->fParams.begin());
1122
1123 if (min.Errors() != nullptr) {
1124 updateErrors();
1125 }
1126 return true;
1127}
1128
1130{
1132 const std::size_t npar = _result->fParams.size();
1133
1134 _result->fErrors.resize(npar);
1135 std::copy(min.Errors(), min.Errors() + npar, _result->fErrors.begin());
1136
1137 if (_result->fCovStatus != 0) {
1138
1139 // update error matrix
1140 unsigned int r = npar * (npar + 1) / 2;
1141 _result->fCovMatrix.resize(r);
1142 unsigned int l = 0;
1143 for (unsigned int i = 0; i < npar; ++i) {
1144 for (unsigned int j = 0; j <= i; ++j)
1145 _result->fCovMatrix[l++] = min.CovMatrix(i, j);
1146 }
1147 }
1148 // minos errors are set separately when calling Fitter::CalculateMinosErrors()
1149
1150 // update global CC
1151 _result->fGlobalCC.resize(npar);
1152 for (unsigned int i = 0; i < npar; ++i) {
1153 double globcc = min.GlobalCC(i);
1154 if (globcc < 0) {
1155 _result->fGlobalCC.clear();
1156 break; // it is not supported by that minimizer
1157 }
1158 _result->fGlobalCC[i] = globcc;
1159 }
1160}
1161
1162double RooMinimizer::FitResult::lowerError(unsigned int i) const
1163{
1164 // return lower Minos error for parameter i
1165 // return the parabolic error if Minos error has not been calculated for the parameter i
1166 auto itr = fMinosErrors.find(i);
1167 return (itr != fMinosErrors.end()) ? itr->second.first : error(i);
1168}
1169
1170double RooMinimizer::FitResult::upperError(unsigned int i) const
1171{
1172 // return upper Minos error for parameter i
1173 // return the parabolic error if Minos error has not been calculated for the parameter i
1174 auto itr = fMinosErrors.find(i);
1175 return (itr != fMinosErrors.end()) ? itr->second.second : error(i);
1176}
1177
1179{
1180 return fFixedParams.find(ipar) != fFixedParams.end();
1181}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutI(a)
#define coutW(a)
#define oocoutE(o, a)
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
@ kBlue
Definition Rtypes.h:66
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition FitConfig.h:47
const std::vector< unsigned int > & MinosParams() const
return vector of parameter indices for which the Minos Error will be computed
Definition FitConfig.h:218
void SetMinimizer(const char *type, const char *algo=nullptr)
set minimizer type
Definition FitConfig.h:179
void SetMinosErrors(bool on=true)
set Minos errors computation to be performed after fitting
Definition FitConfig.h:229
const std::string & MinimizerAlgoType() const
return type of minimizer algorithms
Definition FitConfig.h:192
unsigned int NPar() const
number of parameters settings
Definition FitConfig.h:96
std::string MinimizerName() const
return Minimizer full name (type / algorithm)
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
Definition FitConfig.h:86
ROOT::Math::Minimizer * CreateMinimizer()
create a new minimizer according to chosen configuration
const std::string & MinimizerType() const
return type of minimizer package
Definition FitConfig.h:187
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
Definition FitConfig.h:76
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
Definition FitConfig.h:167
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
bool IsFixed() const
check if is fixed
void SetValue(double val)
set the value
double LowerLimit() const
return lower limit value
void SetStepSize(double err)
set the step size
double Value() const
copy constructor and assignment operators (leave them to the compiler)
double StepSize() const
return step size
double UpperLimit() const
return upper limit value
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
void SetMaxFunctionCalls(unsigned int maxfcn)
set maximum of function calls
void SetStrategy(int stra)
set the strategy
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
static const std::string & DefaultMinimizerType()
int PrintLevel() const
non-static methods for retrieving options
void SetErrorDef(double err)
set error def
void SetPrintLevel(int level)
set print level
void SetTolerance(double tol)
set the tolerance
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:119
virtual const double * Errors() const
return errors at the minimum
Definition Minimizer.h:241
virtual const double * X() const =0
return pointer to X values at the minimum
virtual double GlobalCC(unsigned int ivar) const
return global correlation coefficient for variable i This is a number between zero and one which give...
virtual int CovMatrixStatus() const
return status of covariance matrix using Minuit convention {0 not calculated 1 approximated 2 made po...
Definition Minimizer.h:251
int Status() const
status code of minimizer
Definition Minimizer.h:305
virtual double CovMatrix(unsigned int ivar, unsigned int jvar) const
return covariance matrices element for variables ivar,jvar if the variable is fixed the return value ...
virtual double Edm() const
return expected distance reached from the minimum (re-implement if minimizer provides it
Definition Minimizer.h:217
virtual double MinValue() const =0
return minimum function value
virtual unsigned int NDim() const =0
this is <= Function().NDim() which is the total number of variables (free+ constrained ones)
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:335
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
void sort(bool reverse=false)
Sort collection using std::sort and name comparison.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
void fillCorrMatrix(const std::vector< double > &globalCC, const TMatrixDSym &corrs, const TMatrixDSym &covs)
Function called by RooMinimizer.
static void setDefaultNWorkers(unsigned int N_workers)
Definition Config.cxx:67
static void setTimingAnalysis(bool timingAnalysis)
Definition Config.cxx:78
static void add_metadata(json data)
RooAbsReal that wraps RooAbsL likelihoods for use in RooFit outside of the RooMinimizer context.
Definition RooRealL.h:28
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
void setRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
int getPrintLevel()
Get the MINUIT internal printing level.
void optimizeConst(int flag)
If flag is true, perform constant term optimization on function being minimized.
void initMinimizerFirstPart()
Initialize the part of the minimizer that is independent of the function to be minimized.
std::ofstream * logfile()
int simplex()
Execute SIMPLEX.
std::unique_ptr< TMatrixDSym > _extV
void setMinimizerType(std::string const &type)
Choose the minimizer algorithm.
RooFit::OwningPtr< RooFitResult > save(const char *name=nullptr, const char *title=nullptr)
Save and return a RooFitResult snapshot of current minimizer status.
std::vector< std::pair< std::string, int > > _statusHistory
void profileStart()
Start profiling timer.
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, double n1=1.0, double n2=2.0, double n3=0.0, double n4=0.0, double n5=0.0, double n6=0.0, unsigned int npoints=50)
Create and draw a TH2 with the error contours in the parameters var1 and var2.
std::unique_ptr< ROOT::Math::Minimizer > _minimizer
! pointer to used minimizer
bool setLogFile(const char *logf=nullptr)
void initMinimizerFcnDependentPart(double defaultErrorLevel)
Initialize the part of the minimizer that is dependent on the function to be minimized.
void fillCorrMatrix(RooFitResult &fitRes)
double & fcnOffset() const
ROOT::Fit::FitConfig _config
fitter configuration (options and parameter settings)
void profileStop()
Stop profiling timer and report results of last session.
int minos()
Execute MINOS.
double & maxFCN()
bool calculateHessErrors()
int hesse()
Execute HESSE.
bool calculateMinosErrors()
void setErrorLevel(double level)
Set the level for MINUIT error analysis to the given value.
void determineStatus(bool fitterReturnValue)
int migrad()
Execute MIGRAD.
bool update(bool isValid)
int seek()
Execute SEEK.
bool updateMinimizerOptions(bool canDifferentMinim=true)
void setEps(double eps)
Change MINUIT epsilon.
void setPrintLevel(int newLevel)
Change the MINUIT internal printing level.
void fillResult(bool isValid)
int exec(std::string const &algoName, std::string const &statusName)
int improve()
Execute IMPROVE.
void setOffsetting(bool flag)
Enable internal likelihood offsetting for enhanced numeric precision.
TStopwatch _timer
RooMinimizer::Config _cfg
bool fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
std::unique_ptr< FitResult > _result
! pointer to the object containing the result of the fit
RooFit::OwningPtr< RooFitResult > lastMinuitFit()
void saveStatus(const char *label, int status)
~RooMinimizer() override
Destructor.
int minimize(const char *type, const char *alg=nullptr)
Minimise the function passed in the constructor.
ROOT::Math::IMultiGenFunction * getMultiGenFcn() const
std::unique_ptr< RooAbsReal::EvalErrorContext > makeEvalErrorContext() const
RooMinimizer(RooAbsReal &function, Config const &cfg={})
Construct MINUIT interface to given function.
void setMaxFunctionCalls(int n)
Change maximum number of likelihood function class from MINUIT (RooMinimizer default 500 * #parameter...
void setStrategy(int istrat)
Change MINUIT strategy to istrat.
int evalCounter() const
TStopwatch _cumulTimer
int getNPar() const
void setMaxIterations(int n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
void addParamsToProcessTimer()
Add parameters in metadata field to process timer.
std::unique_ptr< RooAbsMinimizerFcn > _fcn
void applyCovarianceMatrix(TMatrixDSym const &V)
Apply results of given external covariance matrix.
static RooMsgService & instance()
Return reference to singleton instance.
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:45
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition RooPlot.cxx:366
Variable that can be changed from the outside.
Definition RooRealVar.h:37
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
Manages Markers.
Definition TMarker.h:22
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:438
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:223
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const override
Print the real and cpu time passed between the start and stop events.
Basic string class.
Definition TString.h:139
const Int_t n
Definition legend1.C:16
OwningPtr< T > makeOwningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
Definition Config.h:40
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35
Definition graph.py:1
Config argument to RooMinimizer constructor.
std::string minimizerType
double upperError(unsigned int i) const
std::string fMinimType
string indicating type of minimizer
std::vector< double > fErrors
errors
std::vector< double > fParams
parameter values. Size is total number of parameters
std::map< unsigned int, bool > fFixedParams
list of fixed parameters
bool isParameterFixed(unsigned int ipar) const
double lowerError(unsigned int i) const
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4