Logo ROOT  
Reference Guide
RooAbsMinimizerFcn.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * AL, Alfio Lazzaro, INFN Milan, alfio.lazzaro@mi.infn.it *
7 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl *
8 * *
9 * *
10 * Redistribution and use in source and binary forms, *
11 * with or without modification, are permitted according to the terms *
12 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
13 *****************************************************************************/
14
15#ifndef ROO_ABS_MINIMIZER_FCN
16#define ROO_ABS_MINIMIZER_FCN
17
18#include "Math/IFunction.h"
20#include "Fit/FitResult.h"
21
22#include "TMatrixDSym.h"
23
24#include "RooAbsReal.h"
25#include "RooArgList.h"
26#include "RooMinimizer.h"
27#include "RooRealVar.h"
28
29#include <Fit/Fitter.h>
30
31#include <iostream>
32#include <fstream>
33#include <string>
34#include <memory> // unique_ptr
35
37
38public:
39 RooAbsMinimizerFcn(RooArgList paramList, RooMinimizer *context);
41 virtual ~RooAbsMinimizerFcn() = default;
42
43 /// Informs Minuit through its parameter_settings vector of RooFit parameter properties.
44 bool synchronizeParameterSettings(std::vector<ROOT::Fit::ParameterSettings> &parameters, bool optConst);
45 /// Like synchronizeParameterSettings, Synchronize informs Minuit through
46 /// its parameter_settings vector of RooFit parameter properties, but
47 /// Synchronize can be overridden to e.g. also include gradient strategy
48 /// synchronization in subclasses.
49 virtual bool Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameters);
50
55 Int_t GetNumInvalidNLL() const { return _numBadNLL; }
56
57 double &GetMaxFCN() { return _maxFCN; }
58 Int_t evalCounter() const { return _evalCounter; }
60 /// Return a possible offset that's applied to the function to separate invalid function values from valid ones.
61 double getOffset() const { return _funcOffset; }
62
63 /// Put Minuit results back into RooFit objects.
64 void BackProp(const ROOT::Fit::FitResult &results);
65
66 /// RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
67 virtual std::string getFunctionName() const = 0;
68 /// RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class.
69 virtual std::string getFunctionTitle() const = 0;
70
71 /// Set different external covariance matrix
73
74 bool SetLogFile(const char *inLogfile);
75 std::ofstream *GetLogFile() { return _logfile; }
76
77 unsigned int getNDim() const { return _nDim; }
78
79 // In the past, the `getNDim` function was called just `NDim`. The funciton
80 // was renamed to match the code convention (lower case for funciton names),
81 // but we have to keep an overload with the old name to not break existing
82 // user code.
83 inline unsigned int NDim() const { return getNDim(); }
84
85 void setOptimizeConst(Int_t flag);
86
87 std::vector<double> getParameterValues() const;
88
89 bool SetPdfParamVal(int index, double value) const;
90
91 /// Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
92 virtual void setOffsetting(bool flag) = 0;
93 virtual bool fit(ROOT::Fit::Fitter &) const = 0;
95
96 RooMinimizer::Config const &cfg() const { return _context->_cfg; }
97
98protected:
99 void optimizeConstantTerms(bool constStatChange, bool constValChange);
100 /// This function must be overridden in the derived class to pass on constant term optimization configuration
101 /// to the function to be minimized. For a RooAbsArg, this would be RooAbsArg::constOptimizeTestStatistic.
102 virtual void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) = 0;
103
104 // used in BackProp (Minuit results -> RooFit) and ApplyCovarianceMatrix
105 void SetPdfParamErr(Int_t index, double value);
107 void SetPdfParamErr(Int_t index, double loVal, double hiVal);
108
109 void printEvalErrors() const;
110
111 void finishDoEval() const;
112
113 // members
115
116 // the following four are mutable because DoEval is const (in child classes)
117 // Reset the *largest* negative log-likelihood value we have seen so far:
118 mutable double _maxFCN = -std::numeric_limits<double>::infinity();
119 mutable double _funcOffset{0.};
120 mutable int _numBadNLL = 0;
121 mutable int _evalCounter{0};
122
123 unsigned int _nDim = 0;
124
125 bool _optConst = false;
126
127 std::unique_ptr<RooArgList> _floatParamList;
128 std::unique_ptr<RooArgList> _constParamList;
129 std::unique_ptr<RooArgList> _initFloatParamList;
130 std::unique_ptr<RooArgList> _initConstParamList;
131
132 std::ofstream *_logfile = nullptr;
133};
134
135#endif
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 value
class containing the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:47
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
RooArgList * GetInitFloatParamList()
std::ofstream * GetLogFile()
void setOptimizeConst(Int_t flag)
RooMinimizer * _context
std::unique_ptr< RooArgList > _floatParamList
bool SetLogFile(const char *inLogfile)
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter spac...
Int_t GetNumInvalidNLL() const
RooAbsMinimizerFcn(RooArgList paramList, RooMinimizer *context)
virtual bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameters)
Like synchronizeParameterSettings, Synchronize informs Minuit through its parameter_settings vector o...
RooArgList * GetConstParamList()
virtual void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt)=0
This function must be overridden in the derived class to pass on constant term optimization configura...
virtual ~RooAbsMinimizerFcn()=default
void BackProp(const ROOT::Fit::FitResult &results)
Put Minuit results back into RooFit objects.
RooMinimizer::Config const & cfg() const
virtual std::string getFunctionName() const =0
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
void optimizeConstantTerms(bool constStatChange, bool constValChange)
void printEvalErrors() const
Print information about why evaluation failed.
void ClearPdfParamAsymErr(Int_t index)
Modify PDF parameter error by ordinal index (needed by MINUIT)
virtual std::string getFunctionTitle() const =0
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class...
std::vector< double > getParameterValues() const
std::ofstream * _logfile
virtual ROOT::Math::IMultiGenFunction * getMultiGenFcn()=0
void SetPdfParamErr(Int_t index, double value)
Modify PDF parameter error by ordinal index (needed by MINUIT)
bool synchronizeParameterSettings(std::vector< ROOT::Fit::ParameterSettings > &parameters, bool optConst)
Informs Minuit through its parameter_settings vector of RooFit parameter properties.
void ApplyCovarianceMatrix(TMatrixDSym &V)
Set different external covariance matrix.
std::unique_ptr< RooArgList > _initConstParamList
double getOffset() const
Return a possible offset that's applied to the function to separate invalid function values from vali...
RooArgList * GetFloatParamList()
unsigned int NDim() const
std::unique_ptr< RooArgList > _constParamList
virtual bool fit(ROOT::Fit::Fitter &) const =0
virtual void setOffsetting(bool flag)=0
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
bool SetPdfParamVal(int index, double value) const
Set value of parameter i.
RooArgList * GetInitConstParamList()
unsigned int getNDim() const
std::unique_ptr< RooArgList > _initFloatParamList
Int_t evalCounter() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:43
RooMinimizer::Config _cfg
Definition: RooMinimizer.h:172
Config argument to RooMinimizer ctor.
Definition: RooMinimizer.h:46