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