6 template<
typename T,
typename _Bin = T>
10 virtual std::size_t findBin(
const std::vector<_Bin>& values) = 0;
11 virtual std::size_t findClosestBin(
const std::vector<_Bin>& values,
bool* outOfRange =
nullptr) = 0;
12 virtual bool inRange(
const std::vector<_Bin>& values) = 0;
13 virtual std::vector<_Bin> clamp(
const std::vector<_Bin>& values) = 0;
15 T getBinContent(std::size_t bin) {
16 return m_values[bin - 1];
18 T getBinErrorLow(std::size_t bin) {
19 return m_errors_low[bin - 1];
21 T getBinErrorHigh(std::size_t bin) {
22 return m_errors_high[bin - 1];
25 void setBinContent(std::size_t bin, T value) {
26 m_values[bin - 1] = value;
28 void setBinErrorLow(std::size_t bin, T value) {
29 m_errors_low[bin - 1] = value;
31 void setBinErrorHigh(std::size_t bin, T value) {
32 m_errors_high[bin - 1] = value;
35 void setContent(
const std::vector<_Bin>& values, T content) {
36 size_t bin = findBin(values);
40 setBinContent(bin, content);
51 m_values.reset(
new T[m_size]);
52 m_errors_low.reset(
new T[m_size]);
53 m_errors_high.reset(
new T[m_size]);
56 static size_t findBin(
const std::vector<_Bin>& array, _Bin value) {
57 for (std::size_t i = 0; i < array.size() - 1; i++) {
58 if ((value >= array[i]) && (value < array[i + 1]))
65 static size_t findClosestBin(
const std::vector<_Bin>& array, _Bin value,
bool* outOfRange =
nullptr) {
69 if (value < array.front()) {
73 }
else if (value >= array.back()) {
76 return array.size() - 1;
78 return findBin(array, value);
82 static bool inRange(
const std::vector<_Bin>& array, _Bin value) {
83 _Bin min = array.front();
84 _Bin max = array.back();
86 return ((value >= min) && (value < max));
89 static _Bin clamp(
const std::vector<_Bin>& array, _Bin value) {
90 _Bin min = array.front();
91 _Bin max = array.back();
103 std::unique_ptr<T[]> m_values;
104 std::unique_ptr<T[]> m_errors_low;
105 std::unique_ptr<T[]> m_errors_high;
112 template<
typename T,
typename _Bin = T>
120 virtual std::size_t findBin(
const std::vector<_Bin>& values)
override {
121 if (values.size() != 1)
124 _Bin value = values[0];
129 virtual std::size_t findClosestBin(
const std::vector<_Bin>& values,
bool* outOfRange =
nullptr)
override {
130 if (values.size() != 1)
133 _Bin value = values[0];
138 virtual bool inRange(
const std::vector<_Bin>& values)
override {
139 if (values.size() != 1) {
143 _Bin value = values.front();
147 virtual std::vector<_Bin> clamp(
const std::vector<_Bin>& values)
override {
148 if (values.size() != 1) {
152 _Bin value = values.front();
157 std::vector<_Bin> m_bins;
160 template<
typename T,
typename _Bin = T>
169 virtual std::size_t findBin(
const std::vector<_Bin>& values)
override {
170 if (values.size() != 2)
173 _Bin value_x = values[0];
174 _Bin value_y = values[1];
184 return bin_x + (m_bins_x.size() - 1) * (bin_y - 1);
187 virtual std::size_t findClosestBin(
const std::vector<_Bin>& values,
bool* outOfRange =
nullptr)
override {
188 if (values.size() != 2)
191 _Bin value_x = values[0];
192 _Bin value_y = values[1];
193 bool local_outOfRange =
false;
201 *outOfRange |= local_outOfRange;
210 *outOfRange |= local_outOfRange;
215 return bin_x + (m_bins_x.size() - 1) * (bin_y - 1);
218 virtual bool inRange(
const std::vector<_Bin>& values)
override {
219 if (values.size() != 2) {
223 _Bin value_x = values.front();
224 _Bin value_y = values[1];
229 virtual std::vector<_Bin> clamp(
const std::vector<_Bin>& values)
override {
230 if (values.size() != 2) {
234 _Bin value_x = values.front();
235 _Bin value_y = values[1];
241 std::vector<_Bin> m_bins_x;
242 std::vector<_Bin> m_bins_y;
245 template<
typename T,
typename _Bin = T>
248 ThreeDimensionsHistogram(
const std::vector<_Bin>& bins_x,
const std::vector<_Bin>& bins_y,
const std::vector<_Bin>& bins_z):
255 virtual std::size_t findBin(
const std::vector<_Bin>& values)
override {
256 if (values.size() != 3)
259 _Bin value_x = values[0];
260 _Bin value_y = values[1];
261 _Bin value_z = values[2];
275 return bin_x + (m_bins_x.size() - 1) * ((bin_y - 1) + (m_bins_y.size() - 1) * (bin_z - 1));
278 virtual std::size_t findClosestBin(
const std::vector<_Bin>& values,
bool* outOfRange =
nullptr)
override {
279 if (values.size() != 3)
282 _Bin value_x = values[0];
283 _Bin value_y = values[1];
284 _Bin value_z = values[2];
285 bool local_outOfRange =
false;
290 *outOfRange |= local_outOfRange;
298 *outOfRange |= local_outOfRange;
306 *outOfRange |= local_outOfRange;
311 return bin_x + (m_bins_x.size() - 1) * ((bin_y - 1) + (m_bins_y.size() - 1) * (bin_z - 1));
314 virtual bool inRange(
const std::vector<_Bin>& values)
override {
315 if (values.size() != 3) {
319 _Bin value_x = values[0];
320 _Bin value_y = values[1];
321 _Bin value_z = values[2];
326 virtual std::vector<_Bin> clamp(
const std::vector<_Bin>& values)
override {
327 if (values.size() != 3) {
331 _Bin value_x = values[0];
332 _Bin value_y = values[1];
333 _Bin value_z = values[2];
339 std::vector<_Bin> m_bins_x;
340 std::vector<_Bin> m_bins_y;
341 std::vector<_Bin> m_bins_z;
344 template <
typename _Value,
typename _Bin = _Value>
346 return object.findBin(values);
349 template <
typename _Value,
typename _Bin = _Value>
351 return object.getBinContent(bin);
354 template <
typename _Value,
typename _Bin = _Value>
356 return object.getBinErrorLow(bin);
359 template <
typename _Value,
typename _Bin = _Value>
361 return object.getBinErrorHigh(bin);
Definition: Histogram.h:7
Definition: Histogram.h:113
Definition: Histogram.h:246
Definition: Histogram.h:161