votca 2025.1-dev
Loading...
Searching...
No Matches
histogram.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2025 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#ifndef VOTCA_TOOLS_HISTOGRAM_H
19#define VOTCA_TOOLS_HISTOGRAM_H
20
21// Standard includes
22#include <cmath>
23#include <limits>
24
25// Local VOTCA includes
26#include "table.h"
27
28namespace votca {
29namespace tools {
30
77class Histogram {
78 public:
85 void Initialize(double min, double max, Index nbins);
86
93 void Process(const double &v, double scale = 1.0);
94
98 template <typename iterator_type>
99 void ProcessRange(const iterator_type &begin, const iterator_type &end);
100
105 double getMin() const { return min_; }
106
111 double getMax() const { return max_; }
112
117 Index getNBins() const { return nbins_; }
118
123 double getMinBinVal() const;
124
129 double getMaxBinVal() const;
135 std::pair<double, double> getInterval(Index bin) const;
136
141 double getStep() const { return step_; }
142
146 void Normalize();
147
151 void Clear();
152
157 Table &data() { return data_; }
158 const Table &data() const { return data_; }
159
164 void setPeriodic(bool periodic) { periodic_ = periodic; }
165
166 private:
167 void Initialize_();
168 double min_ = 0;
169 double max_ = 0;
170 double step_ = 0;
171 bool periodic_ = false;
174};
175
176inline std::ostream &operator<<(std::ostream &out, Histogram &h) {
177 out << h.data();
178 return out;
179}
180
181template <typename iterator_type>
182inline void Histogram::ProcessRange(const iterator_type &begin,
183 const iterator_type &end) {
184 for (iterator_type iter = begin; iter != end; ++iter) {
185 Process(*iter);
186 }
187}
188} // namespace tools
189} // namespace votca
190#endif // VOTCA_TOOLS_HISTOGRAM_H
class to generate histograms
Definition histogram.h:77
double getMinBinVal() const
Get the count of the bin with the fewest counts.
double getMax() const
get the upper bound of the histogram intervaö
Definition histogram.h:111
void Normalize()
normalize the histogram that the integral is 1
Table & data()
get access to content of histogram
Definition histogram.h:157
double getMin() const
get the lower bound of the histogram intervaö
Definition histogram.h:105
void ProcessRange(const iterator_type &begin, const iterator_type &end)
process a range of data using iterator interface
Definition histogram.h:182
void Process(const double &v, double scale=1.0)
process a data point
const Table & data() const
Definition histogram.h:158
std::pair< double, double > getInterval(Index bin) const
Given the bin number get the Inverval bounds.
void Clear()
clear all data
void setPeriodic(bool periodic)
set whether interval is periodic
Definition histogram.h:164
double getMaxBinVal() const
Get the count of the bin with the maximum counts.
Index getNBins() const
Get number of grid points.
Definition histogram.h:117
double getStep() const
get the grid of histogram
Definition histogram.h:141
void Initialize(double min, double max, Index nbins)
Initialize the Histogram.
class to store tables like rdfs, tabulated potentials, etc
Definition table.h:36
std::ostream & operator<<(std::ostream &out, const Correlate &c)
Definition correlate.h:53
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26