thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
LWH::Histogram1D Class Reference

User level interface to 1D Histogram. More...

#include <Histogram1D.h>

Inheritance diagram for LWH::Histogram1D:

Public Member Functions

 Histogram1D (int n, double lo, double up)
 Standard constructor.
 
 Histogram1D (const std::vector< double > &edges)
 Standard constructor for variable bin width.
 
 Histogram1D (const Histogram1D &h)
 Copy constructor.
 
virtual ~Histogram1D ()
 Destructor.
 
std::string title () const
 Get the Histogram's title.
 
std::string name () const
 Get the Histogram's title.
 
bool setTitle (const std::string &title)
 Set the histogram title.
 
IAnnotation & annotation ()
 Not implemented in LWH.
 
const IAnnotation & annotation () const
 Not implemented in LWH.
 
int dimension () const
 Get the Histogram's dimension.
 
bool reset ()
 Reset the Histogram; as if just created.
 
int entries () const
 Get the number of in-range entries in the Histogram.
 
int allEntries () const
 Sum of the entries in all the IHistogram's bins, i.e in-range bins, UNDERFLOW and OVERFLOW.
 
int extraEntries () const
 Number of entries in the UNDERFLOW and OVERFLOW bins.
 
double equivalentBinEntries () const
 Number of equivalent entries, i.e.
 
double sumBinHeights () const
 Sum of in-range bin heights in the IHistogram, UNDERFLOW and OVERFLOW bins are excluded.
 
double sumAllBinHeights () const
 Sum of the heights of all the IHistogram's bins, i.e in-range bins, UNDERFLOW and OVERFLOW.
 
double sumExtraBinHeights () const
 Sum of heights in the UNDERFLOW and OVERFLOW bins.
 
double minBinHeight () const
 Minimum height of the in-range bins, i.e.
 
double maxBinHeight () const
 Maximum height of the in-range bins, i.e.
 
bool fill (double x, double weight=1.)
 Fill the IHistogram1D with a value and the corresponding weight.
 
double binMean (int index) const
 The weighted mean of a bin.
 
double binRms (int index) const
 The weighted RMS of a bin.
 
int binEntries (int index) const
 Number of entries in the corresponding bin (ie the number of times fill was called for this bin).
 
double binHeight (int index) const
 Total height of the corresponding bin (ie the sum of the weights in this bin).
 
double binError (int index) const
 The error of a given bin.
 
double mean () const
 The mean of the whole IHistogram1D.
 
double rms () const
 The RMS of the whole IHistogram1D.
 
const IAxis & axis () const
 Get the x axis of the IHistogram1D.
 
int coordToIndex (double coord) const
 Get the bin number corresponding to a given coordinate along the x axis.
 
bool add (const Histogram1D &h)
 Add to this Histogram1D the contents of another IHistogram1D.
 
bool add (const IHistogram1D &hist)
 Add to this IHistogram1D the contents of another IHistogram1D.
 
bool scale (double s)
 Scale the contents of this histogram with the given factor.
 
void normalize (double intg)
 Scale the given histogram so that the integral over all bins (including overflow) gives intg.
 
double integral () const
 Return the integral over the histogram bins assuming it has been normalize()d.
 
void * cast (const std::string &) const
 Not implemented in LWH.
 
bool writeXML (std::ostream &os, std::string path, std::string name)
 Write out the histogram in the AIDA xml format.
 
bool writeFLAT (std::ostream &os, std::string path, std::string name)
 Write out the histogram in a flat text file suitable for eg.
 
- Public Member Functions inherited from LWH::ManagedObject
virtual ~ManagedObject ()
 Destructor.
 
virtual bool writeXML (std::ostream &os, std::string path, std::string name)=0
 Write out the object to the given stream in XML format.
 
virtual bool writeFLAT (std::ostream &os, std::string path, std::string name)=0
 Write out the object to the given stream in simple table format.
 

Private Attributes

std::string theTitle
 The title.
 
IAxis * ax
 The axis.
 
Axisfax
 Pointer (possibly null) to a axis with fixed bin width.
 
VariAxisvax
 Pointer (possibly null) to a axis with fixed bin width.
 
std::vector< int > sum
 The counts.
 
std::vector< double > sumw
 The weights.
 
std::vector< double > sumw2
 The squared weights.
 
std::vector< double > sumxw
 The weighted x-values.
 
std::vector< double > sumx2w
 The weighted x-square-values.
 

Friends

class HistogramFactory
 HistFactory is a friend.
 

Detailed Description

User level interface to 1D Histogram.

Definition at line 29 of file Histogram1D.h.

Constructor & Destructor Documentation

◆ Histogram1D() [1/3]

LWH::Histogram1D::Histogram1D ( int  n,
double  lo,
double  up 
)
inline

Standard constructor.

Definition at line 41 of file Histogram1D.h.

References ax, and fax.

◆ Histogram1D() [2/3]

LWH::Histogram1D::Histogram1D ( const std::vector< double > &  edges)
inline

Standard constructor for variable bin width.

Definition at line 50 of file Histogram1D.h.

References ax, and vax.

◆ Histogram1D() [3/3]

LWH::Histogram1D::Histogram1D ( const Histogram1D h)
inline

Copy constructor.

Definition at line 60 of file Histogram1D.h.

References ax, fax, and vax.

◆ ~Histogram1D()

virtual LWH::Histogram1D::~Histogram1D ( )
inlinevirtual

Destructor.

Definition at line 70 of file Histogram1D.h.

References ax.

Member Function Documentation

◆ add() [1/2]

bool LWH::Histogram1D::add ( const Histogram1D h)
inline

Add to this Histogram1D the contents of another IHistogram1D.

Parameters
hThe Histogram1D to be added to this IHistogram1D.
Returns
false If the IHistogram1Ds binnings are incompatible.

Definition at line 355 of file Histogram1D.h.

References ax, sum, sumw, sumw2, sumx2w, and sumxw.

Referenced by add(), and LWH::HistogramFactory::add().

◆ add() [2/2]

bool LWH::Histogram1D::add ( const IHistogram1D &  hist)
inline

Add to this IHistogram1D the contents of another IHistogram1D.

Parameters
histThe IHistogram1D to be added to this IHistogram1D.
Returns
false If the IHistogram1Ds binnings are incompatible.

Definition at line 374 of file Histogram1D.h.

References add().

◆ allEntries()

int LWH::Histogram1D::allEntries ( ) const
inline

Sum of the entries in all the IHistogram's bins, i.e in-range bins, UNDERFLOW and OVERFLOW.

This is equivalent to the number of times the method fill was invoked.

Returns
The sum of all the entries.

Definition at line 153 of file Histogram1D.h.

References entries(), and extraEntries().

◆ annotation() [1/2]

IAnnotation & LWH::Histogram1D::annotation ( )
inline

Not implemented in LWH.

will throw an exception.

Definition at line 103 of file Histogram1D.h.

◆ annotation() [2/2]

const IAnnotation & LWH::Histogram1D::annotation ( ) const
inline

Not implemented in LWH.

will throw an exception.

Definition at line 110 of file Histogram1D.h.

◆ axis()

const IAxis & LWH::Histogram1D::axis ( ) const
inline

Get the x axis of the IHistogram1D.

Returns
The x coordinate IAxis.

Definition at line 335 of file Histogram1D.h.

References ax.

◆ binEntries()

int LWH::Histogram1D::binEntries ( int  index) const
inline

Number of entries in the corresponding bin (ie the number of times fill was called for this bin).

Parameters
indexThe bin number (0...N-1) or OVERFLOW or UNDERFLOW.
Returns
The number of entries in the corresponding bin.

Definition at line 276 of file Histogram1D.h.

References sum.

◆ binError()

double LWH::Histogram1D::binError ( int  index) const
inline

The error of a given bin.

Parameters
indexThe bin number (0...N-1) or OVERFLOW or UNDERFLOW.
Returns
The error on the corresponding bin.

Definition at line 296 of file Histogram1D.h.

References sumw2.

◆ binHeight()

double LWH::Histogram1D::binHeight ( int  index) const
inline

Total height of the corresponding bin (ie the sum of the weights in this bin).

Parameters
indexThe bin number (0...N-1) or OVERFLOW or UNDERFLOW.
Returns
The height of the corresponding bin.

Definition at line 286 of file Histogram1D.h.

References sumw.

◆ binMean()

double LWH::Histogram1D::binMean ( int  index) const
inline

The weighted mean of a bin.

Parameters
indexThe bin number (0...N-1) or OVERFLOW or UNDERFLOW.
Returns
The mean of the corresponding bin.

Definition at line 253 of file Histogram1D.h.

References LWH::Axis::binMidPoint(), LWH::VariAxis::binMidPoint(), fax, sumw, sumxw, and vax.

Referenced by writeXML().

◆ binRms()

double LWH::Histogram1D::binRms ( int  index) const
inline

The weighted RMS of a bin.

Parameters
indexThe bin number (0...N-1) or OVERFLOW or UNDERFLOW.
Returns
The RMS of the corresponding bin.

Definition at line 264 of file Histogram1D.h.

References ax, sum, sumw, sumx2w, and sumxw.

Referenced by writeXML().

◆ cast()

void * LWH::Histogram1D::cast ( const std::string &  ) const
inline

Not implemented in LWH.

Returns
null pointer always.

Definition at line 427 of file Histogram1D.h.

◆ coordToIndex()

int LWH::Histogram1D::coordToIndex ( double  coord) const
inline

Get the bin number corresponding to a given coordinate along the x axis.

This is a convenience method, equivalent to axis().coordToIndex(coord).

Parameters
coordThe coordinalte along the x axis.
Returns
The corresponding bin number.

Definition at line 346 of file Histogram1D.h.

References ax.

◆ dimension()

int LWH::Histogram1D::dimension ( ) const
inline

Get the Histogram's dimension.

Returns
The Histogram's dimension.

Definition at line 118 of file Histogram1D.h.

◆ entries()

int LWH::Histogram1D::entries ( ) const
inline

Get the number of in-range entries in the Histogram.

Returns
The number of in-range entries.

Definition at line 140 of file Histogram1D.h.

References ax, and sum.

Referenced by allEntries(), and writeXML().

◆ equivalentBinEntries()

double LWH::Histogram1D::equivalentBinEntries ( ) const
inline

Number of equivalent entries, i.e.

SUM[ weight ] ^ 2 / SUM[ weight^2 ]

Returns
The number of equivalent entries.

Definition at line 170 of file Histogram1D.h.

References ax, sumw, and sumw2.

◆ extraEntries()

int LWH::Histogram1D::extraEntries ( ) const
inline

Number of entries in the UNDERFLOW and OVERFLOW bins.

Returns
The number of entries outside the range of the IHistogram.

Definition at line 161 of file Histogram1D.h.

References sum.

Referenced by allEntries().

◆ fill()

bool LWH::Histogram1D::fill ( double  x,
double  weight = 1. 
)
inline

Fill the IHistogram1D with a value and the corresponding weight.

Parameters
xThe value to be filled in.
weightThe corresponding weight (by default 1).
Returns
false If the weight is <0 or >1 (?).

Definition at line 238 of file Histogram1D.h.

References ax, sum, sumw, sumw2, sumx2w, and sumxw.

◆ integral()

double LWH::Histogram1D::integral ( ) const
inline

Return the integral over the histogram bins assuming it has been normalize()d.

Definition at line 416 of file Histogram1D.h.

References ax, and sumw.

◆ maxBinHeight()

double LWH::Histogram1D::maxBinHeight ( ) const
inline

Maximum height of the in-range bins, i.e.

not considering the UNDERFLOW and OVERFLOW bins.

Returns
The maximum height among the in-range bins.

Definition at line 225 of file Histogram1D.h.

References ax, and sumw.

◆ mean()

double LWH::Histogram1D::mean ( ) const
inline

The mean of the whole IHistogram1D.

Returns
The mean of the IHistogram1D.

Definition at line 304 of file Histogram1D.h.

References ax, sumw, and sumxw.

Referenced by writeXML().

◆ minBinHeight()

double LWH::Histogram1D::minBinHeight ( ) const
inline

Minimum height of the in-range bins, i.e.

not considering the UNDERFLOW and OVERFLOW bins.

Returns
The minimum height among the in-range bins.

Definition at line 214 of file Histogram1D.h.

References ax, and sumw.

◆ name()

std::string LWH::Histogram1D::name ( ) const
inline

Get the Histogram's title.

Returns
The Histogram's title.

Definition at line 86 of file Histogram1D.h.

References theTitle.

Referenced by writeFLAT(), and writeXML().

◆ normalize()

void LWH::Histogram1D::normalize ( double  intg)
inline

Scale the given histogram so that the integral over all bins (including overflow) gives intg.

This function also corrects for the bin-widths, which means that it should only be run once for each histogram. Further rescaling must be done with the scale(double) function.

Definition at line 399 of file Histogram1D.h.

References ax, sumAllBinHeights(), sumw, sumw2, sumx2w, and sumxw.

◆ reset()

bool LWH::Histogram1D::reset ( )
inline

Reset the Histogram; as if just created.

Returns
false If something goes wrong.

Definition at line 126 of file Histogram1D.h.

References ax, sum, sumw, sumw2, sumx2w, and sumxw.

◆ rms()

double LWH::Histogram1D::rms ( ) const
inline

The RMS of the whole IHistogram1D.

Returns
The RMS if the IHistogram1D.

Definition at line 318 of file Histogram1D.h.

References ax, sumw, sumx2w, and sumxw.

Referenced by writeXML().

◆ scale()

bool LWH::Histogram1D::scale ( double  s)
inline

Scale the contents of this histogram with the given factor.

Parameters
sthe scaling factor to use.

Definition at line 382 of file Histogram1D.h.

References ax, sumw, sumw2, sumx2w, and sumxw.

◆ setTitle()

bool LWH::Histogram1D::setTitle ( const std::string &  title)
inline

Set the histogram title.

Parameters
titleThe title.
Returns
false If title cannot be changed.

Definition at line 95 of file Histogram1D.h.

References theTitle, and title().

Referenced by LWH::HistogramFactory::add(), LWH::HistogramFactory::createCopy(), LWH::HistogramFactory::createHistogram1D(), LWH::HistogramFactory::divide(), LWH::HistogramFactory::multiply(), and LWH::HistogramFactory::subtract().

◆ sumAllBinHeights()

double LWH::Histogram1D::sumAllBinHeights ( ) const
inline

Sum of the heights of all the IHistogram's bins, i.e in-range bins, UNDERFLOW and OVERFLOW.

Returns
The sum of all the bins heights.

Definition at line 197 of file Histogram1D.h.

References sumBinHeights(), and sumExtraBinHeights().

Referenced by normalize().

◆ sumBinHeights()

double LWH::Histogram1D::sumBinHeights ( ) const
inline

Sum of in-range bin heights in the IHistogram, UNDERFLOW and OVERFLOW bins are excluded.

Returns
The sum of the in-range bins heights.

Definition at line 186 of file Histogram1D.h.

References ax, and sumw.

Referenced by sumAllBinHeights().

◆ sumExtraBinHeights()

double LWH::Histogram1D::sumExtraBinHeights ( ) const
inline

Sum of heights in the UNDERFLOW and OVERFLOW bins.

Returns
The sum of the heights of the out-of-range bins.

Definition at line 205 of file Histogram1D.h.

References sumw.

Referenced by sumAllBinHeights().

◆ title()

std::string LWH::Histogram1D::title ( ) const
inline

Get the Histogram's title.

Returns
The Histogram's title.

Definition at line 78 of file Histogram1D.h.

References theTitle.

Referenced by setTitle(), writeFLAT(), and writeXML().

◆ writeFLAT()

bool LWH::Histogram1D::writeFLAT ( std::ostream &  os,
std::string  path,
std::string  name 
)
inlinevirtual

Write out the histogram in a flat text file suitable for eg.

gnuplot to read. The coloums are layed out as 'x w w2 n'.

Implements LWH::ManagedObject.

Definition at line 476 of file Histogram1D.h.

References ax, name(), sum, sumw, sumw2, and title().

◆ writeXML()

bool LWH::Histogram1D::writeXML ( std::ostream &  os,
std::string  path,
std::string  name 
)
inlinevirtual

Write out the histogram in the AIDA xml format.

Implements LWH::ManagedObject.

Definition at line 434 of file Histogram1D.h.

References ax, binMean(), binRms(), entries(), mean(), name(), rms(), sum, sumw, sumw2, title(), and vax.

Friends And Related Function Documentation

◆ HistogramFactory

friend class HistogramFactory
friend

HistFactory is a friend.

Definition at line 34 of file Histogram1D.h.

Member Data Documentation

◆ ax

◆ fax

Axis* LWH::Histogram1D::fax
private

Pointer (possibly null) to a axis with fixed bin width.

Definition at line 496 of file Histogram1D.h.

Referenced by binMean(), LWH::HistogramFactory::checkBins(), and Histogram1D().

◆ sum

std::vector<int> LWH::Histogram1D::sum
private

◆ sumw

◆ sumw2

◆ sumx2w

std::vector<double> LWH::Histogram1D::sumx2w
private

The weighted x-square-values.

Definition at line 514 of file Histogram1D.h.

Referenced by add(), binRms(), fill(), normalize(), reset(), rms(), scale(), and LWH::HistogramFactory::sliceX().

◆ sumxw

std::vector<double> LWH::Histogram1D::sumxw
private

The weighted x-values.

Definition at line 511 of file Histogram1D.h.

Referenced by add(), binMean(), binRms(), fill(), mean(), normalize(), reset(), rms(), scale(), and LWH::HistogramFactory::sliceX().

◆ theTitle

std::string LWH::Histogram1D::theTitle
private

The title.

Definition at line 490 of file Histogram1D.h.

Referenced by name(), setTitle(), and title().

◆ vax

VariAxis* LWH::Histogram1D::vax
private

Pointer (possibly null) to a axis with fixed bin width.

Definition at line 499 of file Histogram1D.h.

Referenced by binMean(), Histogram1D(), and writeXML().


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