Logo ROOT  
Reference Guide
GSLMultiMinFunctionWrapper.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Authors: L. Moneta, 12/2006
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library (see file COPYING); if not, write *
20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21 * 330, Boston, MA 02111-1307 USA, or contact the author. *
22 * *
23 **********************************************************************/
24
25// Header file for class GSLMultiMinFunctionWrapper
26//
27// Created by: moneta at Sat Nov 13 14:54:41 2004
28//
29// Last update: Sat Nov 13 14:54:41 2004
30//
31#ifndef ROOT_Math_GSLMultiMinFunctionWrapper
32#define ROOT_Math_GSLMultiMinFunctionWrapper
33
34#include "gsl/gsl_multimin.h"
35
37
38
39#include <cassert>
40
41namespace ROOT {
42namespace Math {
43
44
45
46 typedef double ( * GSLMultiMinFuncPointer ) ( const gsl_vector *, void *);
47 typedef void ( * GSLMultiMinDfPointer ) ( const gsl_vector *, void *, gsl_vector *);
48 typedef void ( * GSLMultiMinFdfPointer ) ( const gsl_vector *, void *, double *, gsl_vector *);
49
50
51/**
52 wrapper to a multi-dim function withtout derivatives for multi-dimensional
53 minimization algorithm
54
55 @ingroup MultiMin
56*/
57
59
60public:
61
63 {
64 fFunc.f = 0;
65 fFunc.n = 0;
66 fFunc.params = 0;
67 }
68
70 void SetDim ( unsigned int n ) { fFunc.n = n; }
71 void SetParams ( void * p) { fFunc.params = p; }
72
73 /// Fill gsl function structure from a C++ Function class
74 template<class FuncType>
75 void SetFunction(const FuncType &f) {
76 const void * p = &f;
77 assert (p != 0);
79 SetDim( f.NDim() );
80 SetParams(const_cast<void *>(p));
81 }
82
83 gsl_multimin_function * GetFunc() { return &fFunc; }
84
85 bool IsValid() {
86 return (fFunc.f != 0) ? true : false;
87 }
88
89
90 private:
91
92 gsl_multimin_function fFunc;
93
94 };
95
96
97/**
98 Wrapper for a multi-dimensional function with derivatives used in GSL multidim
99 minimization algorithm
100
101 @ingroup MultiMin
102
103 */
105
106 public:
107
109 {
110 fFunc.f = 0;
111 fFunc.df = 0;
112 fFunc.fdf = 0;
113 fFunc.n = 0;
114 fFunc.params = 0;
115 }
116
117
121 void SetDim ( unsigned int n ) { fFunc.n = n; }
122 void SetParams ( void * p) { fFunc.params = p; }
123
124 /// Fill gsl function structure from a C++ Function class
125 template<class FuncType>
126 void SetFunction(const FuncType &f) {
127 const void * p = &f;
128 assert (p != 0);
132 SetDim( f.NDim() );
133 SetParams(const_cast<void *>(p));
134 }
135
136 gsl_multimin_function_fdf * GetFunc() { return &fFunc; }
137
138#ifdef NEEDED_LATER
139 // evaluate the function
140 double operator() (const double * x) {
141 // vx must be a gsl_vector
142 return GSL_MULTIMIN_FN_EVAL(&fFunc, vx);
143 }
144#endif
145
146 /// check if function is valid (has been set)
147 bool IsValid() {
148 return (fFunc.f != 0) ? true : false;
149 }
150
151 private:
152
153 gsl_multimin_function_fdf fFunc;
154
155 };
156
157
158
159
160} // namespace Math
161} // namespace ROOT
162
163#endif /* ROOT_Math_GSLMultiMinFunctionWrapper */
#define f(i)
Definition: RSha256.hxx:104
TRObject operator()(const T1 &t1) const
typedef void((*Func_t)())
Wrapper for a multi-dimensional function with derivatives used in GSL multidim minimization algorithm...
bool IsValid()
check if function is valid (has been set)
void SetFunction(const FuncType &f)
Fill gsl function structure from a C++ Function class.
wrapper to a multi-dim function withtout derivatives for multi-dimensional minimization algorithm
void SetFuncPointer(GSLMultiMinFuncPointer f)
void SetFunction(const FuncType &f)
Fill gsl function structure from a C++ Function class.
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Namespace for new Math classes and functions.
void(* GSLMultiMinDfPointer)(const gsl_vector *, void *, gsl_vector *)
double(* GSLMultiMinFuncPointer)(const gsl_vector *, void *)
void(* GSLMultiMinFdfPointer)(const gsl_vector *, void *, double *, gsl_vector *)
VSD Structures.
Definition: StringConv.hxx:21
Class for adapting any multi-dimension C++ functor class to C function pointers used by GSL MultiMin ...