Logo ROOT  
Reference Guide
Go to the documentation of this file.
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 *****************************************************************************/
19#include "RooAbsMinimizerFcn.h"
21#include "Minuit2/MnStrategy.h"
22#include "Minuit2/MnMatrix.h" // MnAlgebraicVector
23#include "Math/IFunction.h" // IMultiGradFunction
27#include <vector>
31 RooGradMinimizerFcn(RooAbsReal *funct, RooMinimizer *context, bool verbose = false);
33 ROOT::Math::IMultiGradFunction *Clone() const override;
36 double getErrorDef() const;
37 void setStrategy(int istrat);
39 bool Synchronize(std::vector<ROOT::Fit::ParameterSettings> &parameter_settings, bool optConst,
40 bool verbose = false) override;
42 void synchronizeGradientParameterSettings(std::vector<ROOT::Fit::ParameterSettings> &parameter_settings) const;
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 flag) override { _funct->enableOffsetting(flag); }
54 bool fit(ROOT::Fit::Fitter& fitter) const override { return fitter.FitFCN(*this); };
55 ROOT::Math::IMultiGenFunction* getMultiGenFcn() override { return this; };
58 void runDerivator(unsigned int i_component) const;
60 void resetHasBeenCalculatedFlags() const;
61 bool syncParameter(double x, std::size_t ix) const;
62 bool syncParameters(const double *x) const;
64 inline void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override
65 {
66 _funct->constOptimizeTestStatistic(opcode, doAlsoTrackingOpt);
67 }
70 enum class GradientCalculatorMode { ExactlyMinuit2, AlmostMinuit2 };
73 // IMultiGradFunction overrides
74 double DoEval(const double *x) const override;
75 double DoDerivative(const double *x, unsigned int icoord) const override;
76 double DoDerivativeWithPrevResult(const double *x, unsigned int i_component, double *previous_grad,
77 double *previous_g2, double *previous_gstep) const override;
79 // members
80 // mutable because ROOT::Math::IMultiGradFunction::DoDerivative is const
82 mutable std::vector<ROOT::Minuit2::DerivatorElement> _grad;
83 mutable std::vector<double> _grad_params;
88 mutable std::vector<bool> has_been_calculated;
89 mutable bool none_have_been_calculated = false;
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
bool FitFCN(unsigned int npar, Function &fcn, const double *params=0, unsigned int dataSize=0, bool chi2fit=false)
Fit using the a generic FCN function as a C++ callable object implementing double () (const double *)...
Definition: Fitter.h:625
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
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 doAlsoTrackingOpt=true)
Interface function signaling a request to perform constant term optimization.
Definition: RooAbsArg.cxx:1857
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)
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
void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override
This function must be overridden in the derived class to pass on constant term optimization configura...
unsigned int NDim() const override
Retrieve the dimension of the function.
void setOffsetting(bool flag) override
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
void resetHasBeenCalculatedFlags() const
void setStrategy(int istrat)
void setNcycles(unsigned int ncycles) const
double getErrorDef() const
double DoEval(const double *x) const override
std::string getFunctionName() const override
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameter_settings, bool optConst, bool verbose=false) override
Like synchronizeParameterSettings, Synchronize informs Minuit through its parameter_settings vector o...
void setGradTolerance(double grad_tolerance) const
bool returnsInMinuit2ParameterSpace() const override
std::vector< bool > has_been_calculated
bool fit(ROOT::Fit::Fitter &fitter) const override
RooGradMinimizerFcn(RooAbsReal *funct, RooMinimizer *context, bool verbose=false)
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
ROOT::Math::IMultiGenFunction * getMultiGenFcn() override
double DoDerivative(const double *x, unsigned int icoord) const override
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:43
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
Double_t x[n]
Definition: legend1.C:17