Jpp 20.0.0-rc.2
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 JROOT {
14
15 /**
16 * Forward declaration of auxiliary class for copying ROOT histograms.
17 */
18 class JHistogramHelper;
19}
20
21namespace JTOOLS {}
22namespace JPP { using namespace JTOOLS; }
23
24namespace JTOOLS {
25
26 using JIO::JReader;
27 using JIO::JWriter;
28
29
30 /**
31 * Template definition of histogram object interface.
32 * This class also comprises auxiliary data.
33 */
34 template<class JAbscissa_t, class JContents_t>
36 {
37 protected:
38 /**
39 * Default constructor.
40 */
42 underflow(JMATH::zero),
43 overflow (JMATH::zero),
44 integral (JMATH::zero)
45 {}
46
47
48 public:
49
50 typedef JAbscissa_t abscissa_type;
51 typedef JContents_t contents_type;
52
53
54 /**
55 * Virtual destructor.
56 */
57 virtual ~JHistogram()
58 {}
59
60
61 /**
62 * Reset.
63 */
64 void reset()
65 {
66 this->underflow = JMATH::zero;
67 this->overflow = JMATH::zero;
68 this->integral = JMATH::zero;
69 }
70
71
72 /**
73 * Histogram filling.
74 *
75 * \param pX pointer to abscissa values
76 * \param w weight
77 */
78 virtual void evaluate(const abscissa_type* pX,
80
81
82 /**
83 * Add histogram.
84 *
85 * \param histogram histogram
86 * \return this histogram
87 */
88 JHistogram& add(const JHistogram& histogram)
89 {
90 this->underflow += histogram.underflow;
91 this->overflow += histogram.overflow;
92 this->integral += histogram.integral;
93
94 return *this;
95 }
96
97
98 /**
99 * Subtract histogram.
100 *
101 * \param histogram histogram
102 * \return this histogram
103 */
104 JHistogram& sub(const JHistogram& histogram)
105 {
106 this->underflow -= histogram.underflow;
107 this->overflow -= histogram.overflow;
108 this->integral -= histogram.integral;
109
110 return *this;
111 }
112
113
114 /**
115 * Scale histogram.
116 *
117 * \param value multiplication factor
118 * \return this histogram
119 */
120 JHistogram& mul(const double value)
121 {
122 this->underflow *= value;
123 this->overflow *= value;
124 this->integral *= value;
125
126 return *this;
127 }
128
129
130 /**
131 * Scale histogram.
132 *
133 * \param value division factor
134 * \return this histogram
135 */
136 JHistogram& div(double value)
137 {
138 this->underflow /= value;
139 this->overflow /= value;
140 this->integral /= value;
141
142 return *this;
143 }
144
145
146 /**
147 * Get contents below lower limit.
148 *
149 * \return contents
150 */
152 {
153 return underflow;
154 }
155
156
157 /**
158 * Get contents above upper limit.
159 *
160 * \return contents
161 */
163 {
164 return overflow;
165 }
166
167
168 /**
169 * Get contents above upper limit.
170 *
171 * \return contents
172 */
174 {
175 return integral;
176 }
177
178
179 /**
180 * Read histogram from input.
181 *
182 * \param in reader
183 * \param object histogram
184 * \return reader
185 */
186 friend inline JReader& operator>>(JReader& in, JHistogram& object)
187 {
188 in >> object.underflow;
189 in >> object.overflow;
190 in >> object.integral;
191
192 return in;
193 }
194
195
196 /**
197 * Write histogram to output.
198 *
199 * \param out writer
200 * \param object histogram
201 * \return writer
202 */
203 friend inline JWriter& operator<<(JWriter& out, const JHistogram& object)
204 {
205 out << object.underflow;
206 out << object.overflow;
207 out << object.integral;
208
209 return out;
210 }
211
212
213 /**
214 * Friend declaration of auxiliary class for copying ROOT histograms.
215 *
216 * \param from source
217 * \param to destination
218 */
220
221
222 protected:
226 };
227
228
229 /**
230 * Functional histogram cumulator.
231 */
232 struct JCumulator {
233 /**
234 * Default constructor.
235 */
237 {}
238
239
240 /**
241 * Compile function.
242 *
243 * \param function function
244 * \return this cumulator
245 */
246 template<class JHistogram_t>
247 const JCumulator& operator()(JHistogram_t& function) const
248 {
249 function.cumlative();
250
251 return *this;
252 }
253 };
254
255
256 /**
257 * Function object for functional object compilation.
258 */
259 static const JCumulator cumulator;
260}
261
262#endif
Definition of zero value for any class.
Interface for binary input.
Interface for binary output.
Auxiliary class for copying ROOT histograms to Jpp histograms.
Template definition of histogram object interface.
Definition JHistogram.hh:36
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:50
JHistogram & sub(const JHistogram &histogram)
Subtract histogram.
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:88
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:57
friend JWriter & operator<<(JWriter &out, const JHistogram &object)
Write histogram to output.
JHistogram()
Default constructor.
Definition JHistogram.hh:41
contents_type underflow
JContents_t contents_type
Definition JHistogram.hh:51
void reset()
Reset.
Definition JHistogram.hh:64
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 ROOT I/O.
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.