17.1 Basic Statistics
Table of Contents
Mean
In ROOT based analyses, the mean is the most common way to summarize the central value of a distribution. For a set of $N$ values $x_1, x_2, \dots, x_N$, the arithmetic mean $\bar{x}$ is defined as
$$
\bar{x} = \frac{1}{N} \sum_{i=1}^{N} x_i.
$$
When you work with histograms, ROOT stores this value internally. For a one dimensional histogram TH1, you can retrieve it with the method GetMean(). This mean is computed using the bin centers and bin contents, taking into account the number of entries in each bin, including any weights if you filled the histogram with weights.
In many practical analyses you will want both the mean value and its uncertainty. ROOT also provides GetMeanError() for histograms and graphs with errors, which returns the standard error on the mean that reflects how precisely the mean is known for your sample size.
The sample mean of $N$ values is
$$
\bar{x} = \frac{1}{N} \sum_{i=1}^{N} x_i.
$$
In ROOT, TH1::GetMean() returns the histogram mean, and TH1::GetMeanError() returns its statistical uncertainty.
When you analyze values stored in a TTree, you can compute the mean either by looping over entries manually and accumulating a sum, or by using higher level tools such as TTree::Draw() or RDataFrame actions like Mean(). These tools hide the loop but apply exactly the same underlying definition.
For weighted data, which appear very often in physics, the mean is generalized to a weighted mean. If each value $x_i$ has weight $w_i$, the weighted mean is
$$
\bar{x}_w = \frac{\sum_{i=1}^{N} w_i x_i}{\sum_{i=1}^{N} w_i}.
$$
ROOT uses such weighted formulas for histograms filled with weights, so the reported mean belongs to the weighted distribution, not simply to the unweighted sample of Fill() calls.
Variance
The variance quantifies how spread out your values are around the mean. For $N$ values $x_1, x_2, \dots, x_N$ with mean $\bar{x}$, there are two closely related formulas.
The population variance, used when your list represents the entire set of possible values, is
$$
\sigma^2 = \frac{1}{N} \sum_{i=1}^{N} (x_i - \bar{x})^2.
$$
The sample variance, more common in experimental data analysis where your $N$ values are a sample from a larger population, is
$$
s^2 = \frac{1}{N - 1} \sum_{i=1}^{N} (x_i - \bar{x})^2.
$$
The factor $1/(N - 1)$ provides an unbiased estimate of the population variance when the mean is estimated from the same sample.
In ROOT, histograms store information that allows you to recover the variance without recomputing sums manually. For TH1 objects, GetStdDev() and GetStdDevError() are provided, and the variance corresponds to the square of the standard deviation. Internally ROOT uses bin centers and contents, just as for the mean. Weighted histograms use a weighted form of the variance where each term $(x_i - \bar{x})^2$ is multiplied by the corresponding weight.
The sample variance of $N$ values with mean $\bar{x}$ is
$$
s^2 = \frac{1}{N - 1} \sum_{i=1}^{N} (x_i - \bar{x})^2.
$$
The population variance uses $1/N$ instead of $1/(N - 1)$.
When you build your own event loops or use tools such as RDataFrame, you can compute variance either directly with this definition or via sufficient statistics. The variance can be expressed in terms of the mean of $x$ and the mean of $x^2$,
$$
s^2 = \frac{1}{N - 1} \left(\sum_{i=1}^{N} x_i^2 - N \bar{x}^2 \right),
$$
which is often how ROOT accumulates the needed sums incrementally.
Standard deviation
The standard deviation is the square root of the variance. It has the same units as the original variable and gives a more intuitive scale for the spread of values. For a population with variance $\sigma^2$,
$$
\sigma = \sqrt{\sigma^2}.
$$
For a sample with sample variance $s^2$,
$$
s = \sqrt{s^2}.
$$
In histogram based analyses, TH1::GetStdDev() returns the standard deviation of the distribution represented by the histogram, again using bin centers, contents, and any weights. The associated uncertainty is accessible through GetStdDevError(). The same ideas extend to graphs and numerical datasets stored in TTrees or processed through RDataFrame, where you can compute or request both mean and standard deviation to summarize your data.
The standard deviation is the square root of the variance:
$$
\sigma = \sqrt{\sigma^2}, \qquad s = \sqrt{s^2}.
$$
In ROOT, GetStdDev() on a histogram returns this quantity, and GetStdDevError() gives its statistical uncertainty.
In practical ROOT workflows the mean and standard deviation appear together very often, for example when you print histogram statistics on a plot or when you compare two different datasets. Remember that a larger standard deviation means a broader distribution, while a smaller one indicates that most values cluster more tightly around the mean.
Views: 9
KAHIBARO