BornAgain  1.19.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 reflection and scattering
4 //
5 //! @file Fit/Adapter/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 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_FIT_ADAPTER_ROOTRESIDUALFUNCTION_H
21 #define BORNAGAIN_FIT_ADAPTER_ROOTRESIDUALFUNCTION_H
22 
23 #include "Fit/Minimizer/Types.h"
24 
25 #ifdef _WIN32
26 #include <Math/FitMethodFunction.h>
27 #else
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
30 #include <Math/FitMethodFunction.h>
31 #pragma GCC diagnostic pop
32 #endif
33 
34 //! Minimizer function with access to single data element residuals,
35 //! required by Fumili2 and GSLMultiMin minimizers.
36 
37 class RootResidualFunction : public ROOT::Math::FitMethodFunction {
38 public:
39  typedef ROOT::Math::BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>::Type_t Type_t;
40 
41  //! Constructs RootResidualFunction
43  size_t npars, size_t ndatasize);
44 
45  Type_t Type() const override;
46 
47  ROOT::Math::IMultiGenFunction* Clone() const override;
48 
49  //! Evaluation of single data element residual. Will be called by ROOT minimizer.
50  double DataElement(const double* pars, unsigned int index,
51  double* gradients = 0) const override;
52 
53 private:
54  //! evaluation of chi2
55  double DoEval(const double* pars) const override;
56 
57  scalar_function_t m_objective_fun; //!< User function to get value to minimizer.
58  gradient_function_t m_gradient_fun; //!< User function to get residual and gradients.
59  size_t m_npars;
60  size_t m_datasize;
61 };
62 
63 #endif // BORNAGAIN_FIT_ADAPTER_ROOTRESIDUALFUNCTION_H
64 #endif // USER_API
Defines common types for fitting library.
std::function< double(const std::vector< double > &)> scalar_function_t
Definition: Types.h:30
std::function< double(const std::vector< double > &, unsigned int, std::vector< double > &)> gradient_function_t
Definition: Types.h:33
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.