KAHIBARO
Discord Login Register

25.3. C. ROOT Graph Classes

Overview

ROOT provides several graph classes to represent and visualize discrete points with associated coordinates and, optionally, uncertainties. Unlike histograms, graphs do not bin data. They are ideal when you have a set of measured points, such as $(x_i, y_i)$ pairs, with or without errors.

This appendix summarizes the most commonly used ROOT graph classes, their typical use cases, and key methods you will often need. It is intended as a quick reference, not a full tutorial.

TGraph

A TGraph stores a set of $(x, y)$ points. It does not store errors. It is the most basic ROOT graph class and is widely used for simple X Y plots.

Typical use cases include measured data points without uncertainties, function samples saved as discrete points, or any situation where you want to connect or mark points directly.

A TGraph can be created by passing arrays or vectors of x and y to the constructor, or by creating an empty graph and adding points manually with SetPoint.

Useful features include control over markers, lines, and axes, through methods such as SetMarkerStyle, SetMarkerColor, SetLineColor, and SetLineWidth. The Draw method supports many drawing options, for example "AP" for axes and points or "AL" for axes and a connected line.

TGraphErrors

TGraphErrors extends TGraph by adding symmetric errors in both x and y. For each point, it stores values $(x_i, y_i, \sigma_{x_i}, \sigma_{y_i})$ where $\sigma_{x_i}$ and $\sigma_{y_i}$ are the uncertainties on the coordinates.

This class is essential for experimental data where measurements include error bars. It is also frequently used in fits where you want the fit algorithm to take uncertainties into account.

You can construct a TGraphErrors from arrays or from an existing TGraph by setting errors point by point with SetPointError. The Draw method with option "AP" or "APZ" shows points with symmetric error bars, and you can style markers and lines similarly to TGraph.

Important: For TGraphErrors, the errors are interpreted as standard deviations. When fitting, ROOT uses these errors to weight points, so always set them consistently with your statistical model.

TGraphAsymmErrors

TGraphAsymmErrors stores asymmetric errors in both x and y. For each point $(x_i, y_i)$, it stores four error components: lower and upper errors on x, and lower and upper errors on y. In other words, it represents
$$
(x_i, y_i, x_i - x_i^{-}, x_i^{+} - x_i, y_i - y_i^{-}, y_i^{+} - y_i)
$$
where $x_i^{-}$ and $x_i^{+}$ are lower and upper bounds for x, and similarly for `y$.

This is useful when uncertainties are not symmetric, for example in low count Poisson statistics, efficiency measurements near boundaries, or systematic uncertainties that produce different upward and downward shifts.

Creation is similar to TGraphErrors but with separate arrays for lower and upper errors or with SetPointError(ixlow, ixhigh, iylow, iyhigh) for each point. The "AP" draw option shows the full asymmetric error bars.

Important: In TGraphAsymmErrors, you must provide nonnegative error lengths. ROOT expects lower and upper errors as positive values that represent the distance from the central value, not as absolute coordinates.

TMultiGraph

TMultiGraph is a container that allows you to display several graphs on the same axes. It does not represent data by itself, but manages a collection of TGraph, TGraphErrors, or TGraphAsymmErrors objects.

You typically create individual graphs, style each one, then add them to a TMultiGraph using Add. When you call Draw on the multigraph, all contained graphs are drawn together with shared axes. This is convenient for comparing datasets, overlaying measurements and fits, or combining several observables on the same plot.

Axis titles and ranges for a multigraph can be set through the TMultiGraph itself, usually after it has been drawn once and its internal histogram has been created.

Other Graph Classes

ROOT provides several additional graph classes for more specialized tasks. The most common ones are listed here for quick reference.

ClassDescription
TGraph2DStores points in three dimensions (x, y, z) and draws 3D scatter or surfaces.
TGraphPolarGraph in polar coordinates (r, theta), useful for angular distributions.
TGraphBentErrorsVariant of TGraphErrors with bent error bars for clarity when overlapping.
TGraphTimeSpecialization for time axes on the x coordinate.
TGraphDelaunayPerforms Delaunay triangulation of 2D point sets for surface interpolation.

These classes follow similar patterns to TGraph but are tailored to specific coordinate systems or representations. For most introductory work, TGraph, TGraphErrors, TGraphAsymmErrors, and TMultiGraph are sufficient.

Views: 9

Comments

Please login to add a comment.

Don't have an account? Register now!