00001 // @(#)root/mathmore:$Id: GSLMultiFitFunctionWrapper.h 22522 2008-03-07 16:07:51Z moneta $ 00002 // Authors: L. Moneta Dec 2006 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU General Public License * 00010 * as published by the Free Software Foundation; either version 2 * 00011 * of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this library (see file COPYING); if not, write * 00020 * to the Free Software Foundation, Inc., 59 Temple Place, Suite * 00021 * 330, Boston, MA 02111-1307 USA, or contact the author. * 00022 * * 00023 **********************************************************************/ 00024 00025 // Header file for class GSLMultiMinFunctionWrapper 00026 // 00027 // Created by: moneta at Sat Nov 13 14:54:41 2004 00028 // 00029 // Last update: Sat Nov 13 14:54:41 2004 00030 // 00031 #ifndef ROOT_Math_GSLMultiFitFunctionWrapper 00032 #define ROOT_Math_GSLMultiFitFunctionWrapper 00033 00034 #include "gsl/gsl_multifit.h" 00035 00036 #include "GSLMultiFitFunctionAdapter.h" 00037 00038 00039 #include <cassert> 00040 00041 namespace ROOT { 00042 namespace Math { 00043 00044 00045 00046 typedef double ( * GSLMultiFitFPointer ) ( const gsl_vector *, void *, gsl_vector *); 00047 typedef void ( * GSLMultiFitDfPointer ) ( const gsl_vector *, void *, gsl_matrix *); 00048 typedef void ( * GSLMultiFitFdfPointer ) ( const gsl_vector *, void *, gsl_vector *, gsl_matrix *); 00049 00050 00051 /** 00052 wrapper to a multi-dim function withtout derivatives for multi-dimensional 00053 minimization algorithm 00054 00055 @ingroup MultiMin 00056 */ 00057 00058 class GSLMultiFitFunctionWrapper { 00059 00060 public: 00061 00062 GSLMultiFitFunctionWrapper() 00063 { 00064 fFunc.f = 0; 00065 fFunc.df = 0; 00066 fFunc.fdf = 0; 00067 fFunc.n = 0; 00068 fFunc.p = 0; 00069 fFunc.params = 0; 00070 } 00071 00072 00073 /// Fill gsl function structure from a C++ function iterator and size and number of residuals 00074 template<class FuncVector> 00075 void SetFunction(const FuncVector & f, unsigned int nres, unsigned int npar ) { 00076 const void * p = &f; 00077 assert (p != 0); 00078 fFunc.f = &GSLMultiFitFunctionAdapter<FuncVector >::F; 00079 fFunc.df = &GSLMultiFitFunctionAdapter<FuncVector >::Df; 00080 fFunc.fdf = &GSLMultiFitFunctionAdapter<FuncVector >::FDf; 00081 fFunc.n = nres; 00082 fFunc.p = npar; 00083 fFunc.params = const_cast<void *>(p); 00084 } 00085 00086 gsl_multifit_function_fdf * GetFunc() { return &fFunc; } 00087 00088 00089 private: 00090 00091 gsl_multifit_function_fdf fFunc; 00092 00093 }; 00094 00095 00096 00097 } // namespace Math 00098 } // namespace ROOT 00099 00100 #endif /* ROOT_Math_GSLMultiMinFunctionWrapper */