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"
19
20#include "TMatrixDSym.h"
21
22#include "RooAbsReal.h"
23#include "RooArgList.h"
24#include "RooMinimizer.h"
25#include "RooRealVar.h"
26
27#include <iostream>
28#include <fstream>
29#include <string>
30#include <memory> // unique_ptr
31
33
34public:
35 RooAbsMinimizerFcn(RooArgList paramList, RooMinimizer *context);
36 virtual ~RooAbsMinimizerFcn() = default;
37
38 /// Informs Minuit through its parameter_settings vector of RooFit parameter properties.
39 bool synchronizeParameterSettings(std::vector<ROOT::Fit::ParameterSettings> &parameters, bool optConst);
40 /// Like synchronizeParameterSettings, Synchronize informs Minuit through
41 /// its parameter_settings vector of RooFit parameter properties, but
42 /// Synchronize can be overridden to e.g. also include gradient strategy
43 /// synchronization in subclasses.
44 virtual bool Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameters);
45
46 RooArgList const &allParams() const { return _allParams; }
47 RooArgList floatParams() const;
48 RooArgList constParams() const;
50 Int_t GetNumInvalidNLL() const { return _numBadNLL; }
51
52 double &GetMaxFCN() { return _maxFCN; }
53 Int_t evalCounter() const { return _evalCounter; }
55 /// Return a possible offset that's applied to the function to separate invalid function values from valid ones.
56 double &getOffset() const { return _funcOffset; }
57
58 /// Put Minuit results back into RooFit objects.
59 void BackProp();
60
61 /// RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
62 virtual std::string getFunctionName() const = 0;
63 /// RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class.
64 virtual std::string getFunctionTitle() const = 0;
65
66 /// Set different external covariance matrix
68
69 bool SetLogFile(const char *inLogfile);
70 std::ofstream *GetLogFile() { return _logfile; }
71
72 unsigned int getNDim() const { return _floatableParamIndices.size(); }
73
74 void setOptimizeConst(Int_t flag);
75
76 bool SetPdfParamVal(int index, double value) const;
77
78 /// Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
79 virtual void setOffsetting(bool flag) = 0;
81
82 RooMinimizer::Config const &cfg() const { return _context->_cfg; }
83
84 inline RooRealVar &floatableParam(std::size_t i) const
85 {
86 return static_cast<RooRealVar &>(_allParams[_floatableParamIndices[i]]);
87 }
88
89protected:
90 void optimizeConstantTerms(bool constStatChange, bool constValChange);
91 /// This function must be overridden in the derived class to pass on constant term optimization configuration
92 /// to the function to be minimized. For a RooAbsArg, this would be RooAbsArg::constOptimizeTestStatistic.
93 virtual void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) = 0;
94
95 void printEvalErrors() const;
96
97 double applyEvalErrorHandling(double fvalue) const;
98 void finishDoEval() const;
99
100 inline static bool canBeFloating(RooAbsArg const &arg) { return dynamic_cast<RooRealVar const *>(&arg); }
101
102 // Figure out whether we have to treat this parameter as a constant.
103 inline static bool treatAsConstant(RooAbsArg const &arg) { return arg.isConstant() || !canBeFloating(arg); }
104
105 // members
107
108 // the following four are mutable because DoEval is const (in child classes)
109 // Reset the *largest* negative log-likelihood value we have seen so far:
110 mutable double _maxFCN = -std::numeric_limits<double>::infinity();
111 mutable double _funcOffset{0.};
112 mutable int _numBadNLL = 0;
113 mutable int _evalCounter{0};
114 // PB: these mutables signal a suboptimal design. A separate error handling
115 // object containing all this would clean up this class. It would allow const
116 // functions to be actually const (even though state still changes in the
117 // error handling object).
118
119 bool _optConst = false;
120
123
124 std::vector<std::size_t> _floatableParamIndices;
125
126 std::ofstream *_logfile = nullptr;
127};
128
129#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
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
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
std::vector< std::size_t > _floatableParamIndices
std::ofstream * GetLogFile()
void setOptimizeConst(Int_t flag)
static bool canBeFloating(RooAbsArg const &arg)
static bool treatAsConstant(RooAbsArg const &arg)
bool SetLogFile(const char *inLogfile)
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter spac...
RooArgList const & allParams() const
Int_t GetNumInvalidNLL() const
virtual bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameters)
Like synchronizeParameterSettings, Synchronize informs Minuit through its parameter_settings vector o...
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
RooArgList constParams() const
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.
virtual std::string getFunctionTitle() const =0
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class...
std::ofstream * _logfile
virtual ROOT::Math::IMultiGenFunction * getMultiGenFcn()=0
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.
RooArgList initFloatParams() const
double & getOffset() const
Return a possible offset that's applied to the function to separate invalid function values from vali...
RooRealVar & floatableParam(std::size_t i) const
void BackProp()
Put Minuit results back into RooFit objects.
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 floatParams() const
unsigned int getNDim() const
Int_t evalCounter() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
RooMinimizer::Config _cfg
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Config argument to RooMinimizer constructor.