39 #include <type_traits> 42 #include <boost/math/constants/constants.hpp> 44 #include <boost/serialization/serialization.hpp> 45 #include <boost/serialization/base_object.hpp> 71 template<
typename Scalar_ =
double>
78 inline HistogramParams(Scalar min_ = 0.0, Scalar max_ = 1.0, Eigen::Index num_bins_ = 50)
79 : min(min_), max(max_), num_bins(num_bins_)
83 template<
typename Params2
84 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 86 , decltype((
int)std::declval<const Params2>().min + (
int)std::declval<const Params2>().max
87 + std::declval<Params2>().num_bins) dummyval = 0
91 : min(other.min), max(other.max), num_bins(other.num_bins)
119 if ( !isWithinBounds(value) ) {
121 <<
" out of range ["<<min<<
","<<max<<
"["));
123 return binIndexUnsafe(value);
135 return (Eigen::Index)((value-min) / (max-min) * num_bins);
148 return min + index * (max-min) / num_bins;
160 return min + (index+boost::math::constants::half<Scalar>()) * (max-min) / num_bins;
173 return min + (index+1) * (max-min) / num_bins;
181 return (max - min) / num_bins;
188 const auto halfbinres = boost::math::constants::half<Scalar>() * binResolution();
207 friend boost::serialization::access;
208 template<
typename Archive>
209 void serialize(Archive & a,
unsigned int )
229 template<
typename Scalar_,
typename CountType_ =
int>
247 static constexpr
bool HasErrorBars =
false;
260 template<
typename Params2 = Params
261 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 263 , decltype((
int)std::declval<const Params2>().min + (
int)std::declval<const Params2>().max
264 + std::declval<Params2>().num_bins) dummyval = 0
268 : params(p), bins(
Eigen::Array<CountType,
Eigen::Dynamic,1>::Zero(p.num_bins)),
274 Histogram(Scalar min_, Scalar max_, Eigen::Index num_bins)
275 : params(min_, max_, num_bins), bins(
Eigen::Array<CountType,
Eigen::Dynamic,1>::Zero(num_bins)),
282 : params(
std::move(x.params)),
283 bins(
std::move(x.bins)),
284 off_chart(x.off_chart)
292 off_chart(x.off_chart)
297 template<
typename HistogramType,
299 TOMOGRAPHER_ENABLED_IF_TMPL(HistogramType::HasErrorBars == 0 ||
300 HistogramType::HasErrorBars == 1)>
304 h.
bins = other.bins.template cast<CountType>();
326 template<
typename EigenType>
331 bins = x.derived().template cast<CountType>();
332 off_chart = off_chart_;
343 template<
typename EigenType>
351 bins += x.derived().template cast<CountType>();
352 off_chart += off_chart_;
363 template<
typename OtherScalar,
typename OtherCountType>
370 bins += x.
bins.template cast<CountType>();
381 inline CountType
count(Eigen::Index i)
const 428 if ( !isWithinBounds(value) ) {
449 if ( !isWithinBounds(value) ) {
456 bins(index) += weight;
474 template<
typename NewCountType = decltype(Scalar(1) + CountType(1))>
479 return NewCountType(off_chart) + NewCountType(binResolution() * bins.sum());
489 template<
typename NewCountType = Scalar>
493 const NewCountType f = normalization<NewCountType>();
494 h.
load(bins.template cast<NewCountType>() / f, NewCountType(off_chart) / f);
508 return bins.sum() + off_chart;
522 template<
typename NewCountType = Scalar>
526 const NewCountType f = totalCounts();
527 h.
load(bins.template cast<NewCountType>() / f, NewCountType(off_chart) / f);
541 friend boost::serialization::access;
542 template<
typename Archive>
543 void serialize(Archive & a,
unsigned int )
552 template<
typename Scalar_,
typename CountType_>
565 template<
typename Scalar_,
typename CountType_ =
double>
584 static constexpr
bool HasErrorBars =
true;
592 using Base_::off_chart;
601 : Base_(params), delta(
Eigen::Array<CountType,
Eigen::Dynamic, 1>::Zero(params.num_bins))
611 : Base_(min, max, num_bins), delta(
Eigen::Array<CountType,
Eigen::Dynamic, 1>::Zero(num_bins))
617 : Base_(
std::move(x)),
618 delta(
std::move(x.delta))
631 template<
typename HistogramType,
632 TOMOGRAPHER_ENABLED_IF_TMPL(HistogramType::HasErrorBars == 1)>
636 h.
bins = other.bins.template cast<CountType>();
637 h.
delta = other.delta.template cast<CountType>();
651 delta.
resize(Base_::numBins());
677 template<
typename EigenType,
typename EigenType2 = EigenType>
680 CountType off_chart_ = 0)
682 Base_::load(d, off_chart_);
685 delta = derr.derived().template cast<CountType>();
696 template<
typename NewCountType = Scalar>
700 const NewCountType f = Base_::template normalization<NewCountType>();
701 h.
load(bins.template cast<NewCountType>() / f,
702 delta.template cast<NewCountType>() / f,
703 NewCountType(off_chart) / f);
717 template<
typename NewCountType = Scalar>
721 const NewCountType f = Base_::totalCounts();
722 h.
load(bins.template cast<NewCountType>() / f,
723 delta.template cast<NewCountType>() / f,
724 NewCountType(off_chart) / f);
733 template<
typename... Args>
734 inline void add(Args && ... )
740 template<
typename... Args>
741 inline void record(Args && ... )
760 friend boost::serialization::access;
761 template<
typename Archive>
762 void serialize(Archive & a,
unsigned int )
764 a & boost::serialization::base_object<Base_>(*this);
770 template<
typename Scalar_,
typename CountType_>
810 template<
typename HistogramType_,
typename RealAvgType =
double>
831 static constexpr
bool HasErrorBars =
true;
848 : Base_(params), num_histograms(0)
858 : Base_(min, max, num_bins), num_histograms(0)
869 num_histograms(x.num_histograms)
880 inline void reset(
const Params& params_)
882 Base_::params = params_;
917 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
918 inline
void addHistogram(const HistogramType& histogram)
924 (
typename HistogramType::CountType)Base_::numBins());
926 for (Eigen::Index k = 0; k < histogram.numBins(); ++k) {
927 RealAvgType binvalue = histogram.count(k);
928 Base_::bins(k) += binvalue;
929 Base_::delta(k) += binvalue * binvalue;
932 Base_::off_chart += histogram.off_chart;
950 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
951 inline
void finalize()
953 Base_::bins /= num_histograms;
954 Base_::delta /= num_histograms;
955 Base_::off_chart /= num_histograms;
958 auto finhist2 = Base_::bins*Base_::bins;
959 Base_::delta = ( (Base_::delta - finhist2) / (num_histograms-1) ).sqrt();
980 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
986 tomographer_assert((
typename HistogramType::CountType)histogram.numBins() == Base_::numBins());
988 for (Eigen::Index k = 0; k < histogram.numBins(); ++k) {
989 RealAvgType binvalue = histogram.count(k);
990 Base_::bins(k) += binvalue;
991 RealAvgType bindelta = histogram.errorBar(k);
992 Base_::delta(k) += bindelta*bindelta;
995 Base_::off_chart += histogram.off_chart;
1012 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1013 inline
void finalize()
1015 Base_::bins /= num_histograms;
1016 Base_::off_chart /= num_histograms;
1018 Base_::delta = Base_::delta.sqrt();
1019 Base_::delta /= num_histograms;
1023 friend boost::serialization::access;
1024 template<
typename Archive>
1025 void serialize(Archive & a,
unsigned int )
1027 a & boost::serialization::base_object<Base_>(*this);
1062 template<
typename HistogramType_,
typename CountRealType_>
1065 AveragedHistogram<HistogramType_,CountRealType_>
1094 : final_histogram(
std::move(x.final_histogram))
1131 template<
typename ContainerType,
typename ExtractHistogramFn>
1133 const ContainerType & list,
1134 ExtractHistogramFn extract_histogram_fn)
1136 FinalHistogramType h(params);
1139 for (
const auto item : list) {
1166 const int precision = 10)
1168 stream <<
"Value" << sep <<
"Counts" << sep <<
"Error" << linesep
1170 for (Eigen::Index kk = 0; kk < final_histogram.
bins.size(); ++kk) {
1172 << final_histogram.
bins(kk) << sep
1173 << final_histogram.
delta(kk) << linesep;
1179 friend boost::serialization::access;
1180 template<
typename Archive>
1181 void serialize(Archive & a,
unsigned int )
1183 a & final_histogram;
1217 template<
typename HistogramType_,
typename CountRealType_>
1220 AveragedHistogram<HistogramType_, CountRealType_> ,
1221 AveragedHistogram<Histogram<typename HistogramType_::Scalar,
1222 typename HistogramType_::CountType>,
1260 : final_histogram(
std::move(x.final_histogram)),
1261 simple_final_histogram(
std::move(x.simple_final_histogram))
1302 template<
typename ContainerType,
typename ExtractHistogramFn>
1304 const ContainerType & list,
1305 ExtractHistogramFn extract_histogram_fn)
1308 FinalHistogramType hist(params);
1309 SimpleFinalHistogramType histsimple(params);
1312 for (
const auto& item : list) {
1313 const auto& h = extract_histogram_fn(item);
1348 const int precision = 10)
1350 stream <<
"Value" << sep <<
"Counts" << sep <<
"Error" << sep <<
"SimpleError" << linesep
1352 for (Eigen::Index kk = 0; kk < final_histogram.
bins.size(); ++kk) {
1354 << final_histogram.
bins(kk) << sep
1355 << final_histogram.
delta(kk) << sep
1356 << simple_final_histogram.
delta(kk) << linesep;
1361 friend boost::serialization::access;
1362 template<
typename Archive>
1363 void serialize(Archive & a,
unsigned int )
1365 a & final_histogram;
1366 a & simple_final_histogram;
1384 namespace tomo_internal {
1389 template<
typename Scalar,
typename Fn>
1390 inline Scalar max_finite_value(
const Eigen::Index num_items, Fn val_generator,
1391 const Scalar default_val = Scalar(1.0))
1393 bool has_first_val =
false;
1394 Scalar max_val = default_val;
1395 for (Eigen::Index k = 0; k < num_items; ++k) {
1396 const Scalar this_val = val_generator(k);
1397 if (
Tools::isFinite(this_val) && (!has_first_val || this_val > max_val)) {
1399 has_first_val =
true;
1408 template<
typename HistogramType>
1409 struct histogram_pretty_print_label
1413 labels.
resize(hist.numBins());
1414 for (
std::size_t k = 0; k < hist.numBins(); ++k) {
1423 template<
typename HistogramType>
1428 const typename HistogramType::Scalar max_label_val
1429 =
std::max(hist.binCenterValue(0), hist.binCenterValue(hist.numBins()-1));
1431 const int relprecision = 4;
1432 const int precision = (powten > relprecision) ? 0 : (relprecision - powten - 1);
1434 for (Eigen::Index k = 0; k < hist.numBins(); ++k) {
1441 template<
typename Scalar_,
typename CountType_>
1442 struct histogram_pretty_print_label<Histogram<Scalar_, CountType_> >
1447 histogram_get_labels_for_hist_params<HistogramType>(labels, hist);
1451 template<
typename Scalar_,
typename CountType_>
1452 struct histogram_pretty_print_label<HistogramWithErrorBars<Scalar_, CountType_> >
1457 histogram_get_labels_for_hist_params<HistogramType>(labels, hist);
1461 template<
typename BaseHistogramType_,
typename RealAvgType_>
1462 struct histogram_pretty_print_label<AveragedHistogram<BaseHistogramType_, RealAvgType_> >
1467 histogram_get_labels_for_hist_params<HistogramType>(labels, hist);
1472 template<
typename HistogramType>
1473 struct histogram_pretty_print_value
1476 histogram_pretty_print_value(
const HistogramType & hist_) : hist(hist_) { }
1478 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
1483 typename HistogramType::CountType max_val =
1484 max_finite_value<typename HistogramType::CountType>(hist.numBins(),
1485 [&](Eigen::Index k) {
return hist.count(k); },
1486 typename HistogramType::CountType(1));
1489 const int relprecision = 3;
1490 const int precision = abs_precision_for(powten, relprecision);
1491 const int w = (precision > 0) ? (precision+powten+1) : (relprecision+2);
1493 for (Eigen::Index k = 0; k < hist.numBins(); ++k) {
1501 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1506 typename HistogramType::CountType max_val =
1507 max_finite_value<typename HistogramType::CountType>(hist.numBins(),
1508 [&](Eigen::Index k) {
return hist.count(k); },
1509 typename HistogramType::CountType(1));
1512 const int relprecision = 3;
1513 const int precision = abs_precision_for(powten, relprecision);
1514 const int w = (precision > 0) ? (precision+powten+2) : (relprecision+2);
1516 for (Eigen::Index k = 0; k < hist.numBins(); ++k) {
1519 << hist.count(k) <<
" +- " 1521 << hist.errorBar(k);
1526 static inline int abs_precision_for(
const int powten,
const int relprecision)
1528 return (powten >= relprecision) ? 0 : (relprecision - powten - 1);
1536 template<
typename HistogramType>
1537 struct histogram_pretty_printer
1540 const int max_width;
1543 typedef decltype(
typename HistogramType::CountType(1) +
double(1)) CountType;
1554 CountType max_value;
1559 histogram_pretty_printer(
const HistogramType & hist_,
const int max_width_)
1560 : hist(hist_), max_width(max_width_), lsep(
" |"), rsep(
" ")
1569 histogram_pretty_print_label<HistogramType>::getLabels(labels, hist);
1570 histogram_pretty_print_value<HistogramType>::getStrValues(svalues, hist);
1572 bool has_maxval =
false;
1574 const CountType val = maxval(k);
1580 if (k == 0 || (
int)labels[k].size() > maxlabelwidth) {
1581 maxlabelwidth = (int)labels[k].size();
1583 if (k == 0 || (
int)svalues[k].
size() > maxsvaluewidth) {
1584 maxsvaluewidth = (int)svalues[k].size();
1591 max_bar_width = max_width - maxlabelwidth - maxsvaluewidth - (int)lsep.
size() - (int)rsep.
size();
1592 if (max_bar_width < 2) {
1595 barscale = ((max_value > 0) ? (max_value / max_bar_width) : 1.0);
1598 inline std::size_t value_to_bar_length(CountType val)
const 1610 inline void fill_str_len(
std::string & s, CountType valstart, CountType valend,
1611 char c,
char clside,
char crside)
const 1622 if (clside && crside && clside != crside && vs == ve) {
1623 if (ve < s.
size()-1) {
1625 }
else if (vs > 1) {
1643 str <<
std::setw(maxlabelwidth) << labels[k] << lsep
1644 << make_bar(k) << rsep <<
std::setw(maxsvaluewidth) << svalues[k] <<
"\n";
1650 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
1651 inline CountType maxval(
const std::size_t k)
const 1653 return hist.count((Eigen::Index)k);
1655 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1656 inline CountType maxval(
const std::size_t k)
const 1658 return (hist.count((Eigen::Index)k) + hist.errorBar((Eigen::Index)k));
1661 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
1665 fill_str_len(sbar, 0.0, hist.count((Eigen::Index)k),
'*', 0, 0);
1668 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1672 const typename HistogramType::CountType binval = hist.count((Eigen::Index)k);
1673 const typename HistogramType::CountType binerr = hist.errorBar((Eigen::Index)k);
1674 fill_str_len(sbar, 0.0, binval - binerr,
'*',
'*',
'*');
1675 fill_str_len(sbar, binval - binerr, binval + binerr,
'-',
'|',
'|');
1680 template<
typename HistogramType>
1682 const int max_width)
1686 if (histogram.off_chart > 0) {
1687 send +=
Tools::fmts(
" [+%.1g off]", (
double)histogram.off_chart);
1690 const int maxbarwidth = max_width - (int)s.
size() - (int)send.size();
1691 const int numdiv = (int)(
std::ceil((
float)histogram.numBins() / maxbarwidth) + 0.5f);
1692 const int barwidth = (int)(
std::ceil((
float)histogram.numBins() / numdiv) + 0.5f);
1695 Eigen::ArrayXf veclog(barwidth);
1698 float minlogval = 0;
1699 float maxlogval = 0;
1700 for (k = 0; k < barwidth; ++k) {
1701 vec(k) = histogram.bins.
segment((Eigen::Index)(numdiv*k),
1703 (Eigen::Index)(histogram.bins.size()-numdiv*k))).sum();
1706 veclog(k) =
std::log((
float)vec(k));
1708 veclog(k) = (float)vec(k);
1710 if (k == 0 || minlogval > veclog(k)) {
1711 minlogval = veclog(k);
1713 if (k == 0 || maxlogval < veclog(k)) {
1714 maxlogval = veclog(k) + 1e-6f;
1723 for (k = 0; k < barwidth; ++k) {
1727 int i = (int)(chars.
size() * (veclog(k) - minlogval) / (maxlogval - minlogval));
1728 if (i < 0) { i = 0; }
1729 if (i >= (
int)chars.
size()) { i = (int)chars.
size()-1; }
1750 template<
typename HistogramType>
1755 if (histogram.params.num_bins == 0) {
1756 str <<
"<empty histogram: no bins>\n";
1761 tomo_internal::histogram_pretty_printer<HistogramType>(histogram, max_width).pretty_print(str);
1772 template<
typename HistogramType>
1776 histogramPrettyPrint<HistogramType>(ss, histogram, max_width);
1797 template<
typename HistogramType>
1799 bool log_scale =
true,
int max_width = 0)
1806 if (histogram.params.num_bins == 0) {
1807 s =
"<empty histogram: no bins>";
1809 s = tomo_internal::histogram_short_bar_fmt<HistogramType>(histogram, log_scale, max_width);
1813 return max_width - (int)s.
size();
1825 template<
typename HistogramType>
1830 if (histogram.params.num_bins == 0) {
1831 return "<empty histogram: no bins>";
1835 return tomo_internal::histogram_short_bar_fmt<HistogramType>(histogram, log_scale, max_width);
1853 template<
typename HistogramType>
1856 const HistogramType& hist,
1858 bool log_scale =
true,
1859 int full_max_width = 0)
1864 const int w =
histogramShortBar(str, hist, log_scale, full_max_width - (
int)head.size() - (int)tail.
size());
1882 template<
typename HistogramType>
1884 const HistogramType& hist,
1886 bool log_scale =
true,
1887 int full_max_width = 0)
1899 template<
typename Scalar_ =
double>
1901 template<
typename Scalar_,
typename CountType_ =
int>
1903 template<
typename Scalar_,
typename CountType_ =
double>
Utilities for formatting strings.
Scalar binCenterValue(Eigen::Index index) const
Returns the value which a given bin index represents (center bin value)
bool isWithinBounds(Scalar value) const
Shorthand for Params::isWithinBounds()
HistogramType::Params HistogramParams
The parameters type used to describe our histogram range and number of bins.
FinalHistogramType final_histogram
The final histogram, with error bars.
Histogram(Params2 p=Params2())
Constructor: stores the parameters and initializes the histogram to zero counts everywhere.
Eigen::Array< CountType, Eigen::Dynamic, 1 > delta
The error bars associated with each histogram bin.
void reset()
Resets the histogram to zero counts everywhere (including the off-chart counts)
CountRealType_ CountRealType
Type used for averaged histogram counts (e.g. double)
Eigen::Index record(Scalar value)
Record a new value in the histogram.
Scalar max
Upper range value.
void addHistogram(const HistogramType &histogram)
Add a new histogram in the data series.
The parameters of a Histogram.
void reset()
Resets the histogram to zero counts everywhere, and zero error bars.
Base namespace for the Tomographer project.
void histogramShortBarWithInfo(std::ostream &str, std::string head, const HistogramType &hist, std::string tail, bool log_scale=true, int full_max_width=0)
Format the histogram as a one-line bar, with some surrounding info.
Scalar binResolution() const
Returns the width of a bin.
HistogramParams< Scalar_ > Params
The type for specifying parameters of this histogram (limits, number of bins)
Scalar binCenterValue(Eigen::Index index) const
Shorthand for Params::binCenterValue()
Eigen::Index binIndexUnsafe(Scalar value) const
Returns which bin this value should be counted in.
HistogramParams(const Params2 &other)
Copy constructor, from any other Histogram::Params type.
static HistogramWithErrorBars copy(const HistogramType &other)
explicitly copy another histogram type
Stores a histogram along with error bars.
CountType count(Eigen::Index i) const
Shorthand for bins(i)
Base_::Scalar Scalar
The histogram's X-axis scalar type. See HistogramWithErrorBars::Scalar.
Histogram(Scalar min_, Scalar max_, Eigen::Index num_bins)
Constructor: stores the parameters and initializes the histogram to zero counts everywhere.
void add(const Histogram< OtherScalar, OtherCountType > &x)
Add data to the histogram.
HistogramWithErrorBars(Params params=Params())
Constructor, with given histogram parameters.
Base_::Params Params
The histogram parameters' type. See HistogramWithErrorBars::Params.
bool isWithinBounds(Scalar value) const
Tests whether the given value is in the range of the histogram.
HistogramWithErrorBars(HistogramWithErrorBars &&x)
Constructor: move another histogram type.
std::string prettyPrint(int max_width=0) const
Pretty-print the histogram and return it as a string with horizontal bars.
Eigen::Index binIndex(Scalar value) const
Returns which bin this value should be counted in (index in the histogram's bins array) ...
Params params
Parameters of this histogram (range and # of bins)
HistogramType::Scalar HistogramScalarType
The scalar type of the histogram (i.e., x-axis labels)
Histogram< Scalar_, CountType_ > Base_
Shortcut for our base class type.
HistogramParams(Scalar min_=0.0, Scalar max_=1.0, Eigen::Index num_bins_=50)
The obvious constructor.
Histogram< typename HistogramType::Scalar, typename HistogramType::CountType > SimpleHistogramType
The "simple" histogram, as if without binning analysis.
void add(const Eigen::ArrayBase< EigenType > &x, CountType off_chart_=0)
Add data to the histogram.
CountType_ CountType
The Type used to keep track of counts. See Histogram::CountType.
HistogramType::Scalar HistogramScalarType
The scalar type of the histogram (i.e., x-axis labels)
int num_histograms
The number of histograms averaged.
SegmentReturnType segment(Index start, Index n)
void reset()
Resets the data keeping the exisiting params.
Scalar_ Scalar
The scalar type of the "X"-axis of the histogram (usually double)
AveragedHistogram< HistogramType, CountRealType > FinalHistogramType
The type of the final resulting, averaged histogram.
NewCountType normalization() const
Calculate the total weight stored in this histogram.
AveragedHistogram(const Params ¶ms=Params())
Constructs an AveragedHistogram with the given histogram parameters.
Histogram< Scalar, NewCountType > normalized() const
Get a normalized version of this histogram.
HistogramWithErrorBars(Scalar min, Scalar max, Eigen::Index num_bins)
Constructor, with given histogram parameters.
Combines several histograms (with same parameters) into an averaged histogram.
void histogramPrettyPrint(std::ostream &str, const HistogramType &histogram, int max_width=0)
pretty-print the given histogram.
void load(const Eigen::DenseBase< EigenType > &x, CountType off_chart_=0)
Load data for the histogram. Uses current histogram parameters, just sets the bin counts...
AveragedHistogram< HistogramType, CountRealType > FinalHistogramType
The type of the final resulting, averaged histogram.
static Histogram copy(const HistogramType &other)
explicitly copy another histogram type
Basic utilities for dealing with Eigen matrices and other types.
HistogramType_ HistogramType
The histogram type corresponding to the result of a task.
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
Base_::Params Params
Shortcut for our base class' histogram parameters. See Histogram::Params.
Eigen::Index numBins() const
Shorthand for params.num_bins
AveragedHistogram< SimpleHistogramType, CountRealType > SimpleFinalHistogramType
Properly averaged "simple" histogram, with naive statistical standard deviation error bars from the s...
Eigen::Array< CountType, Eigen::Dynamic, 1 > bins
The counts for each bin.
CountType off_chart
The number of points that fell outside of the given range.
CountRealType_ CountRealType
Type used for averaged histogram counts (e.g. double)
Base_::CountType CountType
The histogram' count type. This is exactly the same as RealAvgType.
Eigen::Array< Scalar, Eigen::Dynamic, 1 > valuesCenter() const
Return an array of values corresponding to the center of each bin.
Histogram(const Histogram &x)
Constructor: copy another histogram type.
Eigen::Index binIndex(Scalar value) const
Shorthand for Params::binIndex()
Scalar binLowerValue(Eigen::Index index) const
Returns the value which a given bin index represents (lower bin value limit)
CountType totalCounts() const
Return the total number of histogram counts (no normalization)
HistogramWithErrorBars< Scalar, NewCountType > normalized() const
Get a normalized version of this histogram.
Some C++ utilities, with a tad of C++11 tricks.
SimpleFinalHistogramType simple_final_histogram
The "naive" final histogram, ignoring the error bars of each histogram (see class doc) ...
HistogramType_ HistogramType
The histogram type corresponding to the result of a task.
void reset(const Params ¶ms_)
Resets the data and sets new params.
Scalar_ Scalar
The scalar type used to specify the "value" (horizongal axis) of the histogram.
std::string prettyPrint(int max_width=0) const
Print the histogram in human readable form.
AveragedHistogram(Scalar min, Scalar max, Eigen::Index num_bins)
Constructs an AveragedHistogram with the given histogram parameters.
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
Scalar binResolution() const
Shorthand for Params::binResolution()
Eigen::Array< Scalar, Eigen::Dynamic, 1 > valuesLower() const
Return an array of values corresponding to the lower value of each bin.
Histogram< Scalar, NewCountType > normalizedCounts() const
Get a version of this histogram, normalized by total counts.
static AggregatedHistogramSimple aggregate(const HistogramParams ¶ms, const ContainerType &list, ExtractHistogramFn extract_histogram_fn)
Aggregate a list of histograms.
VarValueDecoder< T >::RetType value(const Var &var)
Access the value of the given variable, as a C++ type.
static AggregatedHistogramWithErrorBars aggregate(const HistogramParams ¶ms, const ContainerType &list, ExtractHistogramFn extract_histogram_fn)
Aggregate a list of histograms.
HistogramWithErrorBars< typename HistogramType_::Scalar, RealAvgType > Base_
Shortcut for our base class' type.
Scalar binUpperValue(Eigen::Index index) const
Returns the value which a given bin index represents (upper bin value limit)
CountType errorBar(Eigen::Index i) const
Get error bar for bin number i.
Scalar_ Scalar
The Scalar (X-axis) Type. See Histogram::Scalar.
HistogramType_ HistogramType
Type of the individual histograms we are averaging.
Scalar binUpperValue(Eigen::Index index) const
Shorthand for Params::binUpperValue()
Eigen::Array< Scalar, Eigen::Dynamic, 1 > valuesUpper() const
Return an array of values corresponding to the upper value of each bin.
void printHistogramCsv(std::ostream &stream, const std::string sep="\, const std::string linesep="\", const int precision=10)
Produce a comma-separated-value (CSV) representation of the final aggregated histogram data...
void resize(Index nbRows, Index nbCols)
#define streamstr(tokens)
Utility macro to format stream tokens to a std::string.
int histogramShortBar(std::ostream &str, const HistogramType &histogram, bool log_scale=true, int max_width=0)
Format the histogram as a one-line bar.
Eigen::Index record(Scalar value, CountType weight)
Record a new value in the histogram, with a certain weight.
void load(const Eigen::DenseBase< EigenType > &d, const Eigen::DenseBase< EigenType2 > &derr, CountType off_chart_=0)
Load data for the histogram. Uses current histogram parameters, just sets the bin counts and the erro...
void printHistogramCsv(std::ostream &stream, const std::string sep="\, const std::string linesep="\", const int precision=10)
Produce a comma-separated-value (CSV) representation of the final aggregated histogram data...
HistogramWithErrorBars(const HistogramWithErrorBars &x)
Constructor: copy another histogram type.
Histogram(Histogram &&x)
Constructor: move another histogram type.
T setprecision(T... args)
HistogramWithErrorBars< Scalar, NewCountType > normalizedCounts() const
Get a version of this histogram, normalized by total counts.
Eigen::Index num_bins
Number of bins to split the range into.
Histogram aggregator, if each individual histogram already has error bars.
Histogram aggregator, if each histogram doesn't have error bars.
HistogramType::Params HistogramParams
The parameters type used to describe our histogram range and number of bins.
CountType_ CountType
The type that serves to count how many hits in each bin.
#define tomographer_assert(...)
Assertion test macro.
Scalar binLowerValue(Eigen::Index index) const
Shorthand for Params::binLowerValue()
Scalar min
Lower range value.
void finalize()
Finalize the averaging procedure.
Derived & setZero(Index size)
FinalHistogramType final_histogram
The final histogram, properly combining the error bars of each histogram.