Logo ROOT  
Reference Guide
 
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 <Math/Minimizer.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);
40 virtual ~RooAbsMinimizerFcn() = default;
41
42 virtual void initMinimizer(ROOT::Math::Minimizer &, RooMinimizer *context) = 0;
43
44 /// Informs Minuit through its parameter_settings vector of RooFit parameter properties.
45 bool synchronizeParameterSettings(std::vector<ROOT::Fit::ParameterSettings> &parameters);
46 /// Like synchronizeParameterSettings, Synchronize informs Minuit through
47 /// its parameter_settings vector of RooFit parameter properties, but
48 /// Synchronize can be overridden to e.g. also include gradient strategy
49 /// synchronization in subclasses.
50 virtual bool Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameters);
51
52 RooArgList const &allParams() const { return _allParams; }
53 RooArgList floatParams() const;
54 RooArgList constParams() const;
56 Int_t GetNumInvalidNLL() const { return _numBadNLL; }
57
58 double &GetMaxFCN() { return _maxFCN; }
59 Int_t evalCounter() const { return _evalCounter; }
60 void zeroEvalCount() { _evalCounter = 0; }
61 /// Return a possible offset that's applied to the function to separate invalid function values from valid ones.
62 double &getOffset() const { return _funcOffset; }
63
64 /// Put Minuit results back into RooFit objects.
65 void BackProp();
66
67 /// RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
68 virtual std::string getFunctionName() const = 0;
69 /// RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class.
70 virtual std::string getFunctionTitle() const = 0;
71
72 /// Set different external covariance matrix
74
75 bool SetLogFile(const char *inLogfile);
76 std::ofstream *GetLogFile() { return _logfile; }
77
78 unsigned int getNDim() const { return _floatableParamIndices.size(); }
79
80 bool SetPdfParamVal(int index, double value) const;
81
82 /// Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
83 virtual void setOffsetting(bool flag) = 0;
84
85 RooMinimizer::Config const &cfg() const { return _context->_cfg; }
86
87 inline RooRealVar &floatableParam(std::size_t i) const
88 {
89 return static_cast<RooRealVar &>(_allParams[_floatableParamIndices[i]]);
90 }
91
92 virtual RooArgSet freezeDisconnectedParameters() const { return {}; }
93
94protected:
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
106 RooMinimizer *_context = nullptr;
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
121
122 std::vector<std::size_t> _floatableParamIndices;
123
124 std::ofstream *_logfile = nullptr;
125};
126
127#endif
128
129/// \endcond
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
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
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:124
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:283
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
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.