Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
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"
7
8
9/**
10 * \author mdejong
11 */
12
13namespace JTOOLS {}
14namespace JPP { using namespace JTOOLS; }
15
16namespace 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>
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 */
155 {
156 return overflow;
157 }
158
159
160 /**
161 * Get contents above upper limit.
162 *
163 * \return contents
164 */
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
Definition of zero value for any class.
Interface for binary input.
Interface for binary output.
Template definition of histogram object interface.
Definition JHistogram.hh:28
contents_type overflow
contents_type integral
JHistogram & mul(const double value)
Scale histogram.
friend JReader & operator>>(JReader &in, JHistogram &object)
Read histogram from input.
JAbscissa_t abscissa_type
Definition JHistogram.hh:42
JHistogram & sub(const JHistogram &histogram)
Subtract histogram.
Definition JHistogram.hh:96
virtual void evaluate(const abscissa_type *pX, typename JLANG::JClass< contents_type >::argument_type w)=0
Histogram filling.
JHistogram & add(const JHistogram &histogram)
Add histogram.
Definition JHistogram.hh:80
const contents_type & getOverflow() const
Get contents above upper limit.
const contents_type & getUnderflow() const
Get contents below lower limit.
JHistogram & div(double value)
Scale histogram.
const contents_type & getIntegral() const
Get contents above upper limit.
virtual ~JHistogram()
Virtual destructor.
Definition JHistogram.hh:49
friend JWriter & operator<<(JWriter &out, const JHistogram &object)
Write histogram to output.
JHistogram()
Default constructor.
Definition JHistogram.hh:33
contents_type underflow
JContents_t contents_type
Definition JHistogram.hh:43
void reset()
Reset.
Definition JHistogram.hh:56
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
static const JCumulator cumulator
Function object for functional object compilation.
JArgument< T >::argument_type argument_type
Definition JClass.hh:82
Functional histogram cumulator.
JCumulator()
Default constructor.
const JCumulator & operator()(JHistogram_t &function) const
Compile function.