Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooGradMinimizerFcn.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, NL eScience Center, p.bos@esciencecenter.nl *
8 * VC, Vince Croft, DIANA / NYU, vincent.croft@cern.ch *
9 * *
10 * *
11 * Redistribution and use in source and binary forms, *
12 * with or without modification, are permitted according to the terms *
13 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
14 *****************************************************************************/
15
16#ifndef ROO_GRAD_MINIMIZER_FCN
17#define ROO_GRAD_MINIMIZER_FCN
18
19#include "RooAbsMinimizerFcn.h"
20
21#include "Minuit2/MnStrategy.h"
22#include "Minuit2/MnMatrix.h" // MnAlgebraicVector
23#include "Math/IFunction.h" // IMultiGradFunction
26
27#include <vector>
28
30public:
31 RooGradMinimizerFcn(RooAbsReal *funct, RooMinimizer *context, bool verbose = false);
33 ROOT::Math::IMultiGradFunction *Clone() const override;
34
36 double getErrorDef() const;
37 void setStrategy(int istrat);
38
39 Bool_t Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameter_settings, Bool_t optConst,
40 Bool_t verbose = kFALSE) override;
41
42 void synchronizeGradientParameterSettings(std::vector<ROOT::Fit::ParameterSettings> &parameter_settings) const;
43
44 inline bool returnsInMinuit2ParameterSpace() const override { return true; }
45 inline unsigned int NDim() const override { return getNDim(); }
46 inline void setStepTolerance(double step_tolerance) const { _gradf.SetStepTolerance(step_tolerance); }
47 inline void setGradTolerance(double grad_tolerance) const { _gradf.SetGradTolerance(grad_tolerance); }
48 inline void setNcycles(unsigned int ncycles) const { _gradf.SetNCycles(ncycles); }
49 inline void setErrorLevel(double error_level) const { _gradf.SetErrorLevel(error_level); }
50 inline std::string getFunctionName() const override { return _funct->GetName(); }
51 inline std::string getFunctionTitle() const override { return _funct->GetTitle(); }
52 inline void setOffsetting(Bool_t flag) override { _funct->enableOffsetting(flag); }
53
54private:
55 void runDerivator(unsigned int i_component) const;
56
57 void resetHasBeenCalculatedFlags() const;
58 bool syncParameter(double x, std::size_t ix) const;
59 bool syncParameters(const double *x) const;
60
61 inline void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, Bool_t doAlsoTrackingOpt) override
62 {
63 _funct->constOptimizeTestStatistic(opcode, doAlsoTrackingOpt);
64 }
65
66public:
68
69private:
70 // IMultiGradFunction overrides
71 double DoEval(const double *x) const override;
72 double DoDerivative(const double *x, unsigned int icoord) const override;
73 double DoDerivativeWithPrevResult(const double *x, unsigned int i_component, double *previous_grad,
74 double *previous_g2, double *previous_gstep) const override;
75
76 // members
77 // mutable because ROOT::Math::IMultiGradFunction::DoDerivative is const
78protected:
79 mutable std::vector<ROOT::Minuit2::DerivatorElement> _grad;
80 mutable std::vector<double> _grad_params;
81
82private:
85 mutable std::vector<bool> has_been_calculated;
86 mutable bool none_have_been_calculated = false;
87};
88#endif
const Bool_t kFALSE
Definition RtypesCore.h:101
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:343
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition MnStrategy.h:27
void SetNCycles(unsigned int value)
virtual void constOptimizeTestStatistic(ConstOpCode opcode, Bool_t doAlsoTrackingOpt=kTRUE)
Interface function signaling a request to perform constant term optimization.
unsigned int getNDim() const
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
virtual void enableOffsetting(Bool_t)
Definition RooAbsReal.h:371
void synchronizeGradientParameterSettings(std::vector< ROOT::Fit::ParameterSettings > &parameter_settings) const
void setErrorLevel(double error_level) const
ROOT::Minuit2::MnStrategy getStrategy() const
double DoDerivativeWithPrevResult(const double *x, unsigned int i_component, double *previous_grad, double *previous_g2, double *previous_gstep) const override
Bool_t Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameter_settings, Bool_t optConst, Bool_t verbose=kFALSE) override
Like synchronizeParameterSettings, Synchronize informs Minuit through its parameter_settings vector o...
unsigned int NDim() const override
Retrieve the dimension of the function.
void resetHasBeenCalculatedFlags() const
void setNcycles(unsigned int ncycles) const
double getErrorDef() const
double DoEval(const double *x) const override
void setOffsetting(Bool_t flag) override
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
std::string getFunctionName() const override
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
void setGradTolerance(double grad_tolerance) const
bool returnsInMinuit2ParameterSpace() const override
std::vector< bool > has_been_calculated
void runDerivator(unsigned int i_component) const
std::vector< double > _grad_params
std::string getFunctionTitle() const override
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class...
void setStepTolerance(double step_tolerance) const
ROOT::Math::IMultiGradFunction * Clone() const override
Clone a function.
std::vector< ROOT::Minuit2::DerivatorElement > _grad
bool syncParameter(double x, std::size_t ix) const
ROOT::Minuit2::NumericalDerivator _gradf
bool syncParameters(const double *x) const
double DoDerivative(const double *x, unsigned int icoord) const override
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...
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Double_t x[n]
Definition legend1.C:17