next up previous contents
Next: Viewing Histograms Up: First Steps with YODA Previous: A Sample YODA Session

Producing Histograms

Histograms are statistical objects counting the frequencies of a independent variable or tuples in a set of intervals.

Histograms are realized in YODA as one- or two-dimensional objects, either counting the frequency distribution of a em single variable or of a 2-tuple of values, respectively. To see how the histogramming options work, create a second analysis file called dummy2.hoc with a demonstration of most common usage of the histogramming tools. It should contain the following:

/* procedure init. called once when this task is loaded */
proc init()
{
select DUMMY;
h1 = histo ("SingleSpectrum", 1024,  0, 1.);
h2 = histo2d("TwoDimSpectrum",  64, -1, 1, 64, -2, 2);
}

/* procedure analyze. called every time a DUMMY event is coming in */
proc analyze()
{
hfill  (h1, sin(DUMMY[0]));
hfill2d(h2, sin(DUMMY[1]), 2.*cos(DUMMY[2]));
}

This tasks shows an example of creating and filling histograms. In the procedure init(), two histograms are defined: a one dimensional, created with the call histo(...), and a two-dimensional with the call histo2d(...). Both calls return a histogram handle, which is later used to refer to the created histogram. These handles are saved in the user variables h1 and h2. Note that these handles have nothing to do with PAW's histogram identifiers, but are internal YODA parameters. After creation, all channels of the histograms are zero.

The parameters to histo(...) are the following: The first one is a string (in double quotes), giving the name of the histogram. This name will automatically be preceded with the name of the task in which context the histogram is created and a period (''.''). So in this case, the full name of the first histogram is dummy.SingleSpectrum. The next parameter (1024) defines the number of channels (bins) the histogram should have. The next and the last parameter (0, 1) define the lowest and highest x value which is expected to be filled into the histogram. The histograms's x-axis then runs from 0 (low edge of first bin) up to 1 (high edge of last bin). Note, that in this way the x-axis can be of arbitrary floating point values, and need not be integer channel numbers. So this histogram definition divides the interval between 0 and 1 into 1024 equally spaced bins.

The parameters to histo2d(...) are similar: First comes the name of the 2-dimensional histogram, then the number of channels in x (64), low and high limits in x (-1, 1), number of channels in y (64), and low and high limits in y (-2, 2). The corresponding (square) area between (-1, -2) and (1,2) is divided into 64x64 channels (bins).

The procedure analyze() shows the typical usage of the so defined quantities: values are ''filled'' into the histograms via the calls hfill(...) or hfill2d(...), respectively.

The first parameter is the handle of the histogram as it is returned by the appropriate call to histo(...) or histo2d(...).

For the one-dimensional case, the second (and last) parameter is the value which is to be filled in. Here, the sine of the first (random) dummy-array element is investigated. If the actual value is in the interval between -1 and -1 + 1*(2./64)), it will be filled into the first channel of the histogram, causing the counter for bin 0 to be incremented by one. If it is in the interval between -1.+ 1*(2./64) and -1.+ 2*(2./64), the second channel is incremented and so on.

For the two-dimensional case, the second and third parameter is the (x,y) tuple which is to be filled in.

Now let's see how it works!


next up previous contents
Next: Viewing Histograms Up: First Steps with YODA Previous: A Sample YODA Session
Heiko Rohdjess
2001-07-19