Alexandria
2.19
Please provide a description of the project.
Histogram
Histogram
Binning
Sqrt.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2021 Euclid Science Ground Segment
3
*
4
* This library is free software; you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License as published by the Free
6
* Software Foundation; either version 3.0 of the License, or (at your option)
7
* any later version.
8
*
9
* This library is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
* details.
13
*
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
25
#ifndef ALEXANDRIA_HISTOGRAM_BINNING_SQRT_H
26
#define ALEXANDRIA_HISTOGRAM_BINNING_SQRT_H
27
28
#include <algorithm>
29
#include <cmath>
30
#include <numeric>
31
#include <vector>
32
33
#include "
Histogram/Histogram.h
"
34
35
namespace
Euclid
{
36
namespace
Histogram {
37
namespace
Binning {
38
42
template
<
typename
VarType>
43
class
Sqrt
:
public
BinStrategy
<VarType> {
44
public
:
45
template
<
typename
Iterator>
46
void
computeBins
(Iterator begin, Iterator end) {
47
m_nbins
=
std::ceil
(
std::sqrt
(end - begin));
48
auto
minmax =
std::minmax_element
(begin, end);
49
m_step
= (*minmax.second - *minmax.first) /
m_nbins
;
50
m_start
= *minmax.first;
51
m_end
= *minmax.second;
52
}
53
54
ssize_t
getBinIndex
(VarType value)
const
final
{
55
if
(value ==
m_end
)
56
return
m_nbins
- 1;
57
return
(value -
m_start
) /
m_step
;
58
}
59
60
std::pair<VarType, VarType>
getBinEdges
(
size_t
i)
const
final
{
61
return
std::make_pair
(i *
m_step
+
m_start
, (i + 1) *
m_step
+
m_start
);
62
}
63
64
VarType
getEdge
(
size_t
i)
const
final
{
65
return
i *
m_step
+
m_start
;
66
}
67
68
private
:
69
using
BinStrategy<VarType>::m_nbins
;
70
VarType
m_start
,
m_step
,
m_end
;
71
};
72
73
}
// end of namespace Binning
74
}
// end of namespace Histogram
75
}
// end of namespace Euclid
76
77
#endif // ALEXANDRIA_HISTOGRAM_BINNING_SQRT_H
Euclid::Histogram::Binning::Sqrt::getEdge
VarType getEdge(size_t i) const final
Definition:
Sqrt.h:64
std::pair
Euclid::Histogram::Binning::Sqrt::computeBins
void computeBins(Iterator begin, Iterator end)
Definition:
Sqrt.h:46
Euclid::Histogram::Binning::Sqrt::getBinIndex
ssize_t getBinIndex(VarType value) const final
Definition:
Sqrt.h:54
Euclid::Histogram::Binning::Sqrt::m_step
VarType m_step
Definition:
Sqrt.h:70
std::sqrt
T sqrt(T... args)
Euclid::Histogram::Binning::Sqrt::m_start
VarType m_start
Definition:
Sqrt.h:70
Euclid::Histogram::Binning::Sqrt::getBinEdges
std::pair< VarType, VarType > getBinEdges(size_t i) const final
Definition:
Sqrt.h:60
Euclid::Histogram::BinStrategy::m_nbins
size_t m_nbins
Definition:
Histogram.h:126
Euclid::Histogram::Binning::Sqrt::m_end
VarType m_end
Definition:
Sqrt.h:70
std::ceil
T ceil(T... args)
std::minmax_element
T minmax_element(T... args)
Histogram.h
Euclid::Histogram::Binning::Sqrt
Definition:
Sqrt.h:43
std::make_pair
T make_pair(T... args)
Euclid
Definition:
InstOrRefHolder.h:29
Euclid::Histogram::BinStrategy
Definition:
Histogram.h:49
Generated by
1.8.20