All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GSLFunAdapters.cpp
Go to the documentation of this file.
1 // $Id: GSLFunAdapters.cpp,v 1.2 2005/11/25 10:27:03 mato Exp $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // GaudiGSL/GaudiMath
6 // ============================================================================
8 #include "GaudiMath/GaudiMath.h"
9 // ============================================================================
10 // GSL
11 // ============================================================================
12 #include "gsl/gsl_mode.h"
13 #include "gsl/gsl_sf_result.h"
14 // ============================================================================
15 
23 namespace Genfun
24 {
25  namespace GaudiMathImplementation
26  {
27 
28  FUNCTION_OBJECT_IMP( GSLFunctionWithError )
29 
32  : AbsFunction()
33  , m_function ( function )
34  , m_result ( new gsl_sf_result() )
35  {
36  m_result -> val = -1.e+10 ;
37  m_result -> err = -1.e+10 ;
38  }
39 
42  : AbsFunction()
43  , m_function ( func.m_function )
44  , m_result ( new gsl_sf_result() )
45  {
46  m_result -> val = func.m_result -> val ;
47  m_result -> err = func.m_result -> err ;
48  }
49 
51  { if ( 0 != m_result ) { delete m_result ; } }
52 
53  double GSLFunctionWithError::operator()
54  ( double x ) const
55  {
56  (*m_function)( x , m_result ) ;
57  return m_result -> val ;
58  }
59 
60  double GSLFunctionWithError::operator()
61  ( const Genfun::Argument& x ) const
62  {
63  (*m_function)( x[0] , m_result ) ;
64  return m_result -> val ;
65  }
66 
68  ( unsigned int i ) const
69  {
70  if( i >= 1 )
71  {
72  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
73  return Genfun::FunctionNoop( &aux ) ;
74  };
75  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
76  return Genfun::FunctionNoop( &aux ) ;
77  }
78 
80  { return m_function ; }
81 
82  const gsl_sf_result& GSLFunctionWithError::result () const
83  { return *m_result ; }
84 
85  double GSLFunctionWithError::error () const
86  { return m_result -> err ; }
87 
88 
89  FUNCTION_OBJECT_IMP( GSLFunctionWithMode )
90 
93  const gsl_mode_t& mod )
94  : AbsFunction()
95  , m_function ( function )
96  , m_mode ( new gsl_mode_t() )
97  {
98  *m_mode = mod ;
99  }
100 
102  ( const GSLFunctionWithMode& func )
103  : AbsFunction()
104  , m_function ( func.m_function )
105  , m_mode ( new gsl_mode_t () )
106  {
107  *m_mode = *(func.m_mode) ;
108  }
109 
111  { if ( 0 != m_mode ) { delete m_mode ; } }
112 
113  double GSLFunctionWithMode::operator()
114  ( double x ) const
115  { return (*m_function)( x , *m_mode ) ; }
116 
117  double GSLFunctionWithMode::operator()
118  ( const Genfun::Argument& x ) const
119  { return (*m_function)( x[0] , *m_mode ) ; }
120 
122  ( unsigned int i ) const
123  {
124  if( i >= 1 )
125  {
126  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
127  return Genfun::FunctionNoop( &aux ) ;
128  };
129  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
130  return Genfun::FunctionNoop( &aux ) ;
131  }
132 
134  { return m_function ; }
135 
136  const gsl_mode_t& GSLFunctionWithMode::mode () const
137  { return *m_mode ; }
138 
139 
140  FUNCTION_OBJECT_IMP( GSLFunctionWithModeAndError )
141 
144  const gsl_mode_t& mod )
145  : AbsFunction()
146  , m_function ( function )
147  , m_mode ( new gsl_mode_t() )
148  , m_result ( new gsl_sf_result() )
149  {
150  *m_mode = mod ;
151  m_result -> val = -1.e+10 ;
152  m_result -> err = -1.e+10 ;
153  }
154 
157  : AbsFunction()
158  , m_function ( func.m_function )
159  , m_mode ( new gsl_mode_t () )
160  , m_result ( new gsl_sf_result() )
161  {
162  *m_mode = *(func.m_mode) ;
163  m_result -> val = func.m_result -> val ;
164  m_result -> err = func.m_result -> err ;
165  }
166 
168  {
169  if ( 0 != m_mode ) { delete m_mode ; }
170  if ( 0 != m_result ) { delete m_result ; }
171  }
172 
173  double GSLFunctionWithModeAndError::operator()
174  ( double x ) const
175  {
176  (*m_function)( x , *m_mode , m_result ) ;
177  return m_result -> val ;
178  }
179 
180  double GSLFunctionWithModeAndError::operator()
181  ( const Genfun::Argument& x ) const
182  {
183  (*m_function)( x[0] , *m_mode , m_result ) ;
184  return m_result -> val ;
185  }
186 
188  ( unsigned int i ) const
189  {
190  if( i >= 1 )
191  {
192  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
193  return Genfun::FunctionNoop( &aux ) ;
194  };
195  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
196  return Genfun::FunctionNoop( &aux ) ;
197  }
198 
201  { return m_function ; }
202 
203  const gsl_mode_t&
205  { return *m_mode ; }
206 
207  const gsl_sf_result&
209  { return *m_result ; }
210 
211  double
213  { return m_result -> err ; }
214 
215  } // end of namespace GaudiMathImplementation
216 } // end of namespace Genfun
217 
Function function() const
get the function itself
Genfun::GaudiMathImplementation::GSLFunctionWithError GSLFunctionWithError
Definition: Adapters.h:29
Function function() const
get the function itself
const gsl_sf_result & result() const
get the last evaluated result
int(* Function)(double, gsl_mode_t, gsl_sf_result *)
the actual type of the function
const gsl_sf_result & result() const
get the last evaluated result
Genfun::AbsFunction Function
Definition: GaudiMath.h:26
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:31
Genfun::Derivative partial(unsigned int i) const
Genfun::Derivative partial(unsigned int i) const
const gsl_mode_t & mode() const
get the current mode
Function function() const
get the function itself
Genfun::Derivative partial(unsigned int i) const
double(* Function)(double, gsl_mode_t)
the actual type of the function
const gsl_mode_t & mode() const
get the current mode
double error() const
get the error in the last estimate of the result
list i
Definition: ana.py:128
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:29
double error() const
get the error in the last estimate of the result
int(* Function)(double, gsl_sf_result *)
the actual type of the function