BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
Class to accumulate and merge histograms in different ways. More...
#include <HistogramAccumulator.hh>
Public Member Functions | |
HistogramAccumulator () | |
Default constructor only for ROOT reflexivity - not intended for use. | |
HistogramAccumulator (TH1 *baseHistogram, const std::string &resultHistNameIn, const std::string &resultHistTitleIn) | |
HistogramAccumulator (TH1 *baseHistogram, int nDimensionsIn, const std::string &resultHistName, const std::string &resultHistTitle) | |
virtual | ~HistogramAccumulator () |
virtual void | Accumulate (TH1 *newValue) |
virtual TH1 * | Terminate () |
TH1 * | Result () const |
Accessor. | |
void | AddNEmptyEntries (unsigned long i) |
unsigned long | N () const |
Access currently accumulated number of entries. | |
Protected Member Functions | |
virtual void | AccumulateSingleValue (double oldMean, double oldVari, double x, double xVari, unsigned long nEntriesAccumulated, unsigned long nEntriesToAccumulate, double &newMean, double &newVari) const |
ClassDef (HistogramAccumulator, 1) | |
Protected Attributes | |
int | nDimensions |
Number of dimensions. | |
unsigned long | n |
Counter. | |
bool | terminated |
Whether this instance has been finished. | |
const std::string | resultHistName |
Name for resultant histogram. | |
const std::string | resultHistTitle |
Title for resultant histogram. | |
TH1 * | mean |
TH1 * | variance |
TH1 * | result |
Class to accumulate and merge histograms in different ways.
This acts as a base class to accumulate a single histogram from many. The default implementation is to calculate the mean and the standard error on the mean, however, the AccumulateSingleValue() function is virtual and may be overridden to provide different functionality.
TH1 is the base class of all ROOT histograms so even 2 and 3D histograms can be supplied through a TH1 pointer. These are statically cast to TH1D, TH2D and TH3D based on the number of dimensions (1,2 or 3 only).
A result histogram name can be specified. Note ROOT uses this to create objects in the currently open file (lots of static stuff) and therefore this should be unique from the supplied base histogram name!
Each instance is single use. Once terminated, the accumulation should not be used.
The algorithm used to calculate the mean and variance is one that supports online calculation and is numerically stable.
Normally, at least 2 entries should be accumulated to calculate the variance and to avoid nans from 1/(n-1), however, in this special case, the bin error is set to 0.
Definition at line 57 of file HistogramAccumulator.hh.
HistogramAccumulator::HistogramAccumulator | ( | TH1 * | baseHistogram, |
const std::string & | resultHistNameIn, | ||
const std::string & | resultHistTitleIn | ||
) |
Construct Accumulator based on another histogram of 1,2, or 3 dimensions. Inspects the TH1 (ie base class) instance to get the number of dimensions then uses the next constructor.
Definition at line 43 of file HistogramAccumulator.cc.
HistogramAccumulator::HistogramAccumulator | ( | TH1 * | baseHistogram, |
int | nDimensionsIn, | ||
const std::string & | resultHistName, | ||
const std::string & | resultHistTitle | ||
) |
Construct accumulator based on another histogram of 1,2 or 3 dimensions. Note, the result name must be different from that of baseHistogram if baseHistogram exists in the currently open file.
Definition at line 49 of file HistogramAccumulator.cc.
References nDimensions, resultHistName, and resultHistTitle.
|
virtual |
Destructor deletes mean and variance temporary histograms but leaks result as deleting it would remove it from the open file in ROOT.
Definition at line 128 of file HistogramAccumulator.cc.
|
virtual |
Loop over the bins in a histogram and accumulate that bin from a new histogram ("newValue"). newValue is assumed to be the exact same as the baseHistogram the instance of this class was constructed with.
Reimplemented in HistogramAccumulatorMerge, and HistogramAccumulatorSum.
Definition at line 136 of file HistogramAccumulator.cc.
References AccumulateSingleValue(), n, and nDimensions.
Referenced by PerEntryHistogram::AccumulateCurrentEntry().
|
protectedvirtual |
Accumulate a single value into the online mean and variance histograms. This by default accumulates the mean and variance with a new value x. The xVari argument is not used in the implementation provided with this class but is used in derived classes with different AccumulateSingleValue implementations.
Reimplemented in HistogramAccumulatorMerge.
Definition at line 343 of file HistogramAccumulator.cc.
Referenced by Accumulate().
|
inline |
Permit the number of recorded entries to be incremented with zero values, ie just increment n.
Definition at line 96 of file HistogramAccumulator.hh.
References n.
Referenced by PerEntryHistogram::AddNEmptyEntries().
|
inline |
Access currently accumulated number of entries.
Definition at line 99 of file HistogramAccumulator.hh.
References n.
|
inline |
Accessor.
Definition at line 92 of file HistogramAccumulator.hh.
|
virtual |
Write the result to the result histogram. Calculate the standard error on the mean from the variance for the error in each bin.
Reimplemented in HistogramAccumulatorSum.
Definition at line 242 of file HistogramAccumulator.cc.
References n, and nDimensions.
Referenced by PerEntryHistogram::Terminate().
|
protected |
Definition at line 121 of file HistogramAccumulator.hh.
|
protected |
Counter.
Definition at line 117 of file HistogramAccumulator.hh.
Referenced by Accumulate(), HistogramAccumulatorMerge::Accumulate(), AddNEmptyEntries(), N(), and Terminate().
|
protected |
Number of dimensions.
Definition at line 116 of file HistogramAccumulator.hh.
Referenced by Accumulate(), HistogramAccumulatorMerge::Accumulate(), HistogramAccumulator(), and Terminate().
|
protected |
Definition at line 123 of file HistogramAccumulator.hh.
|
protected |
Name for resultant histogram.
Definition at line 119 of file HistogramAccumulator.hh.
Referenced by HistogramAccumulator().
|
protected |
Title for resultant histogram.
Definition at line 120 of file HistogramAccumulator.hh.
Referenced by HistogramAccumulator().
|
protected |
Whether this instance has been finished.
Definition at line 118 of file HistogramAccumulator.hh.
|
protected |
Definition at line 122 of file HistogramAccumulator.hh.