8#include "Distribution.h"
9#include <util/format/Dbl.h>
35 binWidth_(other.binWidth_),
37 nSample_(other.nSample_),
38 nReject_(other.nReject_)
43 for (
int i=0; i <
nBin_; ++i) {
60 if (
this == &other)
return *
this;
63 if (other.
nBin_ > 0) {
66 assert(other.
nBin_ == 0);
83 for (
int i=0; i <
nBin_; ++i) {
102 read<double>(in,
"min",
min_);
103 read<double>(in,
"max",
max_);
104 read<int>(in,
"nBin",
nBin_);
132 loadParameter<double>(ar,
"min",
min_);
133 loadParameter<double>(ar,
"max",
max_);
134 loadParameter<int>(ar,
"nBin",
nBin_);
142 UTIL_THROW(
"Inconsistent histogram capacity");
162 for (
int i=0; i <
nBin_; ++i) {
188 for (
int i=0; i <
nBin_; ++i) {
192 out <<
Dbl(x, 18, 8) <<
Dbl(rho, 18, 8) << std::endl;
203 long* totHistogram =
new long[
nBin_];
205 if (communicator.Get_rank() == root) {
206 for (
int i=0; i <
nBin_; ++i) {
210 for (
int i=0; i <
nBin_; ++i) {
214 delete [] totHistogram;
217 communicator.Reduce(&
nSample_, &totSample, 1, MPI::LONG, MPI::SUM, root);
218 if (communicator.Get_rank() == root) {
225 communicator.Reduce(&
nReject_, &totReject, 1, MPI::LONG, MPI::SUM, root);
226 if (communicator.Get_rank() == root) {
Data * cArray()
Return a pointer to the underlying C array.
int capacity() const
Return allocated size.
Saving archive for binary istream.
Saving / output archive for binary ostream.
void allocate(int capacity)
Allocate the underlying C array.
Wrapper for a double precision number, for formatted ostream output.
A distribution (or histogram) of values for a real variable.
int nBin() const
Get the number of bins.
void sample(double value)
Sample a value.
double binWidth_
width of bin = (max_-min_)/nBin_ .
double min_
minimum value.
DArray< long > histogram_
Histogram of occurences, one element per bin.
double min() const
Get minimum value in range of histogram.
void setParam(double min, double max, int nBin)
Set parameters and initialize.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
void reduce(MPI::Intracomm &communicator, int root)
Reduce (add) distributions from multiple MPI processors.
double max_
maximum value.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
void output(std::ostream &out)
Output the distribution to file.
int binIndex(double value) const
Return the index of the bin for a value.
Distribution & operator=(const Distribution &other)
Assignment operator.
virtual ~Distribution()
Destructor.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Distribution()
Default constructor.
int nSample_
Number of sampled values in Histogram.
int nReject_
Number of sampled values that were out of range.
virtual void clear()
Clear (i.e., zero) previously allocated histogram.
double max() const
Get maximum value in range of histogram.
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
bool feq(double x, double y, double eps=1.0E-10)
Are two floating point numbers equal to within round-off error?
Utility classes for scientific computation.