Jpp  debug
the software that should make you happy
JMathlib3D.hh
Go to the documentation of this file.
1 #ifndef __JMATH__JMATHLIB3D__
2 #define __JMATH__JMATHLIB3D__
3 
4 #include "JMath/JMathlib.hh"
5 
6 /**
7  * \file
8  * Functional algebra in 3D.
9  *
10  * \author mdejong
11  */
12 
13 namespace JMATH {}
14 namespace JPP { using namespace JMATH; }
15 
16 namespace JMATH {
17 
18  /**
19  * Make 3D function of x from 1D function.
20  */
21  template<class JF1_t>
22  struct JMake3X :
23  public JMathlib< JMake3X<JF1_t> >,
24  public JF1_t
25  {
26  using JMathlib< JMake3X<JF1_t> >::operator();
27 
28 
29  /**
30  * Default constructor.
31  */
33  {}
34 
35 
36  /**
37  * Constructor.
38  *
39  * \param f1 function
40  */
41  JMake3X(const JF1_t& f1) :
42  JF1_t(f1)
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param args list of values
50  */
51  template<class ...Args>
52  JMake3X(const Args& ...args) :
53  JF1_t(args...)
54  {}
55 
56 
57  /**
58  * Function value.
59  *
60  * \param x abscissa value
61  * \param y abscissa value
62  * \param z abscissa value
63  * \return function value
64  */
65  double getValue(const double x, const double y, const double z) const
66  {
67  return static_cast<const JF1_t&>(*this).getValue(x);
68  }
69 
70 
71  /**
72  * Get gradient.
73  *
74  * \param x abscissa value
75  * \param y abscissa value
76  * \param z abscissa value
77  * \return gradient
78  */
79  const JMake3X& getGradient(const double x, const double y, const double z) const
80  {
81  static JMake3X gradient;
82 
83  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(x);
84 
85  return gradient;
86  }
87  };
88 
89 
90  /**
91  * Make 3D function of y from 1D function.
92  */
93  template<class JF1_t>
94  struct JMake3Y :
95  public JMathlib< JMake3Y<JF1_t> >,
96  public JF1_t
97  {
98  using JMathlib< JMake3Y<JF1_t> >::operator();
99 
100 
101  /**
102  * Default constructor.
103  */
105  {}
106 
107 
108  /**
109  * Constructor.
110  *
111  * \param f1 function
112  */
113  JMake3Y(const JF1_t& f1) :
114  JF1_t(f1)
115  {}
116 
117 
118  /**
119  * Constructor.
120  *
121  * \param args list of values
122  */
123  template<class ...Args>
124  JMake3Y(const Args& ...args) :
125  JF1_t(args...)
126  {}
127 
128 
129  /**
130  * Function value.
131  *
132  * \param x abscissa value
133  * \param y abscissa value
134  * \param z abscissa value
135  * \return function value
136  */
137  double getValue(const double x, const double y, const double z) const
138  {
139  return static_cast<const JF1_t&>(*this).getValue(y);
140  }
141 
142 
143  /**
144  * Get gradient.
145  *
146  * \param x abscissa value
147  * \param y abscissa value
148  * \param z abscissa value
149  * \return gradient
150  */
151  const JMake3Y& getGradient(const double x, const double y, const double z) const
152  {
153  static JMake3Y gradient;
154 
155  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(y);
156 
157  return gradient;
158  }
159  };
160 
161 
162  /**
163  * Make 3D function of z from 1D function.
164  */
165  template<class JF1_t>
166  struct JMake3Z :
167  public JMathlib< JMake3Z<JF1_t> >,
168  public JF1_t
169  {
170  using JMathlib< JMake3Z<JF1_t> >::operator();
171 
172 
173  /**
174  * Default constructor.
175  */
177  {}
178 
179 
180  /**
181  * Constructor.
182  *
183  * \param f1 function
184  */
185  JMake3Z(const JF1_t& f1) :
186  JF1_t(f1)
187  {}
188 
189 
190  /**
191  * Constructor.
192  *
193  * \param args list of values
194  */
195  template<class ...Args>
196  JMake3Z(const Args& ...args) :
197  JF1_t(args...)
198  {}
199 
200 
201  /**
202  * Function value.
203  *
204  * \param x abscissa value
205  * \param y abscissa value
206  * \param z abscissa value
207  * \return function value
208  */
209  double getValue(const double x, const double y, const double z) const
210  {
211  return static_cast<const JF1_t&>(*this).getValue(z);
212  }
213 
214 
215  /**
216  * Get gradient.
217  *
218  * \param x abscissa value
219  * \param y abscissa value
220  * \param z abscissa value
221  * \return gradient
222  */
223  const JMake3Z& getGradient(const double x, const double y, const double z) const
224  {
225  static JMake3Z gradient;
226 
227  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(z);
228 
229  return gradient;
230  }
231  };
232 
233 
234  template<int ID_t, size_t N> using JPolynome3X = JMake3X< JPolynome<ID_t, N> >; //!< 3D polynomial function of x.
235  template<int ID_t, size_t N> using JPolynome3Y = JMake3Y< JPolynome<ID_t, N> >; //!< 3D polynomial function of y.
236  template<int ID_t, size_t N> using JPolynome3Z = JMake3Z< JPolynome<ID_t, N> >; //!< 3D polynomial function of z.
237  template<int ID_t, bool normalise = false> using JGauss3X = JMake3X< JGauss<ID_t, normalise> >; //!< 3D Gauss function of x.
238  template<int ID_t, bool normalise = false> using JGauss3Y = JMake3Y< JGauss<ID_t, normalise> >; //!< 3D Gauss function of y.
239  template<int ID_t, bool normalise = false> using JGauss3Z = JMake3Z< JGauss<ID_t, normalise> >; //!< 3D Gauss function of z.
240  template<int ID_t, class JF1_t = _vF> using JPow3X = JMake3X< JPow<ID_t, JF1_t> >; //!< 3D power of function of x.
241  template<int ID_t, class JF1_t = _vF> using JPow3Y = JMake3Y< JPow<ID_t, JF1_t> >; //!< 3D power of function of y.
242  template<int ID_t, class JF1_t = _vF> using JPow3Z = JMake3Z< JPow<ID_t, JF1_t> >; //!< 3D power of function of z.
243  template<int N> using JXn3X = JMake3X< JXn<N> >; //!< 3D fixed power of x.
244  template<int N> using JXn3Y = JMake3Y< JXn<N> >; //!< 3D fixed power of y.
245  template<int N> using JXn3Z = JMake3Z< JXn<N> >; //!< 3D fixed power of z.
246  template<class JF1_t = _vF> using JSqrt3X = JMake3X< JSqrt<JF1_t> >; //!< 3D square root of function of x.
247  template<class JF1_t = _vF> using JSqrt3Y = JMake3Y< JSqrt<JF1_t> >; //!< 3D square root of function of y.
248  template<class JF1_t = _vF> using JSqrt3Z = JMake3Z< JSqrt<JF1_t> >; //!< 3D square root of function of z.
249  template<class JF1_t> using JSin3X = JMake3X< JSin<JF1_t> >; //!< 3D sine of function of x.
250  template<class JF1_t> using JSin3Y = JMake3Y< JSin<JF1_t> >; //!< 3D sine of function of y.
251  template<class JF1_t> using JSin3Z = JMake3Z< JSin<JF1_t> >; //!< 3D sine of function of z.
252  template<class JF1_t> using JCos3X = JMake3X< JCos<JF1_t> >; //!< 3D cosine of function of x.
253  template<class JF1_t> using JCos3Y = JMake3Y< JCos<JF1_t> >; //!< 3D cosine of function of y.
254  template<class JF1_t> using JCos3Z = JMake3Z< JCos<JF1_t> >; //!< 3D cosine of function of z.
255  template<class JF1_t> using JExp3X = JMake3X< JExp<JF1_t> >; //!< 3D exponent of function of x.
256  template<class JF1_t> using JExp3Y = JMake3Y< JExp<JF1_t> >; //!< 3D exponent of function of y.
257  template<class JF1_t> using JExp3Z = JMake3Z< JExp<JF1_t> >; //!< 3D exponent of function of z.
258  template<class JF1_t> using JLog3X = JMake3X< JLog<JF1_t> >; //!< 3D logarithm of function of x.
259  template<class JF1_t> using JLog3Y = JMake3Y< JLog<JF1_t> >; //!< 3D logarithm of function of y.
260  template<class JF1_t> using JLog3Z = JMake3Z< JLog<JF1_t> >; //!< 3D logarithm of function of z.
261 
262 
263  /**
264  * 3D correlated Gauss function.
265  */
266  template<int ID_t, bool normalise = false>
267  struct JGauss3D :
268  public JMathlib< JGauss3D<ID_t, normalise> >,
269  public JGauss<ID_t, normalise>
270  {
271  using JMathlib< JGauss3D<ID_t, normalise> >::operator();
272 
273 
274  /**
275  * Default constructor.
276  */
278  {}
279 
280 
281  /**
282  * Constructor.
283  *
284  * \param mean mean
285  * \param sigma sigma
286  */
287  JGauss3D(const double mean,
288  const double sigma) :
289  JGauss<ID_t, normalise>(mean, sigma)
290  {}
291 
292 
293  /**
294  * Function value.
295  *
296  * \param x abscissa value
297  * \param y abscissa value
298  * \param z abscissa value
299  * \return function value
300  */
301  double getValue(const double x, const double y, const double z) const
302  {
304 
305  return (static_cast<const JGauss_t&>(*this).getValue(x) *
306  static_cast<const JGauss_t&>(*this).getValue(y) *
307  static_cast<const JGauss_t&>(*this).getValue(z));
308  }
309 
310 
311  /**
312  * Get gradient.
313  *
314  * \param x abscissa value
315  * \param y abscissa value
316  * \param z abscissa value
317  * \return gradient
318  */
319  const JGauss3D& getGradient(const double x, const double y, const double z) const
320  {
321  static JGauss3D gradient;
322 
324 
325  static_cast<JGauss_t&>(gradient) = JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(x)).mul(static_cast<const JGauss_t&>(*this).getValue(y) * static_cast<const JGauss_t&>(*this).getValue(z));
326  static_cast<JGauss_t&>(gradient) += JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(y)).mul(static_cast<const JGauss_t&>(*this).getValue(x) * static_cast<const JGauss_t&>(*this).getValue(z));
327  static_cast<JGauss_t&>(gradient) += JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(z)).mul(static_cast<const JGauss_t&>(*this).getValue(x) * static_cast<const JGauss_t&>(*this).getValue(y));
328 
329  return gradient;
330  }
331  };
332 }
333 
334 #endif
Functional algebra.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
Auxiliary classes and methods for mathematical operations.
Definition: JEigen3D.hh:88
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
3D correlated Gauss function.
Definition: JMathlib3D.hh:270
const JGauss3D & getGradient(const double x, const double y, const double z) const
Get gradient.
Definition: JMathlib3D.hh:319
double getValue(const double x, const double y, const double z) const
Function value.
Definition: JMathlib3D.hh:301
JGauss3D()
Default constructor.
Definition: JMathlib3D.hh:277
JGauss3D(const double mean, const double sigma)
Constructor.
Definition: JMathlib3D.hh:287
Gauss model.
Definition: JGauss.hh:32
JGauss_t & mul(const double factor)
Scale gauss.
Definition: JGauss.hh:120
JGauss_t()
Default constructor.
Definition: JGauss.hh:36
double mean
Definition: JGauss.hh:161
Gauss function object.
Definition: JGauss.hh:175
Make 3D function of x from 1D function.
Definition: JMathlib3D.hh:25
const JMake3X & getGradient(const double x, const double y, const double z) const
Get gradient.
Definition: JMathlib3D.hh:79
double getValue(const double x, const double y, const double z) const
Function value.
Definition: JMathlib3D.hh:65
JMake3X(const Args &...args)
Constructor.
Definition: JMathlib3D.hh:52
JMake3X(const JF1_t &f1)
Constructor.
Definition: JMathlib3D.hh:41
JMake3X()
Default constructor.
Definition: JMathlib3D.hh:32
Make 3D function of y from 1D function.
Definition: JMathlib3D.hh:97
const JMake3Y & getGradient(const double x, const double y, const double z) const
Get gradient.
Definition: JMathlib3D.hh:151
JMake3Y()
Default constructor.
Definition: JMathlib3D.hh:104
JMake3Y(const JF1_t &f1)
Constructor.
Definition: JMathlib3D.hh:113
JMake3Y(const Args &...args)
Constructor.
Definition: JMathlib3D.hh:124
double getValue(const double x, const double y, const double z) const
Function value.
Definition: JMathlib3D.hh:137
Make 3D function of z from 1D function.
Definition: JMathlib3D.hh:169
JMake3Z()
Default constructor.
Definition: JMathlib3D.hh:176
JMake3Z(const JF1_t &f1)
Constructor.
Definition: JMathlib3D.hh:185
JMake3Z(const Args &...args)
Constructor.
Definition: JMathlib3D.hh:196
const JMake3Z & getGradient(const double x, const double y, const double z) const
Get gradient.
Definition: JMathlib3D.hh:223
double getValue(const double x, const double y, const double z) const
Function value.
Definition: JMathlib3D.hh:209
forward declaration for fixed power of function.
Definition: JMathlib.hh:354