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 <Fit/Fitter.h>
25#include "Math/IFunction.h" // ROOT::Math::IMultiGradFunction
26
27// forward declaration
28class RooAbsReal;
29class RooMinimizer;
30
31namespace RooFit {
32namespace TestStatistics {
33
35public:
36 MinuitFcnGrad(const std::shared_ptr<RooFit::TestStatistics::RooAbsL> &_likelihood, RooMinimizer *context,
37 std::vector<ROOT::Fit::ParameterSettings> &parameters, LikelihoodMode likelihoodMode,
38 LikelihoodGradientMode likelihoodGradientMode, bool verbose = false);
39
40 inline ROOT::Math::IMultiGradFunction *Clone() const override { return new MinuitFcnGrad(*this); }
41
42 /// Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
43 Bool_t Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameter_settings, Bool_t optConst,
44 Bool_t verbose = kFALSE) override;
45
46 // used inside Minuit:
47 inline bool returnsInMinuit2ParameterSpace() const override { return gradient->usesMinuitInternalValues(); }
48
49 inline void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, Bool_t doAlsoTrackingOpt) override
50 {
51 likelihood->constOptimizeTestStatistic(opcode, doAlsoTrackingOpt);
52 }
53
54private:
55 /// IMultiGradFunction override necessary for Minuit
56 double DoEval(const double *x) const override;
57
58public:
59 /// IMultiGradFunction overrides necessary for Minuit
60 void Gradient(const double *x, double *grad) const override;
61 void GradientWithPrevResult(const double *x, double *grad, double *previous_grad, double *previous_g2,
62 double *previous_gstep) const override;
63
64 /// Part of IMultiGradFunction interface, used widely both in Minuit and in RooFit.
65 inline unsigned int NDim() const override { return _nDim; }
66
67 inline std::string getFunctionName() const override { return likelihood->GetName(); }
68
69 inline std::string getFunctionTitle() const override { return likelihood->GetTitle(); }
70
71 inline void setOffsetting(Bool_t flag) override { likelihood->enableOffsetting(flag); }
72
73private:
74 /// This override should not be used in this class, so it throws.
75 double DoDerivative(const double *x, unsigned int icoord) const override;
76
77 bool syncParameterValuesFromMinuitCalls(const double *x, bool minuit_internal) const;
78
79 // members
80 std::shared_ptr<LikelihoodWrapper> likelihood;
81 std::shared_ptr<LikelihoodGradientWrapper> gradient;
82
83public:
84 mutable std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean;
85
86private:
87 mutable std::vector<double> minuit_internal_x_;
88 mutable std::vector<double> minuit_external_x_;
89
90public:
92};
93
94} // namespace TestStatistics
95} // namespace RooFit
96
97#endif // ROOT_ROOFIT_TESTSTATISTICS_MinuitFcnGrad
const Bool_t kFALSE
Definition RtypesCore.h:101
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:343
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
Minuit-RooMinimizer interface which synchronizes parameter data and coordinates evaluation of likelih...
void setOffsetting(Bool_t flag) override
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
std::vector< double > minuit_internal_x_
std::string getFunctionName() const override
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
double DoDerivative(const double *x, unsigned int icoord) const override
This override should not be used in this class, so it throws.
Bool_t Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameter_settings, Bool_t optConst, Bool_t verbose=kFALSE) override
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
double DoEval(const double *x) const override
IMultiGradFunction override necessary for Minuit.
bool syncParameterValuesFromMinuitCalls(const double *x, bool minuit_internal) const
Minuit calls (via FcnAdapters etc) DoEval or Gradient with a set of parameters x.
std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean
bool returnsInMinuit2ParameterSpace() const override
std::string getFunctionTitle() const override
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class...
void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, Bool_t doAlsoTrackingOpt) override
This function must be overridden in the derived class to pass on constant term optimization configura...
void GradientWithPrevResult(const double *x, double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) const override
void Gradient(const double *x, double *grad) const override
IMultiGradFunction overrides necessary for Minuit.
ROOT::Math::IMultiGradFunction * Clone() const override
Clone a function.
std::shared_ptr< LikelihoodWrapper > likelihood
std::vector< double > minuit_external_x_
std::shared_ptr< LikelihoodGradientWrapper > gradient
unsigned int NDim() const override
Part of IMultiGradFunction interface, used widely both in Minuit and in RooFit.
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 Common.h:18