Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHistogram.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JHISTOGRAM__
2 #define __JTOOLS__JHISTOGRAM__
3 
4 #include "JLang/JClass.hh"
5 #include "JMath/JZero.hh"
6 #include "JIO/JSerialisable.hh"
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JTOOLS {}
14 namespace JPP { using namespace JTOOLS; }
15 
16 namespace JTOOLS {
17 
18  using JIO::JReader;
19  using JIO::JWriter;
20 
21 
22  /**
23  * Template definition of histogram object interface.
24  * This class also comprises auxiliary data.
25  */
26  template<class JAbscissa_t, class JContents_t>
27  class JHistogram
28  {
29  protected:
30  /**
31  * Default constructor.
32  */
34  underflow(JMATH::zero),
35  overflow (JMATH::zero),
36  integral (JMATH::zero)
37  {}
38 
39 
40  public:
41 
42  typedef JAbscissa_t abscissa_type;
43  typedef JContents_t contents_type;
44 
45 
46  /**
47  * Virtual destructor.
48  */
49  virtual ~JHistogram()
50  {}
51 
52 
53  /**
54  * Histogram filling.
55  *
56  * \param pX pointer to abscissa values
57  * \param w weight
58  */
59  virtual void evaluate(const abscissa_type* pX,
61 
62 
63  /**
64  * Add histogram.
65  *
66  * \param histogram histogram
67  * \return this histogram
68  */
69  JHistogram& add(const JHistogram& histogram)
70  {
71  this->underflow += histogram.underflow;
72  this->overflow += histogram.overflow;
73  this->integral += histogram.integral;
74 
75  return *this;
76  }
77 
78 
79  /**
80  * Subtract histogram.
81  *
82  * \param histogram histogram
83  * \return this histogram
84  */
85  JHistogram& sub(const JHistogram& histogram)
86  {
87  this->underflow -= histogram.underflow;
88  this->overflow -= histogram.overflow;
89  this->integral -= histogram.integral;
90 
91  return *this;
92  }
93 
94 
95  /**
96  * Scale histogram.
97  *
98  * \param value multiplication factor
99  * \return this histogram
100  */
101  JHistogram& mul(const double value)
102  {
103  this->underflow *= value;
104  this->overflow *= value;
105  this->integral *= value;
106 
107  return *this;
108  }
109 
110 
111  /**
112  * Scale histogram.
113  *
114  * \param value division factor
115  * \return this histogram
116  */
117  JHistogram& div(double value)
118  {
119  this->underflow /= value;
120  this->overflow /= value;
121  this->integral /= value;
122 
123  return *this;
124  }
125 
126 
127  /**
128  * Get contents below lower limit.
129  *
130  * \return contents
131  */
133  {
134  return underflow;
135  }
136 
137 
138  /**
139  * Get contents above upper limit.
140  *
141  * \return contents
142  */
143  const contents_type& getOverflow() const
144  {
145  return overflow;
146  }
147 
148 
149  /**
150  * Get contents above upper limit.
151  *
152  * \return contents
153  */
154  const contents_type& getIntegral() const
155  {
156  return integral;
157  }
158 
159 
160  /**
161  * Read histogram from input.
162  *
163  * \param in reader
164  * \param object histogram
165  * \return reader
166  */
167  friend inline JReader& operator>>(JReader& in, JHistogram& object)
168  {
169  in >> object.underflow;
170  in >> object.overflow;
171  in >> object.integral;
172 
173  return in;
174  }
175 
176 
177  /**
178  * Write histogram to output.
179  *
180  * \param out writer
181  * \param object histogram
182  * \return writer
183  */
184  friend inline JWriter& operator<<(JWriter& out, const JHistogram& object)
185  {
186  out << object.underflow;
187  out << object.overflow;
188  out << object.integral;
189 
190  return out;
191  }
192 
193 
194  protected:
198  };
199 
200 
201  /**
202  * Functional histogram cumulator.
203  */
204  struct JCumulator {
205  /**
206  * Default constructor.
207  */
209  {}
210 
211 
212  /**
213  * Compile function.
214  *
215  * \param function function
216  * \return this cumulator
217  */
218  template<class JHistogram_t>
219  const JCumulator& operator()(JHistogram_t& function) const
220  {
221  function.cumlative();
222 
223  return *this;
224  }
225  };
226 
227 
228  /**
229  * Function object for functional object compilation.
230  */
231  static const JCumulator cumulator;
232 }
233 
234 #endif
JHistogram & div(double value)
Scale histogram.
Definition: JHistogram.hh:117
const contents_type & getUnderflow() const
Get contents below lower limit.
Definition: JHistogram.hh:132
const contents_type & getIntegral() const
Get contents above upper limit.
Definition: JHistogram.hh:154
data_type w[N+1][M+1]
Definition: JPolint.hh:741
Interface for binary output.
const contents_type & getOverflow() const
Get contents above upper limit.
Definition: JHistogram.hh:143
contents_type underflow
Definition: JHistogram.hh:195
static const JCumulator cumulator
Function object for functional object compilation.
Definition: JHistogram.hh:231
friend JReader & operator>>(JReader &in, JHistogram &object)
Read histogram from input.
Definition: JHistogram.hh:167
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Definition of zero value for any class.
virtual void evaluate(const abscissa_type *pX, typename JLANG::JClass< contents_type >::argument_type w)=0
Histogram filling.
JHistogram()
Default constructor.
Definition: JHistogram.hh:33
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JHistogram & add(const JHistogram &histogram)
Add histogram.
Definition: JHistogram.hh:69
const JCumulator & operator()(JHistogram_t &function) const
Compile function.
Definition: JHistogram.hh:219
contents_type integral
Definition: JHistogram.hh:197
JHistogram & sub(const JHistogram &histogram)
Subtract histogram.
Definition: JHistogram.hh:85
JHistogram & mul(const double value)
Scale histogram.
Definition: JHistogram.hh:101
JAbscissa_t abscissa_type
Definition: JHistogram.hh:42
Interface for binary input.
JCumulator()
Default constructor.
Definition: JHistogram.hh:208
Functional histogram cumulator.
Definition: JHistogram.hh:204
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
contents_type overflow
Definition: JHistogram.hh:196
JContents_t contents_type
Definition: JHistogram.hh:43
friend JWriter & operator<<(JWriter &out, const JHistogram &object)
Write histogram to output.
Definition: JHistogram.hh:184
virtual ~JHistogram()
Virtual destructor.
Definition: JHistogram.hh:49
Template definition of histogram object interface.
Definition: JHistogram.hh:27