39 #include <type_traits> 42 #include <boost/math/constants/constants.hpp> 66 template<
typename Scalar_ =
double>
73 inline HistogramParams(Scalar min_ = 0.0, Scalar max_ = 1.0, Eigen::Index num_bins_ = 50)
74 : min(min_), max(max_), num_bins(num_bins_)
78 template<
typename Params2
79 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 81 , decltype((
int)std::declval<const Params2>().min + (
int)std::declval<const Params2>().max
82 + std::declval<Params2>().num_bins) dummyval = 0
86 : min(other.min), max(other.max), num_bins(other.num_bins)
114 if ( !isWithinBounds(value) ) {
116 <<
" out of range ["<<min<<
","<<max<<
"["));
118 return binIndexUnsafe(value);
130 return (Eigen::Index)((value-min) / (max-min) * num_bins);
143 return min + index * (max-min) / num_bins;
155 return min + (index+boost::math::constants::half<Scalar>()) * (max-min) / num_bins;
168 return min + (index+1) * (max-min) / num_bins;
176 return (max - min) / num_bins;
183 const auto halfbinres = boost::math::constants::half<Scalar>() * binResolution();
212 template<
typename Scalar_,
typename CountType_ =
int>
230 static constexpr
bool HasErrorBars =
false;
243 template<
typename Params2 = Params
244 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 246 , decltype((
int)std::declval<const Params2>().min + (
int)std::declval<const Params2>().max
247 + std::declval<Params2>().num_bins) dummyval = 0
251 : params(p), bins(
Eigen::Array<CountType,
Eigen::Dynamic,1>::Zero(p.num_bins)),
257 Histogram(Scalar min_, Scalar max_, Eigen::Index num_bins)
258 : params(min_, max_, num_bins), bins(
Eigen::Array<CountType,
Eigen::Dynamic,1>::Zero(num_bins)),
265 : params(
std::move(x.params)),
266 bins(
std::move(x.bins)),
267 off_chart(x.off_chart)
275 off_chart(x.off_chart)
280 template<
typename HistogramType,
282 TOMOGRAPHER_ENABLED_IF_TMPL(HistogramType::HasErrorBars == 0 ||
283 HistogramType::HasErrorBars == 1)>
287 h.
bins = other.bins.template cast<CountType>();
309 template<
typename EigenType>
314 bins = x.derived().template cast<CountType>();
315 off_chart = off_chart_;
326 template<
typename EigenType>
334 bins += x.derived().template cast<CountType>();
335 off_chart += off_chart_;
346 template<
typename OtherScalar,
typename OtherCountType>
353 bins += x.
bins.template cast<CountType>();
364 inline CountType
count(Eigen::Index i)
const 411 if ( !isWithinBounds(value) ) {
432 if ( !isWithinBounds(value) ) {
439 bins(index) += weight;
457 template<
typename NewCountType = decltype(Scalar(1) + CountType(1))>
462 return NewCountType(off_chart) + NewCountType(binResolution() * bins.sum());
472 template<
typename NewCountType = Scalar>
476 const NewCountType f = normalization<NewCountType>();
477 h.
load(bins.template cast<NewCountType>() / f, NewCountType(off_chart) / f);
491 return bins.sum() + off_chart;
505 template<
typename NewCountType = Scalar>
509 const NewCountType f = totalCounts();
510 h.
load(bins.template cast<NewCountType>() / f, NewCountType(off_chart) / f);
525 template<
typename Scalar_,
typename CountType_>
536 template<
typename Scalar_,
typename CountType_ =
double>
555 static constexpr
bool HasErrorBars =
true;
563 using Base_::off_chart;
572 : Base_(params), delta(
Eigen::Array<CountType,
Eigen::Dynamic, 1>::Zero(params.num_bins))
582 : Base_(min, max, num_bins), delta(
Eigen::Array<CountType,
Eigen::Dynamic, 1>::Zero(num_bins))
588 : Base_(
std::move(x)),
589 delta(
std::move(x.delta))
602 template<
typename HistogramType,
603 TOMOGRAPHER_ENABLED_IF_TMPL(HistogramType::HasErrorBars == 1)>
607 h.
bins = other.bins.template cast<CountType>();
608 h.
delta = other.delta.template cast<CountType>();
622 delta.
resize(Base_::numBins());
648 template<
typename EigenType,
typename EigenType2 = EigenType>
651 CountType off_chart_ = 0)
653 Base_::load(d, off_chart_);
656 delta = derr.derived().template cast<CountType>();
667 template<
typename NewCountType = Scalar>
671 const NewCountType f = Base_::template normalization<NewCountType>();
672 h.
load(bins.template cast<NewCountType>() / f,
673 delta.template cast<NewCountType>() / f,
674 NewCountType(off_chart) / f);
688 template<
typename NewCountType = Scalar>
692 const NewCountType f = Base_::totalCounts();
693 h.
load(bins.template cast<NewCountType>() / f,
694 delta.template cast<NewCountType>() / f,
695 NewCountType(off_chart) / f);
704 template<
typename... Args>
705 inline void add(Args && ... )
711 template<
typename... Args>
712 inline void record(Args && ... )
732 template<
typename Scalar_,
typename CountType_>
770 template<
typename HistogramType_,
typename RealAvgType =
double>
791 static constexpr
bool HasErrorBars =
true;
808 : Base_(params), num_histograms(0)
818 : Base_(min, max, num_bins), num_histograms(0)
829 num_histograms(x.num_histograms)
840 inline void reset(
const Params& params_)
842 Base_::params = params_;
877 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
878 inline
void addHistogram(const HistogramType& histogram)
884 (
typename HistogramType::CountType)Base_::numBins());
886 for (Eigen::Index k = 0; k < histogram.numBins(); ++k) {
887 RealAvgType binvalue = histogram.count(k);
888 Base_::bins(k) += binvalue;
889 Base_::delta(k) += binvalue * binvalue;
892 Base_::off_chart += histogram.off_chart;
910 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
911 inline
void finalize()
913 Base_::bins /= num_histograms;
914 Base_::delta /= num_histograms;
915 Base_::off_chart /= num_histograms;
918 auto finhist2 = Base_::bins*Base_::bins;
919 Base_::delta = ( (Base_::delta - finhist2) / (num_histograms-1) ).sqrt();
940 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
946 tomographer_assert((
typename HistogramType::CountType)histogram.numBins() == Base_::numBins());
948 for (Eigen::Index k = 0; k < histogram.numBins(); ++k) {
949 RealAvgType binvalue = histogram.count(k);
950 Base_::bins(k) += binvalue;
951 RealAvgType bindelta = histogram.errorBar(k);
952 Base_::delta(k) += bindelta*bindelta;
955 Base_::off_chart += histogram.off_chart;
972 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
973 inline
void finalize()
975 Base_::bins /= num_histograms;
976 Base_::off_chart /= num_histograms;
978 Base_::delta = Base_::delta.sqrt();
979 Base_::delta /= num_histograms;
1011 template<
typename HistogramType_,
typename CountRealType_>
1014 AveragedHistogram<HistogramType_,CountRealType_>
1043 : final_histogram(
std::move(x.final_histogram))
1080 template<
typename ContainerType,
typename ExtractHistogramFn>
1082 const ContainerType & list,
1083 ExtractHistogramFn extract_histogram_fn)
1085 FinalHistogramType h(params);
1088 for (
const auto item : list) {
1115 const int precision = 10)
1117 stream <<
"Value" << sep <<
"Counts" << sep <<
"Error" << linesep
1119 for (Eigen::Index kk = 0; kk < final_histogram.
bins.size(); ++kk) {
1121 << final_histogram.
bins(kk) << sep
1122 << final_histogram.
delta(kk) << linesep;
1158 template<
typename HistogramType_,
typename CountRealType_>
1161 AveragedHistogram<HistogramType_, CountRealType_> ,
1162 AveragedHistogram<Histogram<typename HistogramType_::Scalar,
1163 typename HistogramType_::CountType>,
1201 : final_histogram(
std::move(x.final_histogram)),
1202 simple_final_histogram(
std::move(x.simple_final_histogram))
1243 template<
typename ContainerType,
typename ExtractHistogramFn>
1245 const ContainerType & list,
1246 ExtractHistogramFn extract_histogram_fn)
1249 FinalHistogramType hist(params);
1250 SimpleFinalHistogramType histsimple(params);
1253 for (
const auto& item : list) {
1254 const auto& h = extract_histogram_fn(item);
1289 const int precision = 10)
1291 stream <<
"Value" << sep <<
"Counts" << sep <<
"Error" << sep <<
"SimpleError" << linesep
1293 for (Eigen::Index kk = 0; kk < final_histogram.
bins.size(); ++kk) {
1295 << final_histogram.
bins(kk) << sep
1296 << final_histogram.
delta(kk) << sep
1297 << simple_final_histogram.
delta(kk) << linesep;
1316 namespace tomo_internal {
1321 template<
typename Scalar,
typename Fn>
1322 inline Scalar max_finite_value(
const Eigen::Index num_items, Fn val_generator,
1323 const Scalar default_val = Scalar(1.0))
1325 bool has_first_val =
false;
1326 Scalar max_val = default_val;
1327 for (Eigen::Index k = 0; k < num_items; ++k) {
1328 const Scalar this_val = val_generator(k);
1329 if (
Tools::isFinite(this_val) && (!has_first_val || this_val > max_val)) {
1331 has_first_val =
true;
1340 template<
typename HistogramType>
1341 struct histogram_pretty_print_label
1345 labels.
resize(hist.numBins());
1346 for (
std::size_t k = 0; k < hist.numBins(); ++k) {
1355 template<
typename HistogramType>
1360 const typename HistogramType::Scalar max_label_val
1361 =
std::max(hist.binCenterValue(0), hist.binCenterValue(hist.numBins()-1));
1363 const int relprecision = 4;
1364 const int precision = (powten > relprecision) ? 0 : (relprecision - powten - 1);
1366 for (Eigen::Index k = 0; k < hist.numBins(); ++k) {
1373 template<
typename Scalar_,
typename CountType_>
1374 struct histogram_pretty_print_label<Histogram<Scalar_, CountType_> >
1379 histogram_get_labels_for_hist_params<HistogramType>(labels, hist);
1383 template<
typename Scalar_,
typename CountType_>
1384 struct histogram_pretty_print_label<HistogramWithErrorBars<Scalar_, CountType_> >
1389 histogram_get_labels_for_hist_params<HistogramType>(labels, hist);
1393 template<
typename BaseHistogramType_,
typename RealAvgType_>
1394 struct histogram_pretty_print_label<AveragedHistogram<BaseHistogramType_, RealAvgType_> >
1399 histogram_get_labels_for_hist_params<HistogramType>(labels, hist);
1404 template<
typename HistogramType>
1405 struct histogram_pretty_print_value
1408 histogram_pretty_print_value(
const HistogramType & hist_) : hist(hist_) { }
1410 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
1415 typename HistogramType::CountType max_val =
1416 max_finite_value<typename HistogramType::CountType>(hist.numBins(),
1417 [&](Eigen::Index k) {
return hist.count(k); },
1418 typename HistogramType::CountType(1));
1421 const int relprecision = 3;
1422 const int precision = abs_precision_for(powten, relprecision);
1423 const int w = (precision > 0) ? (precision+powten+1) : (relprecision+2);
1425 for (Eigen::Index k = 0; k < hist.numBins(); ++k) {
1433 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1438 typename HistogramType::CountType max_val =
1439 max_finite_value<typename HistogramType::CountType>(hist.numBins(),
1440 [&](Eigen::Index k) {
return hist.count(k); },
1441 typename HistogramType::CountType(1));
1444 const int relprecision = 3;
1445 const int precision = abs_precision_for(powten, relprecision);
1446 const int w = (precision > 0) ? (precision+powten+2) : (relprecision+2);
1448 for (Eigen::Index k = 0; k < hist.numBins(); ++k) {
1451 << hist.count(k) <<
" +- " 1453 << hist.errorBar(k);
1458 static inline int abs_precision_for(
const int powten,
const int relprecision)
1460 return (powten >= relprecision) ? 0 : (relprecision - powten - 1);
1468 template<
typename HistogramType>
1469 struct histogram_pretty_printer
1472 const int max_width;
1475 typedef decltype(
typename HistogramType::CountType(1) +
double(1)) CountType;
1486 CountType max_value;
1491 histogram_pretty_printer(
const HistogramType & hist_,
const int max_width_)
1492 : hist(hist_), max_width(max_width_), lsep(
" |"), rsep(
" ")
1501 histogram_pretty_print_label<HistogramType>::getLabels(labels, hist);
1502 histogram_pretty_print_value<HistogramType>::getStrValues(svalues, hist);
1504 bool has_maxval =
false;
1506 const CountType val = maxval(k);
1512 if (k == 0 || (
int)labels[k].size() > maxlabelwidth) {
1513 maxlabelwidth = (int)labels[k].size();
1515 if (k == 0 || (
int)svalues[k].
size() > maxsvaluewidth) {
1516 maxsvaluewidth = (int)svalues[k].size();
1523 max_bar_width = max_width - maxlabelwidth - maxsvaluewidth - (int)lsep.
size() - (int)rsep.
size();
1524 if (max_bar_width < 2) {
1527 barscale = ((max_value > 0) ? (max_value / max_bar_width) : 1.0);
1530 inline std::size_t value_to_bar_length(CountType val)
const 1542 inline void fill_str_len(
std::string & s, CountType valstart, CountType valend,
1543 char c,
char clside,
char crside)
const 1554 if (clside && crside && clside != crside && vs == ve) {
1555 if (ve < s.
size()-1) {
1557 }
else if (vs > 1) {
1575 str <<
std::setw(maxlabelwidth) << labels[k] << lsep
1576 << make_bar(k) << rsep <<
std::setw(maxsvaluewidth) << svalues[k] <<
"\n";
1582 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
1583 inline CountType maxval(
const std::size_t k)
const 1585 return hist.count((Eigen::Index)k);
1587 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1588 inline CountType maxval(
const std::size_t k)
const 1590 return (hist.count((Eigen::Index)k) + hist.errorBar((Eigen::Index)k));
1593 TOMOGRAPHER_ENABLED_IF(!HistogramType::HasErrorBars)
1597 fill_str_len(sbar, 0.0, hist.count((Eigen::Index)k),
'*', 0, 0);
1600 TOMOGRAPHER_ENABLED_IF(HistogramType::HasErrorBars)
1604 const typename HistogramType::CountType binval = hist.count((Eigen::Index)k);
1605 const typename HistogramType::CountType binerr = hist.errorBar((Eigen::Index)k);
1606 fill_str_len(sbar, 0.0, binval - binerr,
'*',
'*',
'*');
1607 fill_str_len(sbar, binval - binerr, binval + binerr,
'-',
'|',
'|');
1612 template<
typename HistogramType>
1614 const int max_width)
1618 if (histogram.off_chart > 0) {
1619 send +=
Tools::fmts(
" [+%.1g off]", (
double)histogram.off_chart);
1622 const int maxbarwidth = max_width - (int)s.
size() - (int)send.size();
1623 const int numdiv = (int)(
std::ceil((
float)histogram.numBins() / maxbarwidth) + 0.5f);
1624 const int barwidth = (int)(
std::ceil((
float)histogram.numBins() / numdiv) + 0.5f);
1627 Eigen::ArrayXf veclog(barwidth);
1630 float minlogval = 0;
1631 float maxlogval = 0;
1632 for (k = 0; k < barwidth; ++k) {
1633 vec(k) = histogram.bins.
segment((Eigen::Index)(numdiv*k),
1635 (Eigen::Index)(histogram.bins.size()-numdiv*k))).sum();
1638 veclog(k) =
std::log((
float)vec(k));
1640 veclog(k) = (float)vec(k);
1642 if (k == 0 || minlogval > veclog(k)) {
1643 minlogval = veclog(k);
1645 if (k == 0 || maxlogval < veclog(k)) {
1646 maxlogval = veclog(k) + 1e-6f;
1655 for (k = 0; k < barwidth; ++k) {
1659 int i = (int)(chars.
size() * (veclog(k) - minlogval) / (maxlogval - minlogval));
1660 if (i < 0) { i = 0; }
1661 if (i >= (
int)chars.
size()) { i = (int)chars.
size()-1; }
1682 template<
typename HistogramType>
1687 if (histogram.params.num_bins == 0) {
1688 str <<
"<empty histogram: no bins>\n";
1693 tomo_internal::histogram_pretty_printer<HistogramType>(histogram, max_width).pretty_print(str);
1704 template<
typename HistogramType>
1708 histogramPrettyPrint<HistogramType>(ss, histogram, max_width);
1729 template<
typename HistogramType>
1731 bool log_scale =
true,
int max_width = 0)
1738 if (histogram.params.num_bins == 0) {
1739 s =
"<empty histogram: no bins>";
1741 s = tomo_internal::histogram_short_bar_fmt<HistogramType>(histogram, log_scale, max_width);
1745 return max_width - (int)s.
size();
1757 template<
typename HistogramType>
1762 if (histogram.params.num_bins == 0) {
1763 return "<empty histogram: no bins>";
1767 return tomo_internal::histogram_short_bar_fmt<HistogramType>(histogram, log_scale, max_width);
1785 template<
typename HistogramType>
1788 const HistogramType& hist,
1790 bool log_scale =
true,
1791 int full_max_width = 0)
1796 const int w =
histogramShortBar(str, hist, log_scale, full_max_width - (
int)head.size() - (int)tail.
size());
1814 template<
typename HistogramType>
1816 const HistogramType& hist,
1818 bool log_scale =
true,
1819 int full_max_width = 0)
1831 template<
typename Scalar_ =
double>
1833 template<
typename Scalar_,
typename CountType_ =
int>
1835 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.