# 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 a TGraphErrors object from a file. You won’t use this method directly.

• TGraphErrors(Int_t n) – You use this when you just want to supply TGraphErrors with the number of points that will be in the graph, then use the SetPoint() and SetPointError() 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 a TGraphErrors object. You can ignore this.

• TGraphErrors(const TH1* h) – You use this to create a TGraphErrors 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.

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.

From scanning through the web sites, it appears to me that HDF5 stores its datasets as if they were n-tuples. ROOT can store its classes as structures; e.g., histograms are stored as histograms, as in this exercise.

Of course, I could be wrong! You and I are both learning new things through this tutorial.

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.