Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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.
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 function
80 // was renamed to match the code convention (lower case for function 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
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;
94
95 RooMinimizer::Config const &cfg() const { return _context->_cfg; }
96
97protected:
99 /// This function must be overridden in the derived class to pass on constant term optimization configuration
100 /// to the function to be minimized. For a RooAbsArg, this would be RooAbsArg::constOptimizeTestStatistic.
102
103 // used in BackProp (Minuit results -> RooFit) and ApplyCovarianceMatrix
104 void SetPdfParamErr(Int_t index, double value);
106 void SetPdfParamErr(Int_t index, double loVal, double hiVal);
107
108 void printEvalErrors() const;
109
110 double applyEvalErrorHandling(double fvalue) const;
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 // PB: these mutables signal a suboptimal design. A separate error handling
123 // object containing all this would clean up this class. It would allow const
124 // functions to be actually const (even though state still changes in the
125 // error handling object).
126
127 unsigned int _nDim = 0;
128
129 bool _optConst = false;
130
131 std::unique_ptr<RooArgList> _floatParamList;
132 std::unique_ptr<RooArgList> _constParamList;
133 std::unique_ptr<RooArgList> _initFloatParamList;
134 std::unique_ptr<RooArgList> _initConstParamList;
135
136 std::ofstream *_logfile = nullptr;
137};
138
139#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
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
RooArgList * GetInitFloatParamList()
std::ofstream * GetLogFile()
void setOptimizeConst(Int_t flag)
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()
double applyEvalErrorHandling(double fvalue) const
Apply corrections on the fvalue if errors were signaled.
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
RooArgList * GetFloatParamList()
double & getOffset() const
Return a possible offset that's applied to the function to separate invalid function values from vali...
unsigned int NDim() const
std::unique_ptr< RooArgList > _constParamList
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
Wrapper class around ROOT::Fit:Fitter that provides a seamless interface between the minimizer functi...
RooMinimizer::Config _cfg
Config argument to RooMinimizer constructor.