BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RootResidualFunction.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/RootAdapter/RootResidualFunction.h
6 //! @brief Declares class RootResidualFunction.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_FIT_ROOTADAPTER_ROOTRESIDUALFUNCTION_H
16 #define BORNAGAIN_FIT_ROOTADAPTER_ROOTRESIDUALFUNCTION_H
17 
18 #include "Fit/Kernel/KernelTypes.h"
19 
20 #ifdef _WIN32
21 #include <Math/FitMethodFunction.h>
22 #else
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
25 #include <Math/FitMethodFunction.h>
26 #pragma GCC diagnostic pop
27 #endif
28 
29 //! Minimizer function with access to single data element residuals,
30 //! required by Fumili2 and GSLMultiMin minimizers.
31 
32 class RootResidualFunction : public ROOT::Math::FitMethodFunction
33 {
34 public:
35  typedef ROOT::Math::BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>::Type_t Type_t;
36 
37  //! Constructs RootResidualFunction
39  size_t npars, size_t ndatasize);
40 
41  Type_t Type() const override;
42 
43  ROOT::Math::IMultiGenFunction* Clone() const override;
44 
45  //! Evaluation of single data element residual. Will be called by ROOT minimizer.
46  double DataElement(const double* pars, unsigned int index,
47  double* gradients = 0) const override;
48 
49 private:
50  //! evaluation of chi2
51  double DoEval(const double* pars) const override;
52 
53  scalar_function_t m_objective_fun; //!< User function to get value to minimizer.
54  gradient_function_t m_gradient_fun; //!< User function to get residual and gradients.
55  size_t m_npars;
56  size_t m_datasize;
57 };
58 
59 #endif // BORNAGAIN_FIT_ROOTADAPTER_ROOTRESIDUALFUNCTION_H
Defines common types for fitting library.
std::function< double(const std::vector< double > &)> scalar_function_t
Definition: KernelTypes.h:28
std::function< double(const std::vector< double > &, unsigned int, std::vector< double > &)> gradient_function_t
Definition: KernelTypes.h:31
Minimizer function with access to single data element residuals, required by Fumili2 and GSLMultiMin ...
double DoEval(const double *pars) const override
evaluation of chi2
Type_t Type() const override
double DataElement(const double *pars, unsigned int index, double *gradients=0) const override
Evaluation of single data element residual. Will be called by ROOT minimizer.
scalar_function_t m_objective_fun
User function to get value to minimizer.
ROOT::Math::BasicFitMethodFunction< ROOT::Math::IMultiGenFunction >::Type_t Type_t
RootResidualFunction(scalar_function_t objective_fun, gradient_function_t gradient_fun, size_t npars, size_t ndatasize)
Constructs RootResidualFunction.
ROOT::Math::IMultiGenFunction * Clone() const override
gradient_function_t m_gradient_fun
User function to get residual and gradients.