Tomographer  v2.0
Tomographer C++ Framework Documentation
Tomographer::UniformBinsHistogram< Scalar_, CountType_ > Struct Template Reference

Stores a histogram. More...

#include <tomographer2/histogram.h>

+ Inheritance diagram for Tomographer::UniformBinsHistogram< Scalar_, CountType_ >:
+ Collaboration diagram for Tomographer::UniformBinsHistogram< Scalar_, CountType_ >:

Classes

struct  Params
 The parameters of a UniformBinsHistogram. More...
 

Public Types

typedef Scalar_ Scalar
 The scalar type of the "X"-axis of the histogram (usually double)
 
typedef CountType_ CountType
 The type that serves to count how many hits in each bin.
 
- Public Types inherited from Tomographer::Tools::EigenAlignedOperatorNewProvider
typedef EigenAlignedOperatorNewProvider OperatorNewProviderType
 

Public Member Functions

 UniformBinsHistogram (Params p=Params())
 Constructor: stores the parameters and initializes the histogram to zero counts everywhere.
 
 UniformBinsHistogram (Scalar min_, Scalar max_, std::size_t num_bins)
 Constructor: stores the parameters and initializes the histogram to zero counts everywhere.
 
template<typename HistogramType >
 UniformBinsHistogram (const HistogramType &other)
 Constructor: copy another histogram type.
 
void reset ()
 Resets the histogram to zero counts everywhere.
 
template<typename EigenType >
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. More...
 
template<typename EigenType >
void add (const Eigen::ArrayBase< EigenType > &x, CountType off_chart_=0)
 Add data to the histogram. More...
 
template<typename OtherScalar , typename OtherCountType >
void add (const UniformBinsHistogram< OtherScalar, OtherCountType > &x)
 Add data to the histogram. More...
 
std::size_t numBins () const
 Shorthand for params.num_bins
 
CountType count (std::size_t i) const
 Shorthand for bins(i)
 
bool isWithinBounds (Scalar value) const
 Shorthand for Params::isWithinBounds()
 
std::size_t binIndex (Scalar value) const
 Shorthand for Params::binIndex()
 
Scalar binLowerValue (int index) const
 Shorthand for Params::binLowerValue()
 
Scalar binCenterValue (std::size_t index) const
 Shorthand for Params::binCenterValue()
 
Scalar binUpperValue (std::size_t index) const
 Shorthand for Params::binUpperValue()
 
Scalar binResolution () const
 Shorthand for Params::binResolution()
 
std::size_t record (Scalar value)
 Record a new value in the histogram. More...
 
std::size_t record (Scalar value, CountType weight)
 Record a new value in the histogram, with a certain weight. More...
 
std::string prettyPrint (int max_width=0) const
 Pretty-print the histogram and return it as a string with horizontal bars. More...
 

Public Attributes

Params params
 Parameters of this histogram (range and # of bins)
 
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.
 

Static Public Attributes

static constexpr bool HasErrorBars = false
 This histogram type does not provide error bars (see Histogram Interface)
 

Detailed Description

template<typename Scalar_, typename CountType_ = unsigned int>
struct Tomographer::UniformBinsHistogram< Scalar_, CountType_ >

Stores a histogram.

Splits the range of values \([\text{min},\text{max}]\) into num_bins number of bins, and keeps counts of how many samples fell in which bin.

Does not store any form of error bars. Complies with the Histogram Interface.

Definition at line 68 of file histogram.h.

Member Function Documentation

template<typename Scalar_, typename CountType_ = unsigned int>
template<typename EigenType >
void Tomographer::UniformBinsHistogram< Scalar_, CountType_ >::add ( const Eigen::ArrayBase< EigenType > &  x,
CountType  off_chart_ = 0 
)
inline

Add data to the histogram.

Parameters
xis an Eigen Vector or 1-D Array from which to load data to add to the histogram counts. It must be (dense) Eigen::ArrayBase-derived type, have one column and exactly numBins() rows.
off_chart_if provided, add this amount to the off_chart counts.

Definition at line 255 of file histogram.h.

template<typename Scalar_, typename CountType_ = unsigned int>
template<typename OtherScalar , typename OtherCountType >
void Tomographer::UniformBinsHistogram< Scalar_, CountType_ >::add ( const UniformBinsHistogram< OtherScalar, OtherCountType > &  x)
inline

Add data to the histogram.

Adds the values contained in the other histogram x to the current histogram. This also updates the off_chart counts.

Warning
The histogram x must have the same params as the current one. An assertion check is performed that this is the case (up to some small tolerance).

Definition at line 275 of file histogram.h.

template<typename Scalar_, typename CountType_ = unsigned int>
template<typename EigenType >
void Tomographer::UniformBinsHistogram< Scalar_, CountType_ >::load ( const Eigen::DenseBase< EigenType > &  x,
CountType  off_chart_ = 0 
)
inline

Load data for the histogram. Uses current histogram parameters, just sets the bin counts.

Parameters
xis an Eigen Vector or 1-D Array from which to load the data. It must be dense, have one column and exactly numBins() rows.
off_chart_if provided, then set the off_chart count to this number. Otherwise, reset the off_chart counts to zero.

Definition at line 238 of file histogram.h.

template<typename Scalar_, typename CountType_ = unsigned int>
std::string Tomographer::UniformBinsHistogram< Scalar_, CountType_ >::prettyPrint ( int  max_width = 0) const
inline

Pretty-print the histogram and return it as a string with horizontal bars.

Parameters
max_widthis the maximum line width the display should fit in.

Definition at line 377 of file histogram.h.

template<typename Scalar_, typename CountType_ = unsigned int>
std::size_t Tomographer::UniformBinsHistogram< Scalar_, CountType_ >::record ( Scalar  value)
inline

Record a new value in the histogram.

This adds one to the bin corresponding to the given value.

If the value is out of the histogram range, then off_chart is incremented by one.

Returns the index of the bin in which the value was added, or "std::numeric_limits<std::size_t>::max()" if off-chart.

Definition at line 338 of file histogram.h.

template<typename Scalar_, typename CountType_ = unsigned int>
std::size_t Tomographer::UniformBinsHistogram< Scalar_, CountType_ >::record ( Scalar  value,
CountType  weight 
)
inline

Record a new value in the histogram, with a certain weight.

This adds weight to the histogram bin corresponding to the given value.

If the value is out of the histogram range, then off_chart is incremented by weight.

Returns the index of the bin in which the value was added, or "std::numeric_limits<std::size_t>::max()" if off-chart.

Definition at line 360 of file histogram.h.


The documentation for this struct was generated from the following file: