00001 // @(#)root/mathmore:$Id: GSLMonteFunctionWrapper.h 21503 2007-12-19 17:34:54Z moneta $ 00002 // Authors: L. Moneta, 08/2007 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 GSLMonteFunctionWrapper 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_GSLMonteFunctionWrapper 00032 #define ROOT_Math_GSLMonteFunctionWrapper 00033 00034 #include "gsl/gsl_monte.h" 00035 #include "gsl/gsl_multimin.h" 00036 00037 #include "GSLMonteFunctionAdapter.h" 00038 00039 00040 #include <cassert> 00041 00042 namespace ROOT { 00043 namespace Math { 00044 00045 00046 00047 typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *); 00048 00049 00050 /** 00051 wrapper to a multi-dim function withtout derivatives for Monte Carlo multi-dimensional 00052 integration algorithm 00053 00054 @ingroup MCIntegration 00055 */ 00056 00057 class GSLMonteFunctionWrapper { 00058 00059 public: 00060 00061 GSLMonteFunctionWrapper() 00062 { 00063 fFunc.f = 0; 00064 fFunc.dim = 0; 00065 fFunc.params = 0; 00066 } 00067 00068 void SetFuncPointer( GSLMonteFuncPointer f) { fFunc.f = f; } 00069 void SetDim ( unsigned int n ) { fFunc.dim = n; } 00070 void SetParams ( void * p) { fFunc.params = p; } 00071 00072 /// Fill gsl function structure from a C++ Function class 00073 template<class FuncType> 00074 void SetFunction(const FuncType &f) { 00075 const void * p = &f; 00076 assert (p != 0); 00077 SetFuncPointer(&GSLMonteFunctionAdapter<FuncType >::F); 00078 SetDim( f.NDim() ); 00079 SetParams(const_cast<void *>(p)); 00080 } 00081 00082 gsl_monte_function * GetFunc() { return &fFunc; } 00083 00084 // evaluate the function and derivatives 00085 double operator() (const double * x) { return GSL_MONTE_FN_EVAL(&fFunc, const_cast<double *>(x) ); } 00086 00087 00088 private: 00089 gsl_monte_function fFunc; 00090 00091 }; 00092 00093 00094 00095 00096 00097 } // namespace Math 00098 } // namespace ROOT 00099 00100 #endif /* ROOT_Math_GSLMonteFunctionWrapper */