Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:13

0001 // @(#)root/mathcore:$Id$
0002 // Authors: L. Moneta, J.T. Offermann, E.G.P. Bos    2013-2018
0003 //
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2013 , LCG ROOT MathLib Team                         *
0007  *                                                                    *
0008  **********************************************************************/
0009 /*
0010  * NumericalDerivator.h
0011  *
0012  *  Original version created on: Aug 14, 2013
0013  *      Authors: L. Moneta, J. T. Offermann
0014  *  Modified version created on: Sep 27, 2017
0015  *      Author: E. G. P. Bos
0016  */
0017 
0018 #ifndef ROOT_Minuit2_NumericalDerivator
0019 #define ROOT_Minuit2_NumericalDerivator
0020 
0021 #include <Math/IFunctionfwd.h>
0022 
0023 #include <vector>
0024 #include "Fit/ParameterSettings.h"
0025 #include "Minuit2/SinParameterTransformation.h"
0026 #include "Minuit2/SqrtUpParameterTransformation.h"
0027 #include "Minuit2/SqrtLowParameterTransformation.h"
0028 #include "Minuit2/MnMachinePrecision.h"
0029 
0030 namespace ROOT {
0031 namespace Minuit2 {
0032 
0033 // Holds all necessary derivatives and associated numbers (per parameter) used in the NumericalDerivator class.
0034 struct DerivatorElement {
0035    double derivative;
0036    double second_derivative;
0037    double step_size;
0038 };
0039 
0040 class NumericalDerivator {
0041 public:
0042    explicit NumericalDerivator(bool always_exactly_mimic_minuit2 = true);
0043    NumericalDerivator(const NumericalDerivator &other);
0044    NumericalDerivator(double step_tolerance, double grad_tolerance, unsigned int ncycles, double error_level,
0045                       bool always_exactly_mimic_minuit2 = true);
0046 
0047    void SetupDifferentiate(const ROOT::Math::IBaseFunctionMultiDim *function, const double *cx,
0048                            const std::vector<ROOT::Fit::ParameterSettings> &parameters);
0049    std::vector<DerivatorElement> Differentiate(const ROOT::Math::IBaseFunctionMultiDim *function, const double *x,
0050                                                const std::vector<ROOT::Fit::ParameterSettings> &parameters,
0051                                                const std::vector<DerivatorElement> &previous_gradient);
0052 
0053    DerivatorElement PartialDerivative(const ROOT::Math::IBaseFunctionMultiDim *function, const double *x,
0054                                       const std::vector<ROOT::Fit::ParameterSettings> &parameters,
0055                                       unsigned int i_component, DerivatorElement previous);
0056    DerivatorElement FastPartialDerivative(const ROOT::Math::IBaseFunctionMultiDim *function,
0057                                           const std::vector<ROOT::Fit::ParameterSettings> &parameters,
0058                                           unsigned int i_component, const DerivatorElement &previous);
0059    DerivatorElement operator()(const ROOT::Math::IBaseFunctionMultiDim *function, const double *x,
0060                                const std::vector<ROOT::Fit::ParameterSettings> &parameters, unsigned int i_component,
0061                                const DerivatorElement &previous);
0062 
0063    double GetValue() const { return fVal; }
0064    inline void SetStepTolerance(double value) { fStepTolerance = value; }
0065    inline void SetGradTolerance(double value) { fGradTolerance = value; }
0066    inline void SetNCycles(unsigned int value) { fNCycles = value; }
0067    inline void SetErrorLevel(double value) { fUp = value; }
0068 
0069    double Int2ext(const ROOT::Fit::ParameterSettings &parameter, double val) const;
0070    double Ext2int(const ROOT::Fit::ParameterSettings &parameter, double val) const;
0071    double DInt2Ext(const ROOT::Fit::ParameterSettings &parameter, double val) const;
0072 
0073    void SetInitialGradient(const ROOT::Math::IBaseFunctionMultiDim *function,
0074                            const std::vector<ROOT::Fit::ParameterSettings> &parameters,
0075                            std::vector<DerivatorElement> &gradient);
0076 
0077    inline bool AlwaysExactlyMimicMinuit2() const { return fAlwaysExactlyMimicMinuit2; }
0078    inline void SetAlwaysExactlyMimicMinuit2(bool flag) { fAlwaysExactlyMimicMinuit2 = flag; }
0079 
0080 private:
0081    double fStepTolerance = 0.5;
0082    double fGradTolerance = 0.1;
0083    double fUp = 1;
0084    double fVal = 0;
0085 
0086    std::vector<double> fVx;
0087    std::vector<double> fVxExternal;
0088    std::vector<double> fVxFValCache;
0089    double fDfmin;
0090    double fVrysml;
0091 
0092    // MODIFIED: Minuit2 determines machine precision in a slightly different way than
0093    // std::numeric_limits<double>::epsilon()). We go with the Minuit2 one.
0094    ROOT::Minuit2::MnMachinePrecision fPrecision;
0095 
0096    ROOT::Minuit2::SinParameterTransformation fDoubleLimTrafo;
0097    ROOT::Minuit2::SqrtUpParameterTransformation fUpperLimTrafo;
0098    ROOT::Minuit2::SqrtLowParameterTransformation fLowerLimTrafo;
0099 
0100    unsigned int fNCycles = 2;
0101    bool fAlwaysExactlyMimicMinuit2;
0102 
0103 };
0104 
0105 std::ostream &operator<<(std::ostream &out, const DerivatorElement &value);
0106 
0107 } // namespace Minuit2
0108 } // namespace ROOT
0109 
0110 #endif // ROOT_Minuit2_NumericalDerivator