Histograms
The Hist
class gives a simple implementation of
one-dimensional histograms, useful for quick-and-dirty testing,
without the need to link to more sophisticated packages.
A Histogram is declared by a
class
Hist name( title, numberOfBins, xMin, xMax)
where
argument
title :
is a string with the title of the histogram at output,
argument
numberOfBins :
is the number of bin the x range will be subdivided into,
argument
xMin :
is the lower edge of the histogram,
argument
xMax :
is the upper edge of the histogram.
For instance
Hist ZpT( "Z0 pT spectrum", 100, 0., 100.);
Alternatively you can first declare it and later define it:
Hist ZpT;
ZpT.book( "Z0 pT spectrum", 100, 0., 100.);
Once declared, its contents can be added by repeated calls to fill
method
fill( xValue, weight)
where
argument
xValue :
is the x position where the filling should occur, and
argument
weight (default = 1.
) :
is the amount of weight to be added at this x value.
For instance
ZpT.fill( 22.7, 1.);
Since the weight defaults to 1 the last argument could have been
omitted in this case.
A histogram can be printed by making use of the overloaded <<
operator, e.g.:
cout << ZpT;
A set of overloaded operators have been defined, so that histograms can
be added, divided by each other (bin by bin) and so on. Also overloaded
operations with double real numbers are available, so that e.g.
histograms easily can be rescaled. Thus one may write e.g.
allpT = ZpT + 2. * HpT
assuming that allpT
, ZpT
and HpT
have been booked with the same number of bins and x range. That
responsibility rests on the user; some checks are made for compatibility,
but not enough to catch all possible mistakes.
Some further possibilities are included, like writing out histogram
contents as a table, for plotting e.g. with Gnuplot.