Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JElement.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JELEMENT__
2 #define __JTOOLS__JELEMENT__
3 
4 #include <cmath>
5 
6 #include "JMath/JZero.hh"
7 #include "JMath/JMath.hh"
8 #include "JLang/JClass.hh"
9 #include "JIO/JSerialisable.hh"
10 
11 
12 /**
13  * \file
14  *
15  * The elements in a collection are sorted according to their abscissa values and a given distance operator.
16  * These elements should have the following type definitions and member methods:
17  * <pre>
18  * typedef <abscissa type> abscissa_type;
19  * typedef <ordinate type> ordinate_type;
20  *
21  * constructor();
22  * constructor(abscissa_type, ordinate_type);
23  *
24  * abscissa_type getX() const;
25  * const ordinate_type& getY() const;
26  * ordinate_type& getY();
27  * </pre>
28  * \author mdejong
29  */
30 
31 namespace JTOOLS {}
32 namespace JPP { using namespace JTOOLS; }
33 
34 namespace JTOOLS {
35 
36  using JIO::JReader;
37  using JIO::JWriter;
38  using JMATH::getZero;
39 
40  /**
41  * 2D Element.
42  */
43  template<class JAbscissa_t, class JOrdinate_t>
44  class JElement2D {
45  public:
46 
47  typedef JAbscissa_t abscissa_type;
48  typedef JOrdinate_t ordinate_type;
49 
50 
51  /**
52  * Default constructor.
53  */
57  {}
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param x abscissa value
64  * \param y ordinate value
65  */
68  __x(x),
69  __y(y)
70  {}
71 
72 
73  /**
74  * Get abscissa value.
75  *
76  * \return abscissa value
77  */
79  {
80  return __x;
81  }
82 
83 
84  /**
85  * Get ordinate value.
86  *
87  * \return ordinate value
88  */
89  const ordinate_type& getY() const
90  {
91  return __y;
92  }
93 
94 
95  /**
96  * Get ordinate value.
97  *
98  * \return ordinate value
99  */
101  {
102  return __y;
103  }
104 
105 
106  /**
107  * Read element from input.
108  *
109  * \param in reader
110  * \param element element
111  * \return reader
112  */
113  friend inline JReader& operator>>(JReader& in, JElement2D& element)
114  {
115  in >> element.__x;
116  in >> element.__y;
117 
118  return in;
119  }
120 
121 
122  /**
123  * Write element to output.
124  *
125  * \param out writer
126  * \param element element
127  * \return writer
128  */
129  friend inline JWriter& operator<<(JWriter& out, const JElement2D& element)
130  {
131  out << element.__x;
132  out << element.__y;
133 
134  return out;
135  }
136 
137 
138  protected:
141  };
142 
143 
144  /**
145  * 2D Element for spline interpolations.
146  *
147  * Note that the internal data members needed for the calculation
148  * of the 2nd derivatives are not subject to I/O, i.e. the I/O of
149  * this class is identical to that of the JElement2D class.
150  */
151  template<class JAbscissa_t, class JOrdinate_t>
153  public JElement2D<JAbscissa_t, JOrdinate_t>
154  {
155  public:
156 
160 
161 
162  /**
163  * Default constructor.
164  */
166  element_type(),
168  {}
169 
170 
171  /**
172  * Constructor.
173  *
174  * \param x abscissa value
175  * \param y ordinate value
176  */
179  element_type(x, y),
181  {}
182 
183 
184  /**
185  * Get derivative.
186  *
187  * \return derivative
188  */
190  {
191  return __u;
192  }
193 
194 
195  /**
196  * Set derivative.
197  *
198  * \param u derivative
199  */
201  {
202  __u= u;
203  }
204 
205 
206  protected:
208  };
209 
210 
211  /**
212  * 2D Element for spline interpolations.
213  *
214  * Note that the internal data members needed for the calculation
215  * of the integral values are not subject to I/O, i.e. the I/O of
216  * this class is identical to that of the JElement2D class.
217  */
218  template<class JAbscissa_t, class JOrdinate_t>
220  public JSplineElement2D<JAbscissa_t, JOrdinate_t>
221  {
222  public:
223 
227 
228 
229  /**
230  * Default constructor.
231  */
233  element_type(),
235  {}
236 
237 
238  /**
239  * Constructor.
240  *
241  * \param x abscissa value
242  * \param y ordinate value
243  */
246  element_type(x, y),
248  {}
249 
250 
251  /**
252  * Get integral.
253  *
254  * \return integral
255  */
257  {
258  return __v;
259  }
260 
261 
262  /**
263  * Set integral.
264  *
265  * \param v integral
266  */
268  {
269  __v = v;
270  }
271 
272 
273  protected:
275  };
276 
277 
278  /**
279  * 2D Element for polynomial interpolations.
280  *
281  * Note that the internal data members needed for the calculation
282  * of the integral values are not subject to I/O, i.e. the I/O of
283  * this class is identical to that of the JElement2D class.
284  */
285  template<class JAbscissa_t, class JOrdinate_t>
287  public JElement2D<JAbscissa_t, JOrdinate_t>
288  {
289  public:
290 
294 
295 
296  /**
297  * Default constructor.
298  */
300  element_type(),
302  {}
303 
304 
305  /**
306  * Constructor.
307  *
308  * \param x abscissa value
309  * \param y ordinate value
310  */
313  element_type(x, y),
315  {}
316 
317 
318  /**
319  * Get integral.
320  *
321  * \return integral
322  */
324  {
325  return __v;
326  }
327 
328 
329  /**
330  * Set integral.
331  *
332  * \param v integral
333  */
335  {
336  __v = v;
337  }
338 
339 
340  protected:
342  };
343 
344 
345  /**
346  * 2D Binned element.
347  *
348  * Note that the internal data members needed for the calculation
349  * of the bin center are not subject to I/O, i.e. the I/O of
350  * this class is identical to that of the JElement2D class.
351  */
352  template<class JAbscissa_t, class JOrdinate_t>
353  class JBin2D :
354  public JElement2D<JAbscissa_t, JOrdinate_t>,
355  public JMATH::JMath< JBin2D<JAbscissa_t, JOrdinate_t> >
356  {
357  public:
358 
359 
363 
364 
365  /**
366  * Default constructor.
367  */
368  JBin2D() :
369  element_type(),
372  {}
373 
374 
375  /**
376  * Constructor.
377  *
378  * \param x abscissa value
379  * \param y ordinate value
380  */
383  element_type(x,y),
386  {}
387 
388 
389  /**
390  * Add abscissa value.
391  *
392  * \param x abscissa value
393  * \param w weight
394  */
397  {
398  this->__y += w;
399  this->__z += w * x;
400  this->__w2 += w * w;
401  }
402 
403 
404  /**
405  * Get bin center.
406  *
407  * \return center
408  */
410  {
411  if (this->__y != 0)
412  return this->__z / this->__y;
413  else
414  return this->__x;
415  }
416 
417 
418  /**
419  * Get bin content.
420  *
421  * \return content
422  */
424  {
425  return this->__y;
426  }
427 
428 
429  /**
430  * Get bin error.
431  *
432  * \return error
433  */
435  {
436  return sqrt(this->__w2);
437  }
438 
439 
440  /**
441  * Add bin.
442  *
443  * \param bin bin
444  * \return this bin
445  */
446  JBin2D& add(const JBin2D& bin)
447  {
448  this->__y += bin.__y;
449  this->__z += bin.__zl;
450  this->__w2 += bin.__w2;
451 
452  return *this;
453  }
454 
455 
456  /**
457  * Scale contents.
458  *
459  * \param value multiplication factor
460  * \return this bin
461  */
462  JBin2D& mul(const double value)
463  {
464  this->__y *= value;
465  this->__z *= value;
466  this->__w2 *= value*value;
467 
468  return *this;
469  }
470 
471 
472  /**
473  * Scale contents.
474  *
475  * \param value division factor
476  * \return this bin
477  */
478  JBin2D& div(const double value)
479  {
480  this->__y /= value;
481  this->__z /= value;
482  this->__w2 /= value*value;
483 
484  return *this;
485  }
486 
487 
488  protected:
491  };
492 
493 
494  /**
495  * 3D Element.
496  */
497  template<class JAbscissa_t, class JOrdinate_t>
498  class JElement3D {
499  public:
500 
501  typedef JAbscissa_t abscissa_type;
502  typedef JOrdinate_t ordinate_type;
503 
504 
505  /**
506  * Default constructor.
507  */
512  {}
513 
514 
515  /**
516  * Constructor.
517  *
518  * \param x abscissa value
519  * \param y abscissa value
520  * \param z ordinate value
521  */
525  __x(x),
526  __y(y),
527  __z(z)
528  {}
529 
530 
531  /**
532  * Get abscissa value.
533  *
534  * \return abscissa value
535  */
537  {
538  return __x;
539  }
540 
541 
542  /**
543  * Get abscissa value.
544  *
545  * \return abscissa value
546  */
548  {
549  return __y;
550  }
551 
552 
553  /**
554  * Get ordinate value.
555  *
556  * \return ordinate value
557  */
558  const ordinate_type& getZ() const
559  {
560  return __y;
561  }
562 
563 
564  /**
565  * Get ordinate value.
566  *
567  * \return ordinate value
568  */
570  {
571  return __y;
572  }
573 
574 
575  /**
576  * Read element from input.
577  *
578  * \param in reader
579  * \param element element
580  * \return reader
581  */
582  friend inline JReader& operator>>(JReader& in, JElement3D& element)
583  {
584  in >> element.__x;
585  in >> element.__y;
586  in >> element.__z;
587 
588  return in;
589  }
590 
591 
592  /**
593  * Write element to output.
594  *
595  * \param out writer
596  * \param element element
597  * \return writer
598  */
599  friend inline JWriter& operator<<(JWriter& out, const JElement3D& element)
600  {
601  out << element.__x;
602  out << element.__y;
603  out << element.__z;
604 
605  return out;
606  }
607 
608 
609  protected:
613  };
614 }
615 
616 #endif
ordinate_type __z
Definition: JElement.hh:489
JPolintElement2S(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:311
friend JWriter & operator<<(JWriter &out, const JElement3D &element)
Write element to output.
Definition: JElement.hh:599
const ordinate_type & getZ() const
Get ordinate value.
Definition: JElement.hh:558
2D Element for spline interpolations.
Definition: JElement.hh:219
2D Element for polynomial interpolations.
Definition: JElement.hh:286
Interface for binary output.
abscissa_type getX() const
Get abscissa value.
Definition: JElement.hh:78
ordinate_type __y
Definition: JElement.hh:140
2D Element.
Definition: JElement.hh:44
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
abscissa_type __x
Definition: JElement.hh:610
JSplineElement2D()
Default constructor.
Definition: JElement.hh:165
JBin2D()
Default constructor.
Definition: JElement.hh:368
abscissa_type getBinCenter() const
Get bin center.
Definition: JElement.hh:409
JSplineElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:224
element_type::ordinate_type ordinate_type
Definition: JElement.hh:362
ordinate_type & getY()
Get ordinate value.
Definition: JElement.hh:100
2D Binned element.
Definition: JElement.hh:353
abscissa_type __x
Definition: JElement.hh:139
friend JReader & operator>>(JReader &in, JElement3D &element)
Read element from input.
Definition: JElement.hh:582
JBin2D & add(const JBin2D &bin)
Add bin.
Definition: JElement.hh:446
ordinate_type getBinError() const
Get bin error.
Definition: JElement.hh:434
Definition of zero value for any class.
JSplineElement2D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:177
JAbscissa_t abscissa_type
Definition: JElement.hh:501
JElement3D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< abscissa_type >::argument_type y, typename JLANG::JClass< ordinate_type >::argument_type z)
Constructor.
Definition: JElement.hh:522
JOrdinate_t ordinate_type
Definition: JElement.hh:48
JSplineElement2S()
Default constructor.
Definition: JElement.hh:232
ordinate_type getBinContent() const
Get bin content.
Definition: JElement.hh:423
T getZero()
Get zero value for a given data type.
Definition: JZero.hh:26
JArgument< T >::argument_type argument_type
Definition: JClass.hh:64
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:360
abscissa_type getY() const
Get abscissa value.
Definition: JElement.hh:547
JPolintElement2S()
Default constructor.
Definition: JElement.hh:299
void setIntegral(typename JLANG::JClass< ordinate_type >::argument_type v)
Set integral.
Definition: JElement.hh:267
ordinate_type & getZ()
Get ordinate value.
Definition: JElement.hh:569
3D Element.
Definition: JElement.hh:498
friend JWriter & operator<<(JWriter &out, const JElement2D &element)
Write element to output.
Definition: JElement.hh:129
JSplineElement2S(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:244
friend JReader & operator>>(JReader &in, JElement2D &element)
Read element from input.
Definition: JElement.hh:113
JElement2D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:66
ordinate_type __z
Definition: JElement.hh:612
element_type::abscissa_type abscissa_type
Definition: JElement.hh:361
Interface for binary input.
JBin2D & div(const double value)
Scale contents.
Definition: JElement.hh:478
element_type::abscissa_type abscissa_type
Definition: JElement.hh:292
ordinate_type getU() const
Get derivative.
Definition: JElement.hh:189
ordinate_type getIntegral() const
Get integral.
Definition: JElement.hh:323
ordinate_type getIntegral() const
Get integral.
Definition: JElement.hh:256
abscissa_type __y
Definition: JElement.hh:611
2D Element for spline interpolations.
Definition: JElement.hh:152
JBin2D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:381
void fill(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type w)
Add abscissa value.
Definition: JElement.hh:395
ordinate_type __w2
Definition: JElement.hh:490
JElement3D()
Default constructor.
Definition: JElement.hh:508
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:291
element_type::ordinate_type ordinate_type
Definition: JElement.hh:293
element_type::abscissa_type abscissa_type
Definition: JElement.hh:225
abscissa_type getX() const
Get abscissa value.
Definition: JElement.hh:536
JBin2D & mul(const double value)
Scale contents.
Definition: JElement.hh:462
Base class for data structures with artithmetic capabilities.
void setIntegral(typename JLANG::JClass< ordinate_type >::argument_type v)
Set integral.
Definition: JElement.hh:334
const ordinate_type & getY() const
Get ordinate value.
Definition: JElement.hh:89
void setU(typename JLANG::JClass< ordinate_type >::argument_type u)
Set derivative.
Definition: JElement.hh:200
element_type::abscissa_type abscissa_type
Definition: JElement.hh:158
JElement2D()
Default constructor.
Definition: JElement.hh:54
element_type::ordinate_type ordinate_type
Definition: JElement.hh:226
element_type::ordinate_type ordinate_type
Definition: JElement.hh:159
JAbscissa_t abscissa_type
Definition: JElement.hh:47
JOrdinate_t ordinate_type
Definition: JElement.hh:502
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:157