Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:21:53

0001 // @(#)root/mathcore:$Id$
0002 // Author: L. Moneta 25 Nov 2014
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class BasicFCN
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    BasicFCN class: base class  for the objective functions used in the fits
0036    It has a reference to the data and the model function used in the fit.
0037    It cannot be instantiated but constructed from the derived classes
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       Constructor from data set  and model function
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       Destructor (no operations)
0065    */
0066    virtual ~BasicFCN ()  {}
0067 
0068 public:
0069 
0070 
0071    /// access to const reference to the data
0072    virtual const DataType & Data() const { return *fData; }
0073 
0074    /// access to data pointer
0075    std::shared_ptr<DataType> DataPtr() const { return fData; }
0076 
0077    /// access to const reference to the model function
0078    virtual const IModelFunction & ModelFunction() const { return *fFunc; }
0079 
0080    /// access to function pointer
0081    std::shared_ptr<IModelFunction> ModelFunctionPtr() const { return fFunc; }
0082 
0083    /// flag to indicate if can compute Hessian
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    /// Set the data pointer
0098    void SetData(const std::shared_ptr<DataType> & data) { fData = data; }
0099 
0100       /// Set the function pointer
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    } // end namespace Fit
0114 
0115 } // end namespace ROOT
0116 
0117 
0118 #endif /* ROOT_Fit_BasicFCN */