Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RooAbsMinimizerFcn.h
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*****************************************************************************
4 * Project: RooFit *
5 * Package: RooFitCore *
6 * @(#)root/roofitcore:$Id$
7 * Authors: *
8 * AL, Alfio Lazzaro, INFN Milan, alfio.lazzaro@mi.infn.it *
9 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl *
10 * *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROO_ABS_MINIMIZER_FCN
18#define ROO_ABS_MINIMIZER_FCN
19
20#include "Math/IFunction.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 <iostream>
30#include <fstream>
31#include <string>
32#include <memory> // unique_ptr
33
35
36public:
37 RooAbsMinimizerFcn(RooArgList paramList, RooMinimizer *context);
38 virtual ~RooAbsMinimizerFcn() = default;
39
40 /// Informs Minuit through its parameter_settings vector of RooFit parameter properties.
41 bool synchronizeParameterSettings(std::vector<ROOT::Fit::ParameterSettings> &parameters, bool optConst);
42 /// Like synchronizeParameterSettings, Synchronize informs Minuit through
43 /// its parameter_settings vector of RooFit parameter properties, but
44 /// Synchronize can be overridden to e.g. also include gradient strategy
45 /// synchronization in subclasses.
46 virtual bool Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameters);
47
48 RooArgList const &allParams() const { return _allParams; }
49 RooArgList floatParams() const;
50 RooArgList constParams() const;
52 Int_t GetNumInvalidNLL() const { return _numBadNLL; }
53
54 double &GetMaxFCN() { return _maxFCN; }
55 Int_t evalCounter() const { return _evalCounter; }
56 void zeroEvalCount() { _evalCounter = 0; }
57 /// Return a possible offset that's applied to the function to separate invalid function values from valid ones.
58 double &getOffset() const { return _funcOffset; }
59
60 /// Put Minuit results back into RooFit objects.
61 void BackProp();
62
63 /// RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
64 virtual std::string getFunctionName() const = 0;
65 /// RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class.
66 virtual std::string getFunctionTitle() const = 0;
67
68 /// Set different external covariance matrix
70
71 bool SetLogFile(const char *inLogfile);
72 std::ofstream *GetLogFile() { return _logfile; }
73
74 unsigned int getNDim() const { return _floatableParamIndices.size(); }
75
77
78 bool SetPdfParamVal(int index, double value) const;
79
80 /// Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
81 virtual void setOffsetting(bool flag) = 0;
82 virtual ROOT::Math::IMultiGenFunction *getMultiGenFcn() = 0;
83
84 RooMinimizer::Config const &cfg() const { return _context->_cfg; }
85
86 inline RooRealVar &floatableParam(std::size_t i) const
87 {
88 return static_cast<RooRealVar &>(_allParams[_floatableParamIndices[i]]);
89 }
90
91protected:
93 /// This function must be overridden in the derived class to pass on constant term optimization configuration
94 /// to the function to be minimized. For a RooAbsArg, this would be RooAbsArg::constOptimizeTestStatistic.
95 virtual void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) = 0;
96
97 void printEvalErrors() const;
98
99 double applyEvalErrorHandling(double fvalue) const;
100 void finishDoEval() const;
101
102 inline static bool canBeFloating(RooAbsArg const &arg) { return dynamic_cast<RooRealVar const *>(&arg); }
103
104 // Figure out whether we have to treat this parameter as a constant.
105 inline static bool treatAsConstant(RooAbsArg const &arg) { return arg.isConstant() || !canBeFloating(arg); }
106
107 // members
108 RooMinimizer *_context = nullptr;
109
110 // the following four are mutable because DoEval is const (in child classes)
111 // Reset the *largest* negative log-likelihood value we have seen so far:
112 mutable double _maxFCN = -std::numeric_limits<double>::infinity();
113 mutable double _funcOffset{0.};
114 mutable int _numBadNLL = 0;
115 mutable int _evalCounter{0};
116 // PB: these mutables signal a suboptimal design. A separate error handling
117 // object containing all this would clean up this class. It would allow const
118 // functions to be actually const (even though state still changes in the
119 // error handling object).
120
121 bool _optConst = false;
122
125
126 std::vector<std::size_t> _floatableParamIndices;
127
128 std::ofstream *_logfile = nullptr;
129};
130
131#endif
132
133/// \endcond
int Int_t
Definition RtypesCore.h:45
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:63
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
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...
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Config argument to RooMinimizer constructor.