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 RooArgList floatParams = _fcn->floatParams();
408 for (RooAbsArg *arg : minosParamList) {
409 RooAbsArg *par = floatParams.find(arg->GetName());
410 if (par && !par->isConstant()) {
411 int index = floatParams.index(par);
412 paramInd.push_back(index);
413 }
414 }
415
416 if (!paramInd.empty()) {
417 // set the parameter indices
418 _config.SetMinosErrors(paramInd);
419
421 bool ret = calculateMinosErrors();
422 determineStatus(ret);
423 // to avoid that following minimization computes automatically the Minos errors
424 _config.SetMinosErrors(false);
425 }
426 }
427 profileStop();
428 _fcn->BackProp();
429
430 saveStatus("MINOS", _status);
431 }
432
433 return _status;
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Execute SEEK. Changes in parameter values
438/// and calculated errors are automatically
439/// propagated back the RooRealVars representing
440/// the floating parameters in the MINUIT operation.
441
443{
444 return exec("seek", "SEEK");
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// Execute SIMPLEX. Changes in parameter values
449/// and calculated errors are automatically
450/// propagated back the RooRealVars representing
451/// the floating parameters in the MINUIT operation.
452
454{
455 return exec("simplex", "SIMPLEX");
456}
457
458////////////////////////////////////////////////////////////////////////////////
459/// Execute IMPROVE. Changes in parameter values
460/// and calculated errors are automatically
461/// propagated back the RooRealVars representing
462/// the floating parameters in the MINUIT operation.
463
465{
466 return exec("migradimproved", "IMPROVE");
467}
468
469////////////////////////////////////////////////////////////////////////////////
470/// Change the MINUIT internal printing level
471
473{
474 _config.MinimizerOptions().SetPrintLevel(newLevel + 1);
475}
476
477////////////////////////////////////////////////////////////////////////////////
478/// Get the MINUIT internal printing level
479
481{
482 return _config.MinimizerOptions().PrintLevel() + 1;
483}
484
485////////////////////////////////////////////////////////////////////////////////
486/// If flag is true, perform constant term optimization on
487/// function being minimized.
488
490{
491 _fcn->setOptimizeConst(flag);
492}
493
494////////////////////////////////////////////////////////////////////////////////
495/// Save and return a RooFitResult snapshot of current minimizer status.
496/// This snapshot contains the values of all constant parameters,
497/// the value of all floating parameters at RooMinimizer construction and
498/// after the last MINUIT operation, the MINUIT status, variance quality,
499/// EDM setting, number of calls with evaluation problems, the minimized
500/// function value and the full correlation matrix.
501
502RooFit::OwningPtr<RooFitResult> RooMinimizer::save(const char *userName, const char *userTitle)
503{
504 if (_minimizer == nullptr) {
505 coutW(Minimization) << "RooMinimizer::save: Error, run minimization before!" << std::endl;
506 return nullptr;
507 }
508
509 TString name = userName ? userName : Form("%s", _fcn->getFunctionName().c_str());
510 TString title = userTitle ? userTitle : Form("%s", _fcn->getFunctionTitle().c_str());
511 auto fitRes = std::make_unique<RooFitResult>(name, title);
512
513 fitRes->setConstParList(_fcn->constParams());
514
515 double removeOffset = 0.;
516 fitRes->setNumInvalidNLL(_fcn->GetNumInvalidNLL());
517 removeOffset = -_fcn->getOffset();
518
519 fitRes->setStatus(_status);
520 fitRes->setCovQual(_minimizer->CovMatrixStatus());
521 fitRes->setMinNLL(_result->fVal + removeOffset);
522 fitRes->setEDM(_result->fEdm);
523
524 fitRes->setInitParList(_fcn->initFloatParams());
525 fitRes->setFinalParList(_fcn->floatParams());
526
527 if (!_extV) {
528 fillCorrMatrix(*fitRes);
529 } else {
530 fitRes->setCovarianceMatrix(*_extV);
531 }
532
533 fitRes->setStatusHistory(_statusHistory);
534
535 return RooFit::makeOwningPtr(std::move(fitRes));
536}
537
538namespace {
539
540/// retrieve covariance matrix element
541double covMatrix(std::vector<double> const &covMat, unsigned int i, unsigned int j)
542{
543 if (covMat.empty())
544 return 0; // no matrix is available in case of non-valid fits
545 return j < i ? covMat[j + i * (i + 1) / 2] : covMat[i + j * (j + 1) / 2];
546}
547
548/// retrieve correlation elements
549double correlation(std::vector<double> const &covMat, unsigned int i, unsigned int j)
550{
551 if (covMat.empty())
552 return 0; // no matrix is available in case of non-valid fits
553 double tmp = covMatrix(covMat, i, i) * covMatrix(covMat, j, j);
554 return tmp > 0 ? covMatrix(covMat, i, j) / std::sqrt(tmp) : 0;
555}
556
557} // namespace
558
560{
561 const std::size_t nParams = _fcn->getNDim();
562 std::vector<double> globalCC;
563 TMatrixDSym corrs(nParams);
564 TMatrixDSym covs(nParams);
565 for (std::size_t ic = 0; ic < nParams; ic++) {
566 globalCC.push_back(_result->fGlobalCC[ic]);
567 for (std::size_t ii = 0; ii < nParams; ii++) {
568 corrs(ic, ii) = correlation(_result->fCovMatrix, ic, ii);
569 covs(ic, ii) = covMatrix(_result->fCovMatrix, ic, ii);
570 }
571 }
572 fitRes.fillCorrMatrix(globalCC, corrs, covs);
573}
574
575////////////////////////////////////////////////////////////////////////////////
576/// Create and draw a TH2 with the error contours in the parameters `var1` and `var2`.
577/// \param[in] var1 The first parameter (x axis).
578/// \param[in] var2 The second parameter (y axis).
579/// \param[in] n1 First contour.
580/// \param[in] n2 Optional contour. 0 means don't draw.
581/// \param[in] n3 Optional contour. 0 means don't draw.
582/// \param[in] n4 Optional contour. 0 means don't draw.
583/// \param[in] n5 Optional contour. 0 means don't draw.
584/// \param[in] n6 Optional contour. 0 means don't draw.
585/// \param[in] npoints Number of points for evaluating the contour.
586///
587/// Up to six contours can be drawn using the arguments `n1` to `n6` to request the desired
588/// coverage in units of \f$ \sigma = n^2 \cdot \mathrm{ErrorDef} \f$.
589/// See ROOT::Math::Minimizer::ErrorDef().
590
591RooPlot *RooMinimizer::contour(RooRealVar &var1, RooRealVar &var2, double n1, double n2, double n3, double n4,
592 double n5, double n6, unsigned int npoints)
593{
594 RooArgList params = _fcn->floatParams();
595 RooArgList paramSave;
596 params.snapshot(paramSave);
597
598 // Verify that both variables are floating parameters of PDF
599 int index1 = params.index(&var1);
600 if (index1 < 0) {
601 coutE(Minimization) << "RooMinimizer::contour(" << GetName() << ") ERROR: " << var1.GetName()
602 << " is not a floating parameter of " << _fcn->getFunctionName() << std::endl;
603 return nullptr;
604 }
605
606 int index2 = params.index(&var2);
607 if (index2 < 0) {
608 coutE(Minimization) << "RooMinimizer::contour(" << GetName() << ") ERROR: " << var2.GetName()
609 << " is not a floating parameter of PDF " << _fcn->getFunctionName() << std::endl;
610 return nullptr;
611 }
612
613 // create and draw a frame
614 RooPlot *frame = new RooPlot(var1, var2);
615
616 // draw a point at the current parameter values
617 TMarker *point = new TMarker(var1.getVal(), var2.getVal(), 8);
618 frame->addObject(point);
619
620 // check first if a inimizer is available. If not means
621 // the minimization is not done , so do it
622 if (_minimizer == nullptr) {
623 coutW(Minimization) << "RooMinimizer::contour: Error, run Migrad before contours!" << std::endl;
624 return frame;
625 }
626
627 // remember our original value of ERRDEF
628 double errdef = _minimizer->ErrorDef();
629
630 double n[6];
631 n[0] = n1;
632 n[1] = n2;
633 n[2] = n3;
634 n[3] = n4;
635 n[4] = n5;
636 n[5] = n6;
637
638 for (int ic = 0; ic < 6; ic++) {
639 if (n[ic] > 0) {
640
641 // set the value corresponding to an n1-sigma contour
642 _minimizer->SetErrorDef(n[ic] * n[ic] * errdef);
643
644 // calculate and draw the contour
645 std::vector<double> xcoor(npoints + 1);
646 std::vector<double> ycoor(npoints + 1);
647 bool ret = _minimizer->Contour(index1, index2, npoints, xcoor.data(), ycoor.data());
648
649 if (!ret) {
650 coutE(Minimization) << "RooMinimizer::contour(" << GetName()
651 << ") ERROR: MINUIT did not return a contour graph for n=" << n[ic] << std::endl;
652 } else {
653 xcoor[npoints] = xcoor[0];
654 ycoor[npoints] = ycoor[0];
655 TGraph *graph = new TGraph(npoints + 1, xcoor.data(), ycoor.data());
656
657 graph->SetName(Form("contour_%s_n%f", _fcn->getFunctionName().c_str(), n[ic]));
658 graph->SetLineStyle(ic + 1);
659 graph->SetLineWidth(2);
660 graph->SetLineColor(kBlue);
661 frame->addObject(graph, "L");
662 }
663 }
664 }
665
666 // restore the original ERRDEF
667 _minimizer->SetErrorDef(errdef);
668
669 // restore parameter values
670 params.assign(paramSave);
671
672 return frame;
673}
674
675////////////////////////////////////////////////////////////////////////////////
676/// Add parameters in metadata field to process timer
677
679{
680#ifdef ROOFIT_MULTIPROCESS
681 // parameter indices for use in timing heat matrix
682 std::vector<std::string> parameter_names;
683 for (RooAbsArg *parameter : _fcn->floatParams()) {
684 parameter_names.push_back(parameter->GetName());
685 if (_cfg.verbose) {
686 coutI(Minimization) << "parameter name: " << parameter_names.back() << std::endl;
687 }
688 }
690#else
691 coutI(Minimization) << "Not adding parameters to processtimer because multiprocessing is not enabled." << std::endl;
692#endif
693}
694
695////////////////////////////////////////////////////////////////////////////////
696/// Start profiling timer
697
699{
700 if (_cfg.profile) {
701 _timer.Start();
702 _cumulTimer.Start(_profileStart ? false : true);
703 _profileStart = true;
704 }
705}
706
707////////////////////////////////////////////////////////////////////////////////
708/// Stop profiling timer and report results of last session
709
711{
712 if (_cfg.profile) {
713 _timer.Stop();
715 coutI(Minimization) << "Command timer: ";
716 _timer.Print();
717 coutI(Minimization) << "Session timer: ";
719 }
720}
721
723{
724 return _fcn->getMultiGenFcn();
725}
726
727////////////////////////////////////////////////////////////////////////////////
728/// Apply results of given external covariance matrix. i.e. propagate its errors
729/// to all RRV parameter representations and give this matrix instead of the
730/// HESSE matrix at the next save() call
731
733{
734 _extV.reset(static_cast<TMatrixDSym *>(V.Clone()));
735 _fcn->ApplyCovarianceMatrix(*_extV);
736}
737
739{
740 // Import the results of the last fit performed, interpreting
741 // the fit parameters as the given varList of parameters.
742
743 if (_minimizer == nullptr) {
744 oocoutE(nullptr, InputArguments) << "RooMinimizer::save: Error, run minimization before!" << std::endl;
745 return nullptr;
746 }
747
748 auto res = std::make_unique<RooFitResult>("lastMinuitFit", "Last MINUIT fit");
749
750 // Extract names of fit parameters
751 // and construct corresponding RooRealVars
752 RooArgList constPars("constPars");
753 RooArgList floatPars("floatPars");
754
755 const RooArgList floatParsFromFcn = _fcn->floatParams();
756
757 for (unsigned int i = 0; i < _fcn->getNDim(); ++i) {
758
759 TString varName(floatParsFromFcn.at(i)->GetName());
760 bool isConst(_result->isParameterFixed(i));
761
762 double xlo = _config.ParSettings(i).LowerLimit();
763 double xhi = _config.ParSettings(i).UpperLimit();
764 double xerr = _result->error(i);
765 double xval = _result->fParams[i];
766
767 std::unique_ptr<RooRealVar> var;
768
769 if ((xlo < xhi) && !isConst) {
770 var = std::make_unique<RooRealVar>(varName, varName, xval, xlo, xhi);
771 } else {
772 var = std::make_unique<RooRealVar>(varName, varName, xval);
773 }
774 var->setConstant(isConst);
775
776 if (isConst) {
777 constPars.addOwned(std::move(var));
778 } else {
779 var->setError(xerr);
780 floatPars.addOwned(std::move(var));
781 }
782 }
783
784 res->setConstParList(constPars);
785 res->setInitParList(floatPars);
786 res->setFinalParList(floatPars);
787 res->setMinNLL(_result->fVal);
788 res->setEDM(_result->fEdm);
789 res->setCovQual(_minimizer->CovMatrixStatus());
790 res->setStatus(_result->fStatus);
791 fillCorrMatrix(*res);
792
793 return RooFit::makeOwningPtr(std::move(res));
794}
795
796/// Try to recover from invalid function values. When invalid function values
797/// are encountered, a penalty term is returned to the minimiser to make it
798/// back off. This sets the strength of this penalty. \note A strength of zero
799/// is equivalent to a constant penalty (= the gradient vanishes, ROOT < 6.24).
800/// Positive values lead to a gradient pointing away from the undefined
801/// regions. Use ~10 to force the minimiser away from invalid function values.
803{
804 _cfg.recoverFromNaN = strength;
805}
806
807bool RooMinimizer::setLogFile(const char *logf)
808{
809 _cfg.logf = logf;
810 return _cfg.logf ? _fcn->SetLogFile(_cfg.logf) : false;
811}
812
814{
815 return _fcn->evalCounter();
816}
818{
819 _fcn->zeroEvalCount();
820}
821
823{
824 return _fcn->getNDim();
825}
826
827std::ofstream *RooMinimizer::logfile()
828{
829 return _fcn->GetLogFile();
830}
832{
833 return _fcn->GetMaxFCN();
834}
836{
837 return _fcn->getOffset();
838}
839
840std::unique_ptr<RooAbsReal::EvalErrorContext> RooMinimizer::makeEvalErrorContext() const
841{
843 // If evaluation error printing is disabled, we don't need to collect the
844 // errors and only need to count them. This significantly reduces the
845 // performance overhead when having evaluation errors.
847 return std::make_unique<RooAbsReal::EvalErrorContext>(m);
848}
849
851{
852 // fit a user provided FCN function
853 // create fit parameter settings
854 unsigned int npar = fcn.NDim();
855 if (npar == 0) {
856 coutE(Minimization) << "RooMinimizer::fitFCN(): FCN function has zero parameters" << std::endl;
857 return false;
858 }
859
860 // init the minimizer
862 // perform the minimization
863
864 // perform the minimization (assume we have already initialized the minimizer)
865
866 bool isValid = _minimizer->Minimize();
867
868 if (!_result)
869 _result = std::make_unique<FitResult>();
870
871 fillResult(isValid);
872
873 // set also new parameter values and errors in FitConfig
874 if (isValid)
876
877 return isValid;
878}
879
881{
882 // compute the Hesse errors according to configuration
883 // set in the parameters and append value in fit result
884
885 // update minimizer (recreate if not done or if name has changed
886 if (!updateMinimizerOptions()) {
887 coutE(Minimization) << "RooMinimizer::calculateHessErrors() Error re-initializing the minimizer" << std::endl;
888 return false;
889 }
890
891 // run Hesse
892 bool ret = _minimizer->Hesse();
893 if (!ret)
894 coutE(Minimization) << "RooMinimizer::calculateHessErrors() Error when calculating Hessian" << std::endl;
895
896 // update minimizer results with what comes out from Hesse
897 // in case is empty - create from a FitConfig
898 if (_result->fParams.empty())
899 _result = std::make_unique<FitResult>(_config);
900
901 // re-give a minimizer instance in case it has been changed
902 ret |= update(ret);
903
904 // set also new errors in FitConfig
905 if (ret)
907
908 return ret;
909}
910
912{
913 // compute the Minos errors according to configuration
914 // set in the parameters and append value in fit result
915 // normally Minos errors are computed just after the minimization
916 // (in DoMinimization) aftewr minimizing if the
917 // FitConfig::MinosErrors() flag is set
918
919 // update minimizer (but cannot re-create in this case). Must use an existing one
920 if (!updateMinimizerOptions(false)) {
921 coutE(Minimization) << "RooMinimizer::calculateHessErrors() Error re-initializing the minimizer" << std::endl;
922 return false;
923 }
924
925 const std::vector<unsigned int> &ipars = _config.MinosParams();
926 unsigned int n = (!ipars.empty()) ? ipars.size() : _fcn->getNDim();
927 bool ok = false;
928
929 int iparNewMin = 0;
930 int iparMax = n;
931 int iter = 0;
932 // rerun minos for the parameters run before a new Minimum has been found
933 do {
934 if (iparNewMin > 0)
935 coutI(Minimization) << "RooMinimizer::calculateMinosErrors() Run again Minos for some parameters because a "
936 "new Minimum has been found"
937 << std::endl;
938 iparNewMin = 0;
939 for (int i = 0; i < iparMax; ++i) {
940 double elow, eup;
941 unsigned int index = (!ipars.empty()) ? ipars[i] : i;
942 bool ret = _minimizer->GetMinosError(index, elow, eup);
943 // flags case when a new minimum has been found
944 if ((_minimizer->MinosStatus() & 8) != 0) {
945 iparNewMin = i;
946 }
947 if (ret)
948 _result->fMinosErrors.emplace(index, std::make_pair(elow, eup));
949 ok |= ret;
950 }
951
952 iparMax = iparNewMin;
953 iter++; // to avoid infinite looping
954 } while (iparNewMin > 0 && iter < 10);
955 if (!ok) {
956 coutE(Minimization)
957 << "RooMinimizer::calculateMinosErrors() Minos error calculation failed for all the selected parameters"
958 << std::endl;
959 }
960
961 // re-give a minimizer instance in case it has been changed
962 // but maintain previous valid status. Do not set result to false if minos failed
963 ok &= update(_result->fValid);
964
965 return ok;
966}
967
969{
970 _minimizer = std::unique_ptr<ROOT::Math::Minimizer>(_config.CreateMinimizer());
971 _minimizer->SetFunction(*getMultiGenFcn());
972 _minimizer->SetVariables(_config.ParamsSettings().begin(), _config.ParamsSettings().end());
973
975 std::vector<double> v;
976 for (std::size_t i = 0; i < _fcn->getNDim(); ++i) {
977 RooRealVar &param = _fcn->floatableParam(i);
978 v.push_back(param.getError() * param.getError());
979 }
980 _minimizer->SetCovarianceDiag(v, v.size());
981 }
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}
1182
1184{
1185 const size_t nParams = fParams.size();
1186 covs.ResizeTo(nParams, nParams);
1187 for (std::size_t ic = 0; ic < nParams; ic++) {
1188 for (std::size_t ii = 0; ii < nParams; ii++) {
1189 covs(ic, ii) = covMatrix(fCovMatrix, ic, ii);
1190 }
1191 }
1192}
#define coutI(a)
#define coutW(a)
#define oocoutE(o, a)
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:382
@ 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
return parameter value
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:246
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:256
int Status() const
status code of minimizer
Definition Minimizer.h:310
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:222
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:77
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:304
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
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.
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
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
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:43
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition RooPlot.cxx:326
Variable that can be changed from the outside.
Definition RooRealVar.h:37
double getError() const
Definition RooRealVar.h:58
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
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
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:456
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:241
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
void GetCovarianceMatrix(TMatrixDSym &cov) const
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