Working with folders inside ROOT files
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.
You’ll see three folders within the file:
example3. Each of these folders will be the basis of the next three
Go to the description of the
TGraphErrors class. To create a
TGraphErrors object, you need to supply some arguments.
These are all different ways to construct a plot with error bars:
TGraphErrors()– This is used internally by ROOT when reading a
TGraphErrorsobject from a file. You won’t use this method directly.
TGraphErrors(Int_t n)– You use this when you just want to supply
TGraphErrorswith the number of points that will be in the graph, then use the
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
TGraphErrorsobject. You can ignore this.
TGraphErrors(const TH1* h)– You use this to create a
TGraphErrorsplot 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.
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.
For Python programmers: Because I have a generous soul, I’ll permit you to use matplotlib instead of
TGraphErrorsfor your x-y plots. The fact that I have no way to stop you has nothing to do with it.