Tomographer  v5.3
Tomographer C++ Framework Documentation
Tomographer::AveragedHistogram< HistogramType_, RealAvgType > Class Template Reference

Combines several histograms (with same parameters) into an averaged histogram. More...

#include <tomographer/histogram.h>

+ Inheritance diagram for Tomographer::AveragedHistogram< HistogramType_, RealAvgType >:
+ Collaboration diagram for Tomographer::AveragedHistogram< HistogramType_, RealAvgType >:

Public Types

typedef HistogramType_ HistogramType
 Type of the individual histograms we are averaging. More...
 
typedef HistogramWithErrorBars< typename HistogramType_::Scalar, RealAvgType > Base_
 Shortcut for our base class' type.
 
typedef Base_::Params Params
 The histogram parameters' type. See HistogramWithErrorBars::Params.
 
typedef Base_::Scalar Scalar
 The histogram's X-axis scalar type. See HistogramWithErrorBars::Scalar.
 
typedef Base_::CountType CountType
 The histogram' count type. This is exactly the same as RealAvgType.
 
- Public Types inherited from Tomographer::HistogramWithErrorBars< HistogramType_::Scalar, RealAvgType >
typedef HistogramType_::Scalar Scalar
 The Scalar (X-axis) Type. See Histogram::Scalar.
 
typedef RealAvgType CountType
 The Type used to keep track of counts. See Histogram::CountType.
 
typedef Histogram< HistogramType_::Scalar, RealAvgType > Base_
 Shortcut for our base class type.
 
typedef Base_::Params Params
 Shortcut for our base class' histogram parameters. See Histogram::Params.
 
- Public Types inherited from Tomographer::Histogram< HistogramType_::Scalar, RealAvgType >
typedef HistogramType_::Scalar Scalar
 The scalar type of the "X"-axis of the histogram (usually double)
 
typedef RealAvgType CountType
 The type that serves to count how many hits in each bin.
 
typedef HistogramParams< HistogramType_::Scalar > Params
 The type for specifying parameters of this histogram (limits, number of bins)
 

Public Member Functions

 AveragedHistogram (const Params &params=Params())
 Constructs an AveragedHistogram with the given histogram parameters. More...
 
 AveragedHistogram (Scalar min, Scalar max, Eigen::Index num_bins)
 Constructs an AveragedHistogram with the given histogram parameters. More...
 
 AveragedHistogram (const AveragedHistogram &copy)
 
 AveragedHistogram (AveragedHistogram &&x)
 
void reset (const Params &params_)
 Resets the data and sets new params. More...
 
void reset ()
 Resets the data keeping the exisiting params. More...
 
template<ENABLED_IF( !HistogramType::HasErrorBars) >
void addHistogram (const HistogramType &histogram)
 Add a new histogram in the data series. More...
 
template<ENABLED_IF( !HistogramType::HasErrorBars) >
void finalize ()
 Finalize the averaging procedure. More...
 
template<ENABLED_IF( HistogramType::HasErrorBars) >
void addHistogram (const HistogramType &histogram)
 Add a new histogram in the data series. More...
 
template<ENABLED_IF( HistogramType::HasErrorBars) >
void finalize ()
 Finalize the averaging procedure. More...
 
- Public Member Functions inherited from Tomographer::HistogramWithErrorBars< HistogramType_::Scalar, RealAvgType >
 HistogramWithErrorBars (Params params=Params())
 Constructor, with given histogram parameters. More...
 
 HistogramWithErrorBars (Scalar min, Scalar max, Eigen::Index num_bins)
 Constructor, with given histogram parameters. More...
 
 HistogramWithErrorBars (HistogramWithErrorBars &&x)
 Constructor: move another histogram type.
 
 HistogramWithErrorBars (const HistogramWithErrorBars &x)
 Constructor: copy another histogram type.
 
void reset ()
 Resets the histogram to zero counts everywhere, and zero error bars. More...
 
CountType errorBar (Eigen::Index i) const
 Get error bar for bin number i. More...
 
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 error bars. More...
 
HistogramWithErrorBars< Scalar, NewCountType > normalized () const
 Get a normalized version of this histogram. More...
 
HistogramWithErrorBars< Scalar, NewCountType > normalizedCounts () const
 Get a version of this histogram, normalized by total counts. More...
 
std::string prettyPrint (int max_width=0) const
 Print the histogram in human readable form. More...
 
- Public Member Functions inherited from Tomographer::Histogram< HistogramType_::Scalar, RealAvgType >
 Histogram (Params2 p=Params2())
 Constructor: stores the parameters and initializes the histogram to zero counts everywhere.
 
 Histogram (Scalar min_, Scalar max_, Eigen::Index num_bins)
 Constructor: stores the parameters and initializes the histogram to zero counts everywhere.
 
 Histogram (Histogram &&x)
 Constructor: move another histogram type.
 
 Histogram (const Histogram &x)
 Constructor: copy another histogram type.
 
void reset ()
 Resets the histogram to zero counts everywhere (including the off-chart counts)
 
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...
 
void add (const Eigen::ArrayBase< EigenType > &x, CountType off_chart_=0)
 Add data to the histogram. More...
 
void add (const Histogram< OtherScalar, OtherCountType > &x)
 Add data to the histogram. More...
 
Eigen::Index numBins () const
 Shorthand for params.num_bins
 
CountType count (Eigen::Index i) const
 Shorthand for bins(i)
 
bool isWithinBounds (Scalar value) const
 Shorthand for Params::isWithinBounds()
 
Eigen::Index binIndex (Scalar value) const
 Shorthand for Params::binIndex()
 
Scalar binLowerValue (Eigen::Index index) const
 Shorthand for Params::binLowerValue()
 
Scalar binCenterValue (Eigen::Index index) const
 Shorthand for Params::binCenterValue()
 
Scalar binUpperValue (Eigen::Index index) const
 Shorthand for Params::binUpperValue()
 
Scalar binResolution () const
 Shorthand for Params::binResolution()
 
Eigen::Index record (Scalar value)
 Record a new value in the histogram. More...
 
Eigen::Index record (Scalar value, CountType weight)
 Record a new value in the histogram, with a certain weight. More...
 
NewCountType normalization () const
 Calculate the total weight stored in this histogram. More...
 
Histogram< Scalar, NewCountType > normalized () const
 Get a normalized version of this histogram. More...
 
CountType totalCounts () const
 Return the total number of histogram counts (no normalization) More...
 
Histogram< Scalar, NewCountType > normalizedCounts () const
 Get a version of this histogram, normalized by total counts. 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

int num_histograms
 The number of histograms averaged. More...
 
- Public Attributes inherited from Tomographer::HistogramWithErrorBars< HistogramType_::Scalar, RealAvgType >
Eigen::Array< CountType, Eigen::Dynamic, 1 > delta
 The error bars associated with each histogram bin.
 
- Public Attributes inherited from Tomographer::Histogram< HistogramType_::Scalar, RealAvgType >
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 = true
 This histogram type does provide error bars.
 
- Static Public Attributes inherited from Tomographer::HistogramWithErrorBars< HistogramType_::Scalar, RealAvgType >
static constexpr bool HasErrorBars
 This type of histogram does provide error bars.
 
- Static Public Attributes inherited from Tomographer::Histogram< HistogramType_::Scalar, RealAvgType >
static constexpr bool HasErrorBars
 This histogram type does not provide error bars.
 

Additional Inherited Members

- Static Public Member Functions inherited from Tomographer::HistogramWithErrorBars< HistogramType_::Scalar, RealAvgType >
static HistogramWithErrorBars copy (const HistogramType &other)
 explicitly copy another histogram type
 
- Static Public Member Functions inherited from Tomographer::Histogram< HistogramType_::Scalar, RealAvgType >
static Histogram copy (const HistogramType &other)
 explicitly copy another histogram type
 

Detailed Description

template<typename HistogramType_, typename RealAvgType = double>
class Tomographer::AveragedHistogram< HistogramType_, RealAvgType >

Combines several histograms (with same parameters) into an averaged histogram.

What this class does exactly is explained on the page Averaged Histogram.

The HistogramType is expected to be a Histogram or a HistogramWithErrorBars type. It thus may, or may not, come with its own error bars. If this is the case, then the error bars are properly combined.

You should add histograms to average with repeated calls to addHistogram(). Then, you should call finalize(). Then this object, which inherits HistogramWithErrorBars, will be properly initialized with average counts and error bars.

Warning
All the histograms added with addHistogram() MUST have the same params, i.e. bin ranges and number of bins! The bin values are added up regardless of any parameters.
Don't forget to call finalize()! The bin counts in bins, off-chart count off_chart and error bars delta have UNDEFINED VALUES before calling finalize().
Template Parameters
HistgoramType_the type of the individual histograms that we are averaging.
RealAvgTypethe real scalar type used for averaging. You'll most likely want to choose double here. This can be different from the underlying HistogramType's CountType, because that may be an integer type and not suitable for holding an average.
Since
Since Tomographer 5.3, this class can be serialized with Boost.Serialization.

Definition at line 811 of file histogram.h.

Member Typedef Documentation

§ HistogramType

template<typename HistogramType_, typename RealAvgType = double>
typedef HistogramType_ Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::HistogramType

Type of the individual histograms we are averaging.

This is the argument given as template parameter.

Definition at line 819 of file histogram.h.

Constructor & Destructor Documentation

§ AveragedHistogram() [1/2]

template<typename HistogramType_, typename RealAvgType = double>
Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::AveragedHistogram ( const Params params = Params())
inline

Constructs an AveragedHistogram with the given histogram parameters.

The params are the histogram parameters (see Histogram::Params) of the individual histograms which will be averaged. Note that all those histograms must have the same params.

Definition at line 847 of file histogram.h.

§ AveragedHistogram() [2/2]

template<typename HistogramType_, typename RealAvgType = double>
Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::AveragedHistogram ( Scalar  min,
Scalar  max,
Eigen::Index  num_bins 
)
inline

Constructs an AveragedHistogram with the given histogram parameters.

This overload is provided for convenience and has the same effect as the other constructor.

Definition at line 857 of file histogram.h.

Member Function Documentation

§ addHistogram() [1/2]

template<typename HistogramType_, typename RealAvgType = double>
template<ENABLED_IF( !HistogramType::HasErrorBars) >
void Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::addHistogram ( const HistogramType histogram)
inline

Add a new histogram in the data series.

Add a new histogram to include into the final averaged histogram. Call this function repeatedly with different histograms you want to average together. When you're finished adding histograms, you must call finalize() in order to finalize the averaging; until then the members bins and delta (as well as count(), errorBar() etc.) yield undefined values.

Note
histogram must have the same range and number of bins as the params specified to the constructor of this class.

This implementation deals with the case where the individual histograms (such as histogram) don't have themselves error bars.

Definition at line 918 of file histogram.h.

§ addHistogram() [2/2]

template<typename HistogramType_, typename RealAvgType = double>
template<ENABLED_IF( HistogramType::HasErrorBars) >
void Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::addHistogram ( const HistogramType histogram)
inline

Add a new histogram in the data series.

Add a new histogram to include into the final averaged histogram. Call this function repeatedly with different histograms you want to average together. When you're finished adding histograms, you must call finalize() in order to finalize the averaging; until then the members bins and delta (as well as count(), errorBar() etc.) yield undefined values.

Note
histogram must have the same range and number of bins as the params specified to the constructor of this class.

This implementation deals with the case where the individual histograms (such as histogram) do have themselves error bars.

Definition at line 981 of file histogram.h.

§ finalize() [1/2]

template<typename HistogramType_, typename RealAvgType = double>
template<ENABLED_IF( !HistogramType::HasErrorBars) >
void Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::finalize ( )
inline

Finalize the averaging procedure.

Call this function once you have called addHistogram() for all the histograms you wanted to average together.

Only after this function was called may you access the averaged histogram data (in bins, delta, count() etc.). Before calling finalize(), those methods return undefined results.

Calling addHistogram() after finalize() will yield undefined results.

This implementation deals with the case where the individual histograms (such as histogram) don't have themselves error bars.

Definition at line 951 of file histogram.h.

§ finalize() [2/2]

template<typename HistogramType_, typename RealAvgType = double>
template<ENABLED_IF( HistogramType::HasErrorBars) >
void Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::finalize ( )
inline

Finalize the averaging procedure.

Call this function once you have called addHistogram() for all the histograms you wanted to average together.

Only after this function was called may you access the averaged histogram data (in bins, delta, count() etc.). Before calling finalize(), those methods return undefined results.

Calling addHistogram() after finalize() will yield undefined results.

This implementation deals with the case where the individual histograms (such as histogram) do have themselves error bars.

Definition at line 1013 of file histogram.h.

§ reset() [1/2]

template<typename HistogramType_, typename RealAvgType = double>
void Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::reset ( const Params params_)
inline

Resets the data and sets new params.

Warning
the corresponding base class has NO virtual methods. So don't see this class inheritance as object polymorphism. If you need to reset a uniform bins histogram with error bars, you need to know its type.

Definition at line 880 of file histogram.h.

§ reset() [2/2]

template<typename HistogramType_, typename RealAvgType = double>
void Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::reset ( )
inline

Resets the data keeping the exisiting params.

Warning
the corresponding base class has NO virtual methods. So don't see this class inheritance as object polymorphism. If you need to reset a uniform bins histogram with error bars, you need to know its type.

Definition at line 893 of file histogram.h.

Member Data Documentation

§ num_histograms

template<typename HistogramType_, typename RealAvgType = double>
int Tomographer::AveragedHistogram< HistogramType_, RealAvgType >::num_histograms

The number of histograms averaged.

This member records how many histograms have been added using addHistogram() since the object was created or was last reset().

Definition at line 838 of file histogram.h.


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