Working with folders inside ROOT files
Note
As you worked with the TBrowser, you may have realized that ROOT organizes its internal resources in the form of “folders,” which are conceptually similar to the hierarchy of directories on a disk. You can also have folders within a single ROOT file, to organize objects within a file.1
Copy the file folders.root
from my root-class
directory into your own,
and use the ROOT TBrowser to examine its contents.
Note
You’ll see three folders within the file: example1
, example2
, and
example3
. Each of these folders will be the basis of the next three
exercises.
All three of the subsequent exercises will require you to make a plot of data points with
error bars. You’ll want to use the
TGraphErrors
class for this.2
Go to the description of the TGraphErrors
class. To create a
TGraphErrors
object, you need to supply some arguments.
Note
These are all different ways to construct a plot with error bars:
TGraphErrors()
– This is used internally by ROOT when reading aTGraphErrors
object from a file. You won’t use this method directly.TGraphErrors(Int_t n)
– You use this when you just want to supplyTGraphErrors
with the number of points that will be in the graph, then use theSetPoint()
andSetPointError()
methods to assign values and errors to the points.TGraphErrors(const TGraphErrors& gr)
– This is called a “copy constructor” in C++, and is used when you copy aTGraphErrors
object. You can ignore this.TGraphErrors(const TH1* h)
– You use this to create aTGraphErrors
plot based on values in a histogram.
Now that I’ve given you a guide to four ways to construct a TGraphErrors object, you can probably figure out what the others are: to create a graph from the contents of a file, and to create plots from either float or double-precision… somethings.
Those somethings are containers. We’ll learn about those in the next section.

Figure 72: https://xkcd.com/688/ by Randall Munroe
- 1
You may already be familiar with HDF5, which is conceptually similar to the approach that ROOT takes for its files: containers for a mixed set of different types of data within a hierarchy of directories. I haven’t worked with HDF5 (yet) so it’s hard for me to compare the two.
- 2
For Python programmers: Because I have a generous soul, I’ll permit you to use matplotlib instead of
TGraphErrors
for your x-y plots. The fact that I have no way to stop you has nothing to do with it.