ROOT:Histo

From AliceWiki
Jump to: navigation, search

jedna 1

dsadsad

sadsadas

rewrewrw

sadsadas

werwrwer

jedna 2

sdsadsadsa




 // REBIN !!!!!!!!!
 // ResetStats() !!!!!!!!!!!
 // SetBinContent     abo      Fill(x, w) !!!!!!!!!!!!!!!!!!


In its simplest form, a (1-dimensional) histogram is defined as the collection of the N pairs (1, n1), (2, n2), ..., (N, nN) and it is usually implemented as an array in which the first value of the pair (i, ni) is the index of the element containing the value ni.

Fix or variable bin size

All histogram types support either fix or variable bin sizes.

Convention for numbering bins

For all histogram types: nbins, xlow, xup

bin = 0;        underflow bin
bin = 1;        first bin with low-edge xlow INCLUDED
bin = nbins;    last bin with upper-edge xup EXCLUDED
bin = nbins+1;  overflow bin
Histograms with automatic bins

When an histogram is created with an axis lower limit greater or equal to its upper limit, the TH1::SetBuffer is automatically called with an argument TH1::fBufferSize equal to TH1::fgBufferSize (default value=1000). TH1::fgBufferSize may be reset via the static function TH1::SetDefaultBufferSize. The axis limits will be automatically computed when the buffer will be full or when the function TH1::BufferEmpty is called.

Filling histograms

An histogram is typically filled with statements like h1->Fill(x), or fill with weight h1->Fill(x, w). The Fill functions compute the bin number corresponding to the given x argument and increment this bin by the given weight. The Fill functions return the bin number for 1-D histograms.

If TH1::Sumw2 has been called before filling, the sum of squares of weights is also stored. One can also increment directly a bin number via TH1::AddBinContent or replace the existing content via TH1::SetBinContent. By default, the bin number is computed using the current axis ranges. If the automatic binning option has been set via h->SetBit(TH1::kCanRebin) then, the Fill function will automatically extend the axis range to accomodate the new value specified in the Fill argument. The method used is to double the bin size until the new value fits in the range, merging bins two by two. This automatic binning options is extensively used by the TTree::Draw function when histogramming Tree variables with an unknown range. During filling, some statistics parameters are incremented to compute the mean value and Root Mean Square with the maximum precision.

Re-binning

At any time, a histogram can be re-binned via the TH1::Rebin method. It returns a new histogram with the re-binned contents. If bin errors were stored, they are recomputed during the re-binning.

Associated errors

By default, for each bin, the sum of weights is computed at fill time. One can also call TH1::Sumw2 to force the storage and computation of the sum of the square of weights per bin. If TH1::Sumw2 has been called, the error per bin is computed as the sqrt(sum of squares of weights), otherwise the error is set equal to the sqrt(bin content). To return the error for a given bin number, do h->GetBinError(bin)

Histogram errors

ROOT assumes by default that the histogram represents counting of values from stochastically independent measurements (e.g. the outcomes of repeated die throwing), so that it computes the bin fluctuation accordingly to the Poisson distribution: the best estimate of the standard deviation on the observed value ni of entries in bin i is the square root of ni. Note that this is not always correct, frequent examples are

  • rate histograms the i-th bin contains the number of events passing cut i and all previous selection criteria. In this case the correct probability distribution is the binomial distribution and the correct standard deviation should be computed by the user (it can also be saved into the histogram itself, for future use). When ni is not too small, the binomial distribution is well approximated by the Poisson distribution, so that the ROOT default is acceptable in most cases (but not for all bins!). The TH1::Divide method has the option "B" for binomial division, but the best error estimation in this case is provided by TGraphAsymmErrors::BayesDivide method (which is not as easy to understand ...)
  • histograms computed using other histograms, for example by adding or dividing them bin by bin, ROOT assumes that the input histograms have the correct standard deviations and correctly computes the final ones. The user should make sure that the input histograms have correct errors
  • histograms that do not represent value counting from stochastically independent random processes for each specific case, the user should take care of computing and saving, via TH1::SetBinError, the correct standard deviations.
Operations on histograms

Many types of operations are supported on histograms or between histograms

  • Addition of an histogram to the current histogram.
  • Additions of two histograms with coefficients and storage into the current histogram.
  • Multiplications and Divisions are supported in the same way as additions.
  • The Add, Divide and Multiply functions also exist to add, divide or multiply an histogram by a function.

If an histogram has associated error bars (TH1::Sumw2 has been called), the resulting error bars are also computed assuming independent histograms. In case of divisions, Binomial errors are also supported. One can mark a histogram to be an "average" histogram by setting its bit TH1::kIsAverage via myhist.SetBit(TH1::kIsAverage). When adding (see TH1::Add) average histograms, the histograms are averaged and not summed.

Normalizing histograms

One can scale an histogram such that the bins integral is equal to the normalization parameter via myhist.Scale(Double_t norm), where norm is the desired normalization divided by the integral of the histogram myhist.Scale(norm/(h->Integral()))