#ifndef __JFIT__JREGRESSOR__ #define __JFIT__JREGRESSOR__ #include "Jeep/JMessage.hh" /** * \file * General purpose data regression method. * \author mdejong */ namespace JFIT {} namespace JPP { using namespace JFIT; } namespace JFIT { using JEEP::JMessage; /** * Abstract minimiser. * This "minimiser" can be used to determine the chi2 of the data for a given model value. */ template class JAbstractMinimiser : public JMessage< JAbstractMinimiser > { public: typedef double result_type; /** * Default constructor. */ JAbstractMinimiser() {} /** * Get chi2. * * \param fit fit function * \param __begin begin of data * \param __end end of data * \return chi2 */ template result_type operator()(const JFunction_t& fit, T __begin, T __end) { double chi2 = 0.0; for (T i = __begin; i != __end; ++i) { chi2 += fit(value, *i); } return chi2; } JModel_t value; //!< model value }; /** * Template definition of a data regressor of given model. * * The first template argument refers to the model that should be fitted to the data and * the second to the type of minimiser. */ template class JMinimiser_t = JAbstractMinimiser> struct JRegressor; /** * Abstract class for global fit method. */ template class JMinimiser_t = JAbstractMinimiser> struct JAbstractRegressor : public JMinimiser_t { typedef JMinimiser_t minimiser_type; typedef JRegressor regressor_type; typedef typename minimiser_type::result_type result_type; /** * Global fit. * * \param value start value * \param __begin begin of data set * \param __end end of data set * \return chi2 */ template result_type operator()(const JModel_t& value, T __begin, T __end) { static_cast(*this).value = value; return static_cast(*this)(static_cast(*this), __begin, __end); } }; } #endif