Adapter.cpp
Go to the documentation of this file.
1 // Include files
2 // ============================================================================
3 // GaudiMath
4 // ============================================================================
5 #include "GaudiMath/GaudiMath.h"
6 // ============================================================================
7 // AIDA
8 // ============================================================================
9 #include "AIDA/IFunction.h"
10 // ============================================================================
11 #include <cstring>
12 
13 namespace Genfun
14 {
15  namespace GaudiMathImplementation
16  {
17 
18  FUNCTION_OBJECT_IMP( AdapterIFunction )
19 
20  AdapterIFunction::AdapterIFunction ( const AIDA::IFunction& fun)
21  : AbsFunction ( )
22  , m_fun ( &fun )
23  , m_dim ( fun.dimension() )
24  , m_arg ( fun.dimension() , 0 )
25  {}
26 
28  : AbsFunction ( )
29  , m_fun ( right.m_fun )
30  , m_dim ( right.m_dim )
31  , m_arg ( right.m_arg )
32  {}
33 
35 
36  double AdapterIFunction::operator() ( double x ) const
37  {
38  for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = 0.0 ; }
39  m_arg[0] = x ;
40  return m_fun -> value ( m_arg ) ;
41  }
42 
43  double AdapterIFunction::operator() ( const Genfun::Argument& x ) const
44  {
45  for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = x[i] ; }
46  return m_fun -> value ( m_arg ) ;
47  }
48 
50  {
51  if ( i >= m_dim )
52  {
53  const AbsFunction& aux = GaudiMath::Constant( 0 , m_dim ) ;
54  return Genfun::FunctionNoop( &aux ) ;
55  };
56  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
57  return Genfun::FunctionNoop ( &aux ) ;
58  }
59 
60  FUNCTION_OBJECT_IMP( Adapter2DoubleFunction )
61 
64  : AbsFunction ( )
65  , m_func ( func )
66  {}
67 
69  ( const Adapter2DoubleFunction& right )
70  : AbsFunction ( )
71  , m_func ( right.m_func )
72  {}
73 
75 
76  double Adapter2DoubleFunction::operator()
77  ( double x ) const
78  { return m_func ( x , 0 ) ; }
79 
80  double Adapter2DoubleFunction::operator()
81  ( const Genfun::Argument& x ) const
82  { return m_func ( x[0] , x[1] ) ; }
83 
84  double Adapter2DoubleFunction::operator()
85  ( const double x ,
86  const double y ) const
87  { return m_func ( x , y ) ; }
88 
91  {
92  if ( i >= 2 )
93  {
94  const AbsFunction& aux = GaudiMath::Constant( 0 , 2 ) ;
95  return Genfun::FunctionNoop( &aux ) ;
96  };
97  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
98  return Genfun::FunctionNoop ( &aux ) ;
99  }
100 
101  FUNCTION_OBJECT_IMP( Adapter3DoubleFunction )
102 
105  : AbsFunction ( )
106  , m_func ( func )
107  {}
108 
110  ( const Adapter3DoubleFunction& right )
111  : AbsFunction ( )
112  , m_func ( right.m_func )
113  {}
114 
116 
117  double Adapter3DoubleFunction::operator()
118  ( double x ) const
119  { return m_func ( x , 0 , 0 ) ; }
120 
121  double Adapter3DoubleFunction::operator()
122  ( const Genfun::Argument& x ) const
123  { return m_func ( x[0] , x[1] , x[2] ) ; }
124 
125  double Adapter3DoubleFunction::operator()
126  ( const double x ,
127  const double y ,
128  const double z ) const
129  { return m_func ( x , y , z ) ; }
130 
133  {
134  if ( i >= 3 )
135  {
136  const AbsFunction& aux = GaudiMath::Constant( 0 , 3 ) ;
137  return Genfun::FunctionNoop( &aux ) ;
138  };
139  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
140  return Genfun::FunctionNoop ( &aux ) ;
141  }
142 
143  // ========================================================================
145  // ========================================================================
146  FUNCTION_OBJECT_IMP( SimpleFunction )
147  // ========================================================================
148 
149  // =======================================================================
153  // ========================================================================
155  ( SimpleFunction::Function1 func )
156  : AbsFunction ()
157  , m_case ( SimpleFunction::TrivialArg )
158  , m_DIM ( 1 )
159  , m_func1 ( func )
160  , m_func2 ( 0 )
161  , m_func3 ( 0 )
162  , m_arg3 ( )
163  {}
164  // ========================================================================
165 
166  // ========================================================================
171  // ========================================================================
174  const size_t dim )
175  : AbsFunction ()
176  , m_case ( SimpleFunction::ArrayArg )
177  , m_DIM ( dim )
178  , m_func1 ( 0 )
179  , m_func2 ( func )
180  , m_arg2 ( new double[dim] )
181  , m_func3 ( 0 )
182  , m_arg3 ( )
183  {
184  }
185  // ========================================================================
186 
187  // ========================================================================
192  // ========================================================================
195  const size_t dim )
196  : AbsFunction ()
197  , m_case ( SimpleFunction::VectorArg )
198  , m_DIM ( dim )
199  , m_func1 ( 0 )
200  , m_func2 ( 0 )
201  , m_func3 ( func )
202  , m_arg3 ( dim , 0 )
203  {}
204  // ========================================================================
205 
206  // ========================================================================
208  // ========================================================================
210  ( const SimpleFunction& right )
211  : AbsFunction ()
212  , m_case ( right.m_case )
213  , m_DIM ( right.m_DIM )
214  , m_func1 ( right.m_func1 )
215  , m_func2 ( right.m_func2 )
216  , m_func3 ( right.m_func3 )
217  , m_arg3 ( right.m_arg3 )
218  {
219  if ( right.m_arg2 )
220  {
221  m_arg2.reset( new double[m_DIM] );
222  std::copy_n(right.m_arg2.get(), m_DIM, m_arg2.get());
223  }
224  }
225  // ========================================================================
226 
227  // ========================================================================
228 
229  // ========================================================================
231  // ========================================================================
233  {
234  if ( i >= m_DIM )
235  {
236  const AbsFunction& aux = GaudiMath::Constant( 0 , m_DIM ) ;
237  return Genfun::FunctionNoop( &aux ) ;
238  }
239  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
240  return Genfun::FunctionNoop( &aux );
241  }
242 
243  // ========================================================================
245  // ========================================================================
246  double SimpleFunction::operator() ( double value ) const
247  {
248  double result = 0 ;
249  switch ( m_case )
250  {
251  case TrivialArg :
252  result = (*m_func1) ( value ) ; break ;
253  case ArrayArg :
254  std::fill_n( m_arg2.get() , m_DIM , 0.0 );
255  m_arg2[0] = value ;
256  result = (*m_func2) ( m_arg2.get() ) ; break ;
257  case VectorArg :
258  std::fill ( m_arg3.begin () , m_arg3.end () , 0.0 );
259  m_arg3[0] = value ;
260  result = (*m_func3) ( m_arg3 ) ; break ;
261  default:
262  break ;
263  };
264  return result ;
265  }
266  // ========================================================================
267 
268  // ========================================================================
270  // ========================================================================
271  double SimpleFunction::operator() ( const Argument& argument ) const
272  {
273  double result = 0 ;
274  switch ( m_case )
275  {
276  case TrivialArg :
277  result = (*m_func1) ( argument[0] ) ; break ;
278  case ArrayArg :
279  for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg2[i] = argument[i] ; }
280  return (*m_func2)( m_arg2.get() ) ; ; break ;
281  case VectorArg :
282  for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg3[i] = argument[i] ; }
283  result = (*m_func3) ( m_arg3 ) ; break ;
284  default:
285  break ;
286  }
287  return result ;
288  }
289 
290  } // end of namespace GaudiMathImplementation
291 } // end of namespace Genfun
292 
293 
294 // ============================================================================
295 // The END
296 // ============================================================================
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:232
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Definition: Fill.cpp:36
virtual double operator()(double a) const
Definition: Adapter.cpp:36
virtual ~Adapter2DoubleFunction()
virtual destructor
Definition: Adapter.cpp:74
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:90
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:49
Genfun::AbsFunction Function
Definition: GaudiMath.h:24
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:132
GaudiKernel.
Definition: Fill.h:8
constructor from the trivial function with two argument
Definition: FunAdapters.h:91
virtual double operator()(double) const
Function value.
Definition: Adapter.cpp:246
virtual ~Adapter3DoubleFunction()
virtual destructor
Definition: Adapter.cpp:115
constructor from the trivial function with two argument
Definition: FunAdapters.h:154
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:207
CLHEP.
Definition: IEqSolver.h:13
list i
Definition: ana.py:128
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:27
constructor from the IFunction ( see AIDA/IFunction.h)
Definition: FunAdapters.h:31