votca
2024.2-dev
Loading...
Searching...
No Matches
tools
src
libtools
histogramnew.cc
Go to the documentation of this file.
1
/*
2
* Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
18
// Standard includes
19
#include <algorithm>
20
21
// Local VOTCA includes
22
#include "
votca/tools/histogramnew.h
"
23
24
using namespace
std
;
25
namespace
votca
{
26
namespace
tools {
27
28
void
HistogramNew::Initialize_
() {
29
if
(
periodic_
) {
30
step_
= (
max_
-
min_
) /
double
(
nbins_
);
31
}
else
{
32
step_
= (
max_
-
min_
) / (
double
(
nbins_
) - 1.0);
33
}
34
35
if
(
nbins_
== 1) {
36
step_
= 1;
37
}
38
data_
.
resize
(
nbins_
);
39
double
v =
min_
;
40
for
(
Index
i = 0; i <
nbins_
; v +=
step_
, ++i) {
41
data_
.
x
(i) = v;
42
}
43
data_
.
y
() = Eigen::VectorXd::Zero(
nbins_
);
44
data_
.
yerr
() = Eigen::VectorXd::Zero(
nbins_
);
45
data_
.
flags
() = std::vector<char>(
nbins_
,
'i'
);
46
}
47
48
void
HistogramNew::Initialize
(
double
min,
double
max,
Index
nbins) {
49
min_
= min;
50
max_
= max;
51
nbins_
= nbins;
52
Initialize_
();
53
}
54
55
void
HistogramNew::Process
(
const
double
&v,
double
scale) {
56
57
Index
i = (
Index
)floor((v -
min_
) /
step_
+ 0.5);
58
if
(i < 0 || i >=
nbins_
) {
59
if
(
periodic_
) {
60
if
(i < 0) {
61
i =
nbins_
- ((-i) %
nbins_
);
62
}
else
{
63
i = i %
nbins_
;
64
}
65
}
else
{
66
return
;
67
}
68
}
69
data_
.
y
(i) += scale;
70
}
71
72
double
HistogramNew::getMinBinVal
()
const
{
return
data_
.
getMinY
(); }
73
74
double
HistogramNew::getMaxBinVal
()
const
{
return
data_
.
getMaxY
(); }
75
76
pair<double, double>
HistogramNew::getInterval
(
Index
bin)
const
{
77
pair<double, double> bounds;
78
double
value =
static_cast<
double
>
(bin);
79
bounds.first = value *
step_
+
min_
;
80
bounds.second +=
step_
;
81
return
bounds;
82
}
83
84
void
HistogramNew::Normalize
() {
85
double
area = 0;
86
area =
data_
.
y
().cwiseAbs().sum() *
step_
;
87
double
scale = 1. / area;
88
data_
.
y
() *= scale;
89
}
90
91
void
HistogramNew::Clear
() {
92
data_
.
y
() = Eigen::VectorXd::Zero(
nbins_
);
93
data_
.
yerr
() = Eigen::VectorXd::Zero(
nbins_
);
94
}
95
96
}
// namespace tools
97
}
// namespace votca
votca::tools::HistogramNew::data_
Table data_
Definition
histogramnew.h:173
votca::tools::HistogramNew::step_
double step_
Definition
histogramnew.h:170
votca::tools::HistogramNew::min_
double min_
Definition
histogramnew.h:168
votca::tools::HistogramNew::getMaxBinVal
double getMaxBinVal() const
Get the count of the bin with the maximum counts.
Definition
histogramnew.cc:74
votca::tools::HistogramNew::Normalize
void Normalize()
normalize the histogram that the integral is 1
Definition
histogramnew.cc:84
votca::tools::HistogramNew::getMinBinVal
double getMinBinVal() const
Get the count of the bin with the fewest counts.
Definition
histogramnew.cc:72
votca::tools::HistogramNew::Initialize
void Initialize(double min, double max, Index nbins)
Initialize the HistogramNew.
Definition
histogramnew.cc:48
votca::tools::HistogramNew::periodic_
bool periodic_
Definition
histogramnew.h:171
votca::tools::HistogramNew::Process
void Process(const double &v, double scale=1.0)
process a data point
Definition
histogramnew.cc:55
votca::tools::HistogramNew::max_
double max_
Definition
histogramnew.h:169
votca::tools::HistogramNew::Initialize_
void Initialize_()
Definition
histogramnew.cc:28
votca::tools::HistogramNew::getInterval
std::pair< double, double > getInterval(Index bin) const
Given the bin number get the Inverval bounds.
Definition
histogramnew.cc:76
votca::tools::HistogramNew::nbins_
Index nbins_
Definition
histogramnew.h:172
votca::tools::HistogramNew::Clear
void Clear()
clear all data
Definition
histogramnew.cc:91
votca::tools::Table::x
double & x(Index i)
Definition
table.h:44
votca::tools::Table::getMinY
double getMinY() const
Gets the minimum value in the y column.
Definition
table.cc:86
votca::tools::Table::yerr
double & yerr(Index i)
Definition
table.h:50
votca::tools::Table::getMaxY
double getMaxY() const
Gets the maximum value in the y column.
Definition
table.cc:84
votca::tools::Table::flags
char & flags(Index i)
Definition
table.h:49
votca::tools::Table::resize
void resize(Index N)
Definition
table.cc:38
votca::tools::Table::y
double & y(Index i)
Definition
table.h:45
histogramnew.h
std
STL namespace.
votca
base class for all analysis tools
Definition
basebead.h:33
votca::Index
Eigen::Index Index
Definition
types.h:26
Generated by
1.12.0