GSLFunAdapters.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiGSL/GaudiMath
5 // ============================================================================
6 #include "GaudiMath/GSLFunAdapters.h"
7 #include "GaudiMath/GaudiMath.h"
8 // ============================================================================
9 // GSL
10 // ============================================================================
11 #include "gsl/gsl_mode.h"
12 #include "gsl/gsl_sf_result.h"
13 // ============================================================================
14 
22 namespace Genfun
23 {
24  namespace GaudiMathImplementation
25  {
26 
27  FUNCTION_OBJECT_IMP( GSLFunctionWithError )
28 
31  : AbsFunction()
32  , m_function ( function )
33  , m_result ( new gsl_sf_result() )
34  {
35  m_result -> val = -1.e+10 ;
36  m_result -> err = -1.e+10 ;
37  }
38 
41  : AbsFunction()
42  , m_function ( func.m_function )
43  , m_result ( new gsl_sf_result() )
44  {
45  m_result -> val = func.m_result -> val ;
46  m_result -> err = func.m_result -> err ;
47  }
48 
49 
50  double GSLFunctionWithError::operator()
51  ( double x ) const
52  {
53  (*m_function)( x , m_result.get() ) ;
54  return m_result -> val ;
55  }
56 
57  double GSLFunctionWithError::operator()
58  ( const Genfun::Argument& x ) const
59  {
60  (*m_function)( x[0] , m_result.get() ) ;
61  return m_result -> val ;
62  }
63 
65  ( unsigned int i ) const
66  {
67  if( i >= 1 )
68  {
69  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
70  return Genfun::FunctionNoop( &aux ) ;
71  };
72  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
73  return Genfun::FunctionNoop( &aux ) ;
74  }
75 
77  { return m_function ; }
78 
79  const gsl_sf_result& GSLFunctionWithError::result () const
80  { return *m_result ; }
81 
82  double GSLFunctionWithError::error () const
83  { return m_result -> err ; }
84 
85 
86  FUNCTION_OBJECT_IMP( GSLFunctionWithMode )
87 
90  const gsl_mode_t& mod )
91  : AbsFunction()
92  , m_function ( function )
93  , m_mode ( new gsl_mode_t() )
94  {
95  *m_mode = mod ;
96  }
97 
99  ( const GSLFunctionWithMode& func )
100  : AbsFunction()
101  , m_function ( func.m_function )
102  , m_mode ( new gsl_mode_t () )
103  {
104  *m_mode = *(func.m_mode) ;
105  }
106 
107  double GSLFunctionWithMode::operator()
108  ( double x ) const
109  { return (*m_function)( x , *m_mode ) ; }
110 
111  double GSLFunctionWithMode::operator()
112  ( const Genfun::Argument& x ) const
113  { return (*m_function)( x[0] , *m_mode ) ; }
114 
116  ( unsigned int i ) const
117  {
118  if( i >= 1 )
119  {
120  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
121  return Genfun::FunctionNoop( &aux ) ;
122  };
123  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
124  return Genfun::FunctionNoop( &aux ) ;
125  }
126 
128  { return m_function ; }
129 
130  const gsl_mode_t& GSLFunctionWithMode::mode () const
131  { return *m_mode ; }
132 
133 
134  FUNCTION_OBJECT_IMP( GSLFunctionWithModeAndError )
135 
138  const gsl_mode_t& mod )
139  : AbsFunction()
140  , m_function ( function )
141  , m_mode ( new gsl_mode_t() )
142  , m_result ( new gsl_sf_result() )
143  {
144  *m_mode = mod ;
145  m_result -> val = -1.e+10 ;
146  m_result -> err = -1.e+10 ;
147  }
148 
151  : AbsFunction()
152  , m_function ( func.m_function )
153  , m_mode ( new gsl_mode_t () )
154  , m_result ( new gsl_sf_result() )
155  {
156  *m_mode = *(func.m_mode) ;
157  m_result -> val = func.m_result -> val ;
158  m_result -> err = func.m_result -> err ;
159  }
160 
161 
162  double GSLFunctionWithModeAndError::operator()
163  ( double x ) const
164  {
165  (*m_function)( x , *m_mode , m_result.get() ) ;
166  return m_result -> val ;
167  }
168 
169  double GSLFunctionWithModeAndError::operator()
170  ( const Genfun::Argument& x ) const
171  {
172  (*m_function)( x[0] , *m_mode , m_result.get() ) ;
173  return m_result -> val ;
174  }
175 
177  ( unsigned int i ) const
178  {
179  if( i >= 1 )
180  {
181  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
182  return Genfun::FunctionNoop( &aux ) ;
183  };
184  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
185  return Genfun::FunctionNoop( &aux ) ;
186  }
187 
190  { return m_function ; }
191 
192  const gsl_mode_t&
194  { return *m_mode ; }
195 
196  const gsl_sf_result&
198  { return *m_result ; }
199 
200  double
202  { return m_result -> err ; }
203 
204  } // end of namespace GaudiMathImplementation
205 } // end of namespace Genfun
206 
Function function() const
get the function itself
Genfun::GaudiMathImplementation::GSLFunctionWithError GSLFunctionWithError
Definition: Adapters.h:27
Function function() const
get the function itself
const gsl_sf_result & result() const
get the last evaluated result
double(* Function)(double, gsl_mode_t)
the actual type of the function
const gsl_sf_result & result() const
get the last evaluated result
Genfun::AbsFunction Function
Definition: GaudiMath.h:24
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
Genfun::Derivative partial(unsigned int i) const
int(* Function)(double, gsl_sf_result *)
the actual type of the function
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
CLHEP.
Definition: IEqSolver.h:13
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:27
double error() const
get the error in the last estimate of the result
int(* Function)(double, gsl_mode_t, gsl_sf_result *)
the actual type of the function