votca 2024-dev
Loading...
Searching...
No Matches
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
23
24using namespace std;
25namespace votca {
26namespace tools {
27
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 }
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
48void HistogramNew::Initialize(double min, double max, Index nbins) {
49 min_ = min;
50 max_ = max;
51 nbins_ = nbins;
53}
54
55void 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
72double HistogramNew::getMinBinVal() const { return data_.getMinY(); }
73
74double HistogramNew::getMaxBinVal() const { return data_.getMaxY(); }
75
76pair<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
85 double area = 0;
86 area = data_.y().cwiseAbs().sum() * step_;
87 double scale = 1. / area;
88 data_.y() *= scale;
89}
90
92 data_.y() = Eigen::VectorXd::Zero(nbins_);
93 data_.yerr() = Eigen::VectorXd::Zero(nbins_);
94}
95
96} // namespace tools
97} // namespace votca
double getMaxBinVal() const
Get the count of the bin with the maximum counts.
void Normalize()
normalize the histogram that the integral is 1
double getMinBinVal() const
Get the count of the bin with the fewest counts.
void Initialize(double min, double max, Index nbins)
Initialize the HistogramNew.
void Process(const double &v, double scale=1.0)
process a data point
std::pair< double, double > getInterval(Index bin) const
Given the bin number get the Inverval bounds.
void Clear()
clear all data
double & x(Index i)
Definition table.h:44
double getMinY() const
Gets the minimum value in the y column.
Definition table.cc:86
double & yerr(Index i)
Definition table.h:50
double getMaxY() const
Gets the maximum value in the y column.
Definition table.cc:84
char & flags(Index i)
Definition table.h:49
void resize(Index N)
Definition table.cc:38
double & y(Index i)
Definition table.h:45
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26