23 std::string
const& data_set_name,
24 std::string
const& param_name)
const
26 if (file_name.empty())
28 ERR(
"No file name specified.");
32 std::ofstream out(file_name);
35 ERR(
"Error writing histogram: Could not open file.");
39 out <<
"# Histogram for parameter " << param_name <<
" of data set "
40 << data_set_name <<
"\n";
41 std::size_t
const n_bins = this->getNumberOfBins();
42 std::vector<std::size_t>
const& bin_cnts(this->getBinCounts());
43 double const min(this->getMinimum());
44 double const bin_width(this->getBinWidth());
46 for (std::size_t k(0); k < n_bins; k++)
48 out << min + k * bin_width <<
" " << bin_cnts[k] <<
"\n";
56 const unsigned int line_width)
const
58 const std::size_t count_max =
59 *std::max_element(histogram_.begin(), histogram_.end());
60 for (
unsigned int bin = 0; bin < nr_bins_; ++bin)
62 os <<
"[" << min_ + bin * bin_width_ <<
", "
63 << min_ + (bin + 1) * bin_width_ <<
")\t";
64 os << histogram_[bin] <<
"\t";
66 const int n_stars =
static_cast<int>(
67 std::ceil(line_width * ((
double)histogram_[bin] / count_max)));
68 for (
int star = 0; star < n_stars; star++)
82 std::ostream_iterator<std::size_t>(os,
" "));
83 return os << std::endl;
86template class Histogram<double>;
Implementation of Histogram class.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
const T & getMinimum() const
const unsigned int & getNumberOfBins() const
const std::vector< std::size_t > & getBinCounts() const
void prettyPrint(std::ostream &os, const unsigned int line_width=16) const
const T & getMaximum() const
int write(std::string const &file_name, std::string const &data_set_name, std::string const ¶m_name) const
std::ostream & operator<<(std::ostream &os, const Histogram< T > &h)