Top Up Prev Next Bottom Contents Index Search

11.6 Histogram classes

The Histogram class accepts a stream of data and accumulates a histogram. The XHistogram class uses a Histogram to collect the data and an XGraph to display it.

11.6.1 Class Histogram

The Histogram class accumulates data in a histogram. Its constructor is as follows:

Histogram(double width = 1.0, int maxBins = HISTO_MAX_BINS);
The default maximum number of bins is 1000. The bin centers will be at integer multiples of the specified bin width. The total width of the histogram depends on the data; however, there will always be a bin that includes the first point.

void add(double x);
Add the point x to the histogram.

int numCounts() const;
double mean() const;
double variance() const;
Return the number of counts, the mean, and the variance of the data in the histogram.

int getData(int binno, int& count, double& binCenter);
Get counts and bin centers by bin number, where 0 indicates the smallest bin. Return TRUE if this is a valid bin. Thus the entire histogram data can be retrieved by stepping from 0 to the first failure.

11.6.2 Class XHistogram

An XHistogram object has a private XGraph member and a private Histogram member. The functions

int numCounts() const;
double mean() const;
double variance();
simply pass through to the Histogram object, and

void addPoint(float y);
adds a point to the histogram and does other bookkeeping. There are two remaining methods:

void initialize(Block* parent, double binWidth, 
const char* options, const char* title,
const char* saveFile, int maxBins = HISTO_MAX_BINS
This method initializes the graph and histogram object. parent is the parent Block, used for error messages. binWidth and maxBins initialize the Histogram object. options is a string that is included in the command line to the xgraph program; other options, including -bar -nl -brw value, are passed as well. title is the graph title, and saveFile, if non-null, gives a file in which the histogram data is saved (this data is the histogram counts, not the data that was input with addPoint).

void terminate();
This method completes the histogram, flushes out the temporary files, and executes xgraph.

Top Up Prev Next Bottom Contents Index Search
Copyright © 1990-1997, University of California. All rights reserved.