Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MinuitFcnGrad.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl
5 *
6 * Copyright (c) 2021, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef ROOT_ROOFIT_TESTSTATISTICS_MinuitFcnGrad
14#define ROOT_ROOFIT_TESTSTATISTICS_MinuitFcnGrad
15
16#include "RooArgList.h"
17#include "RooRealVar.h"
21#include "../RooAbsMinimizerFcn.h"
22
24#include "Math/IFunction.h" // ROOT::Math::IMultiGradFunction
25
26class RooMinimizer;
27
28namespace RooFit {
29namespace TestStatistics {
30
32public:
33 MinuitFcnGrad(const std::shared_ptr<RooFit::TestStatistics::RooAbsL> &absL, RooMinimizer *context,
34 std::vector<ROOT::Fit::ParameterSettings> &parameters, LikelihoodMode likelihoodMode,
35 LikelihoodGradientMode likelihoodGradientMode);
36
37 /// Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
38 bool Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameter_settings) override;
39
40 // used inside Minuit:
41 inline bool returnsInMinuit2ParameterSpace() const { return _gradient->usesMinuitInternalValues(); }
42
43 inline void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override
44 {
45 applyToLikelihood([&](auto &l) { l.constOptimizeTestStatistic(opcode, doAlsoTrackingOpt); });
46 }
47
49
50 double operator()(const double *x) const;
51
52 /// IMultiGradFunction overrides necessary for Minuit
53 void Gradient(const double *x, double *grad) const;
54 void GradientWithPrevResult(const double *x, double *grad, double *previous_grad, double *previous_g2,
55 double *previous_gstep) const;
56
57 inline std::string getFunctionName() const override { return _likelihood->GetName(); }
58
59 inline std::string getFunctionTitle() const override { return _likelihood->GetTitle(); }
60
61 inline void setOffsetting(bool flag) override
62 {
63 applyToLikelihood([&](auto &l) { l.enableOffsetting(flag); });
64 }
65
66private:
67 bool syncParameterValuesFromMinuitCalls(const double *x, bool minuit_internal) const;
68
69 template <class Func>
70 void applyToLikelihood(Func &&func) const
71 {
72 func(*_likelihood);
75 }
76 }
77
78 // members
79 std::unique_ptr<LikelihoodWrapper> _likelihood;
80 std::unique_ptr<LikelihoodWrapper> _likelihoodInGradient;
81 std::unique_ptr<LikelihoodGradientWrapper> _gradient;
82 mutable bool _calculatingGradient = false;
83
84 mutable std::shared_ptr<WrapperCalculationCleanFlags> _calculationIsClean;
85
86 mutable std::vector<double> _minuitInternalX;
87 mutable std::vector<double> _minuitExternalX;
88
89 std::unique_ptr<ROOT::Math::IMultiGradFunction> _multiGenFcn;
90
91 mutable bool _minuitInternalRooFitXMismatch = false;
92};
93
94} // namespace TestStatistics
95} // namespace RooFit
96
97#endif // ROOT_ROOFIT_TESTSTATISTICS_MinuitFcnGrad
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Minuit-RooMinimizer interface which synchronizes parameter data and coordinates evaluation of likelih...
void GradientWithPrevResult(const double *x, double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) const
double operator()(const double *x) const
void setOffsetting(bool flag) override
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override
This function must be overridden in the derived class to pass on constant term optimization configura...
std::unique_ptr< LikelihoodWrapper > _likelihoodInGradient
bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameter_settings) override
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
std::string getFunctionName() const override
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
void Gradient(const double *x, double *grad) const
IMultiGradFunction overrides necessary for Minuit.
std::vector< double > _minuitInternalX
ROOT::Math::IMultiGenFunction * getMultiGenFcn() override
bool syncParameterValuesFromMinuitCalls(const double *x, bool minuit_internal) const
Minuit calls (via FcnAdapters etc) DoEval or Gradient with a set of parameters x.
std::unique_ptr< LikelihoodGradientWrapper > _gradient
std::string getFunctionTitle() const override
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class...
std::unique_ptr< LikelihoodWrapper > _likelihood
std::shared_ptr< WrapperCalculationCleanFlags > _calculationIsClean
std::vector< double > _minuitExternalX
void applyToLikelihood(Func &&func) const
std::unique_ptr< ROOT::Math::IMultiGradFunction > _multiGenFcn
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
TLine l
Definition textangle.C:4