File indexing completed on 2025-01-30 10:21:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_Fit_BasicFCN
0014 #define ROOT_Fit_BasicFCN
0015
0016 #include "Math/FitMethodFunction.h"
0017
0018 #include "Math/IParamFunction.h"
0019
0020 #include "Math/IParamFunctionfwd.h"
0021
0022 #include <memory>
0023
0024
0025
0026 namespace ROOT {
0027
0028
0029 namespace Fit {
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 template<class DerivFunType, class ModelFunType, class DataType>
0040 class BasicFCN : public ::ROOT::Math::BasicFitMethodFunction<DerivFunType> {
0041
0042 protected:
0043
0044 typedef typename ModelFunType::BackendType T;
0045
0046 typedef ::ROOT::Math::BasicFitMethodFunction<DerivFunType> BaseObjFunction;
0047 typedef typename BaseObjFunction::BaseFunction BaseFunction;
0048
0049 typedef ::ROOT::Math::IParamMultiFunctionTempl<T> IModelFunction;
0050 typedef ::ROOT::Math::IParametricGradFunctionMultiDimTempl<T> IGradModelFunction;
0051
0052
0053
0054
0055 BasicFCN (const std::shared_ptr<DataType> & data, const std::shared_ptr<IModelFunction> & func) :
0056 BaseObjFunction(func->NPar(), data->Size() ),
0057 fData(data),
0058 fFunc(func)
0059 { }
0060
0061
0062
0063
0064
0065
0066 virtual ~BasicFCN () {}
0067
0068 public:
0069
0070
0071
0072 virtual const DataType & Data() const { return *fData; }
0073
0074
0075 std::shared_ptr<DataType> DataPtr() const { return fData; }
0076
0077
0078 virtual const IModelFunction & ModelFunction() const { return *fFunc; }
0079
0080
0081 std::shared_ptr<IModelFunction> ModelFunctionPtr() const { return fFunc; }
0082
0083
0084 virtual bool HasHessian() const {
0085 if (!BaseObjFunction::IsAGradFCN()) return false;
0086 auto gfunc = dynamic_cast<const IGradModelFunction *>( fFunc.get());
0087 if (!gfunc) return false;
0088 return gfunc->HasParameterHessian();
0089 }
0090
0091
0092
0093
0094 protected:
0095
0096
0097
0098 void SetData(const std::shared_ptr<DataType> & data) { fData = data; }
0099
0100
0101 void SetModelFunction(const std::shared_ptr<IModelFunction> & func) { fFunc = func; }
0102
0103
0104 std::shared_ptr<DataType> fData;
0105 std::shared_ptr<IModelFunction> fFunc;
0106
0107
0108
0109 };
0110
0111
0112
0113 }
0114
0115 }
0116
0117
0118 #endif