KAHIBARO
Discord Login Register

6.5. Profiles

TProfile

A profile histogram, implemented in ROOT as the class TProfile, is a compact way to summarize the dependence of a variable $y$ on another variable $x$. Instead of storing the full two dimensional distribution of $(x, y)$ pairs, a profile stores the mean value of $y$ in bins of $x$, together with the corresponding statistical uncertainty.

Conceptually, you can think of a profile as a plot of $\langle y \rangle$ versus $x$.

For each $x$ bin, the profile keeps track of several quantities while you call Fill(x, y):

  1. The number of entries in the bin, $N$.
  2. The sum of $y$ values, $S_y = \sum_i y_i$.
  3. The sum of squared $y$ values, $S_{y^2} = \sum_i y_i^2$.

From these internal sums, TProfile computes the bin content as the mean value of $y$ in that $x$ bin, and the bin error as the uncertainty on that mean.

The mean in a given $x$ bin is
$$
\bar{y} = \frac{1}{N} \sum_{i=1}^{N} y_i = \frac{S_y}{N}.
$$

The variance of $y$ in that bin is
$$
\sigma_y^2 = \frac{1}{N} \sum_{i=1}^{N} y_i^2 - \bar{y}^2 = \frac{S_{y^2}}{N} - \left(\frac{S_y}{N}\right)^2.
$$

The standard error on the mean, which is the default bin error displayed by TProfile, is
$$
\sigma_{\bar{y}} = \frac{\sigma_y}{\sqrt{N}}.
$$

For each $x$ bin of a TProfile:
Mean: $\displaystyle \bar{y} = \frac{S_y}{N}$
Variance: $\displaystyle \sigma_y^2 = \frac{S_{y^2}}{N} - \left(\frac{S_y}{N}\right)^2$
Error on the mean: $\displaystyle \sigma_{\bar{y}} = \frac{\sigma_y}{\sqrt{N}}$

In ROOT, you create a profile similarly to how you create a 1D or 2D histogram, but using TProfile:

cpp
TProfile *prof = new TProfile("prof", "Y vs X profile;X;Mean Y", 
                              50, 0.0, 10.0);

This creates a profile with 50 bins in $x$, covering the range from 0 to 10. The x axis is labeled X and the y axis shows Mean Y. To fill it you use pairs of $(x, y)$:

cpp
prof->Fill(x_value, y_value);

Just like histograms, profiles can be drawn and styled:

cpp
prof->Draw();          // default profile plot
prof->SetMarkerStyle(20);
prof->SetMarkerColor(kBlue);

The plotted point in each bin is at the bin center in $x$ and at the mean $y$ value on the vertical axis, with an error bar given by $\sigma_{\bar{y}}$.

TProfile also supports weighted fills. When you call

cpp
prof->Fill(x_value, y_value, weight);

the sums and counts are updated with this weight. The internal formulas then use weighted sums, so the bin content becomes a weighted mean of $y$.

By default, profile bins display the mean of $y$ and its error, but ROOT provides alternative error calculations through profile options. Advanced configurations, like using the spread of the data instead of the error on the mean, are available, but the standard settings are usually appropriate for typical analyses.

Profiles are especially useful when you have a strong functional dependence of $y$ on $x$ and you want to see the trend and its uncertainty. Typical applications include detector calibration curves, time dependent drifts, or resolution as a function of momentum or energy.

Difference between profiles and 2D histograms

Both TProfile and 2D histograms such as TH2F and TH2D deal with pairs of variables $(x, y)$. However, they represent and summarize the data differently and are suited to different analysis tasks.

A 2D histogram bins both $x$ and $y$. Each cell in the 2D grid corresponds to a bin in $x$ and a bin in $y$, and its content stores the number of entries (or sum of weights) that fall in that 2D bin. This provides a detailed picture of the full joint distribution of $x$ and $y$, including correlations, shapes, and structures across the plane.

A profile, in contrast, only bins in $x$ and then compresses all $y$ values in a given $x$ bin into a single number, usually the mean of $y$, with an error bar. The profile does not keep the shape of the $y$ distribution in each $x$ bin, only its first moments. This distinction is key for deciding when to use each tool.

The conceptual differences can be summarized as follows:

Aspect2D histogram (TH2)Profile (TProfile)
BinningIn $x$ and $y$Only in $x$
Stored quantity per binCounts or sum of weightsMean of $y$ in that $x$ bin
Vertical axisY variable or entries in that $(x, y)$ bin$\langle y \rangle$ for a given $x$ bin
Visual representationColor map, contours, surfaces, etc.Points with error bars versus $x$
Information about spread in $y$Implicit in vertical binning and shapesCondensed into an error bar, detailed shape is lost
Best use caseVisualizing full 2D distributionsStudying average trends and dependences

If your goal is to answer questions like "What is the average $y$ as a function of $x$, and how precise is that average?", a profile is usually more efficient and clearer than a 2D histogram. The profile reduces fluctuations in individual events and makes trends easier to read, especially when the data is dense or the scatter is wide.

If instead you want to see the full distribution of $y$ at a given $x$, or you suspect complex features such as multiple peaks, sharp edges, or non Gaussian tails, a 2D histogram is more appropriate. In that case the binning in $y$ is essential and you do not want to compress the vertical structure into a single mean value.

From a practical plotting perspective, a 2D histogram is typically drawn with commands such as

cpp
h2->Draw("COLZ");

which shows a color map of the counts. A profile is drawn as a 1D object:

cpp
prof->Draw("E1");

and looks similar to a TGraphErrors, with markers at $\langle y \rangle$ and error bars.

Another difference is statistical interpretation. In a 2D histogram, the bin content at $(x_j, y_k)$ is directly the number of events in that region of phase space. This is useful for density estimation and for computing integrals over regions in the plane. In a profile, the bin content is an estimator of a conditional mean, $\langle y \rangle$ for events with $x$ in bin $j$. It does not give you the relative rate of events, only the average value of $y$ where events do occur.

2D histogram bins represent how many events fall into each $(x, y)$ region.
Profile bins represent the average value of $y$ for a given range of $x$ and the uncertainty on that average.
Use 2D histograms to study distributions and shapes in the plane, and profiles to study mean trends and functional dependences.

In many analyses, both objects are used together. You might first inspect a 2D histogram to understand the general structure of your data, then create a TProfile from the same events to obtain a clean curve of the mean response or calibration relationship. ROOT even allows you to project a 2D histogram into a profile using ProfileX or ProfileY, which combine the two approaches: you keep the underlying 2D distribution for detailed checks, and derive the profile for an immediate view of the trend and its uncertainty.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!