Jpp  test_elongated_shower_pde
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  * Reset.
55  */
56  void reset()
57  {
58  this->underflow = JMATH::zero;
59  this->overflow = JMATH::zero;
60  this->integral = JMATH::zero;
61  }
62 
63 
64  /**
65  * Histogram filling.
66  *
67  * \param pX pointer to abscissa values
68  * \param w weight
69  */
70  virtual void evaluate(const abscissa_type* pX,
72 
73 
74  /**
75  * Add histogram.
76  *
77  * \param histogram histogram
78  * \return this histogram
79  */
80  JHistogram& add(const JHistogram& histogram)
81  {
82  this->underflow += histogram.underflow;
83  this->overflow += histogram.overflow;
84  this->integral += histogram.integral;
85 
86  return *this;
87  }
88 
89 
90  /**
91  * Subtract histogram.
92  *
93  * \param histogram histogram
94  * \return this histogram
95  */
96  JHistogram& sub(const JHistogram& histogram)
97  {
98  this->underflow -= histogram.underflow;
99  this->overflow -= histogram.overflow;
100  this->integral -= histogram.integral;
101 
102  return *this;
103  }
104 
105 
106  /**
107  * Scale histogram.
108  *
109  * \param value multiplication factor
110  * \return this histogram
111  */
112  JHistogram& mul(const double value)
113  {
114  this->underflow *= value;
115  this->overflow *= value;
116  this->integral *= value;
117 
118  return *this;
119  }
120 
121 
122  /**
123  * Scale histogram.
124  *
125  * \param value division factor
126  * \return this histogram
127  */
128  JHistogram& div(double value)
129  {
130  this->underflow /= value;
131  this->overflow /= value;
132  this->integral /= value;
133 
134  return *this;
135  }
136 
137 
138  /**
139  * Get contents below lower limit.
140  *
141  * \return contents
142  */
144  {
145  return underflow;
146  }
147 
148 
149  /**
150  * Get contents above upper limit.
151  *
152  * \return contents
153  */
154  const contents_type& getOverflow() const
155  {
156  return overflow;
157  }
158 
159 
160  /**
161  * Get contents above upper limit.
162  *
163  * \return contents
164  */
165  const contents_type& getIntegral() const
166  {
167  return integral;
168  }
169 
170 
171  /**
172  * Read histogram from input.
173  *
174  * \param in reader
175  * \param object histogram
176  * \return reader
177  */
178  friend inline JReader& operator>>(JReader& in, JHistogram& object)
179  {
180  in >> object.underflow;
181  in >> object.overflow;
182  in >> object.integral;
183 
184  return in;
185  }
186 
187 
188  /**
189  * Write histogram to output.
190  *
191  * \param out writer
192  * \param object histogram
193  * \return writer
194  */
195  friend inline JWriter& operator<<(JWriter& out, const JHistogram& object)
196  {
197  out << object.underflow;
198  out << object.overflow;
199  out << object.integral;
200 
201  return out;
202  }
203 
204 
205  protected:
209  };
210 
211 
212  /**
213  * Functional histogram cumulator.
214  */
215  struct JCumulator {
216  /**
217  * Default constructor.
218  */
220  {}
221 
222 
223  /**
224  * Compile function.
225  *
226  * \param function function
227  * \return this cumulator
228  */
229  template<class JHistogram_t>
230  const JCumulator& operator()(JHistogram_t& function) const
231  {
232  function.cumlative();
233 
234  return *this;
235  }
236  };
237 
238 
239  /**
240  * Function object for functional object compilation.
241  */
242  static const JCumulator cumulator;
243 }
244 
245 #endif
JHistogram & div(double value)
Scale histogram.
Definition: JHistogram.hh:128
const contents_type & getUnderflow() const
Get contents below lower limit.
Definition: JHistogram.hh:143
const contents_type & getIntegral() const
Get contents above upper limit.
Definition: JHistogram.hh:165
data_type w[N+1][M+1]
Definition: JPolint.hh:757
Interface for binary output.
const contents_type & getOverflow() const
Get contents above upper limit.
Definition: JHistogram.hh:154
contents_type underflow
Definition: JHistogram.hh:206
static const JCumulator cumulator
Function object for functional object compilation.
Definition: JHistogram.hh:242
friend JReader & operator>>(JReader &in, JHistogram &object)
Read histogram from input.
Definition: JHistogram.hh:178
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:80
const JCumulator & operator()(JHistogram_t &function) const
Compile function.
Definition: JHistogram.hh:230
contents_type integral
Definition: JHistogram.hh:208
JHistogram & sub(const JHistogram &histogram)
Subtract histogram.
Definition: JHistogram.hh:96
JHistogram & mul(const double value)
Scale histogram.
Definition: JHistogram.hh:112
JAbscissa_t abscissa_type
Definition: JHistogram.hh:42
Interface for binary input.
JCumulator()
Default constructor.
Definition: JHistogram.hh:219
Functional histogram cumulator.
Definition: JHistogram.hh:215
void reset()
Reset.
Definition: JHistogram.hh:56
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:42
contents_type overflow
Definition: JHistogram.hh:207
JContents_t contents_type
Definition: JHistogram.hh:43
friend JWriter & operator<<(JWriter &out, const JHistogram &object)
Write histogram to output.
Definition: JHistogram.hh:195
virtual ~JHistogram()
Virtual destructor.
Definition: JHistogram.hh:49
Template definition of histogram object interface.
Definition: JHistogram.hh:27