Tools for Quick and Attractive Plotting with ROOT

_images/rootplotmpl_example12.png

ROOT is a powerful data analysis tool within the particle physics community, and the primary lens through which we see our data. The framework includes quite a bit of graphical capability, but this has understandably not been the first priority in designing its capabilities or its interface.

The rootplot package exploits the pyROOT interface to provide scripts and libraries to make working with the graphical side of ROOT easier.

For immediate figures with a minimum of effort from any ROOT file filled with histograms, take a look at the rootplot command-line tool.

To get a quick glimpse at the contents of a ROOT file from the command-line, try rootinfo.

To quickly produce histograms from a ROOT tree or ntuple, take a look at the tree2hists command-line tool.

To plot ROOT figures with the powerful matplotlib python plotting package, take a look at the root2matplotlib library and rootplotmpl.

Future

Many of the under-the-hood features of the rootplot libraries have also been implemented independently and more robustly in rootpy. Most of the rootplot development effort is going into rootpy now, with plans to migrate over all features and deprecate this package. If you are interested in contributing to these tools, take a look at rootpy.

Contact

rootplot is created, developed, and maintained by Jeff Klukas and Michael Anderson. You are heartily encouraged to make suggestions and submit bug reports on our bitbucket page or to join the discussion with the rootplot Users Google Group.

Installation

The easiest installation of rootplot is through easyinstall:

$ easy_install rootplot

The installer will place the whole rootplot package in an appropriate place in your python tree. It will also install the rootplot, rootplotmpl, rootinfo, and tree2hists scripts in an appropriate bin directory so that they are available on the command line.

The current user base is mostly members of the CMS experiment at CERN, who should know that as of CMSSW_3_8_7, rootplot is included in our software framework. When you run cmsenv, all the command-line tools will be available, and in modern versions (at least as of CMSSW_4_2_8) matplotlib is included, so rootplotmpl is also enabled. If you’d like to use the rootplot API within CMSSW, be aware that it is contained within a subpackage, so import statments should look like:

import PhysicsTools.PythonAnalysis.rootplot

This implementation within a subpackage, however, is flawed and some internal imports won’t work. You will be safer if you explicitly include the subpackage in your python path (after which you will be able to import rootplot as normal):

## example for bash
export PYTHONPATH="$CMSSW_RELEASE_BASE/python/PhysicsTools/PythonAnalysis/:$PYTHONPATH

For other users at CERN, you can access an existing installation on lxplus:

$ source /afs/cern.ch/user/k/klukas/public/Sharing/rootplot_setup.sh

This will point to a local installation of rootplot and should also set up a compatible cocktail of python, matplotlib, and ROOT. After you run the script, you can check that it works by trying out some of the root2matplotlib examples.

Interfacing with matplotlib

The root2matplotlib library requires that you have both pyROOT and matplotlib available within a single python installation. This may be easy on Linux platforms (see the PyROOT site), but it is more difficult on a Mac. For additional help, see instructions for a Mac OSX 10.6 installation.

Installing from the Repository

rootplot is version controlled with Mercurial. To download the latest development version:

$ hg clone http://bitbucket.org/klukas/rootplot
$ cd rootplot
$ python setup.py develop

And to update:

$ hg pull http://bitbucket.org/klukas/rootplot
$ hg update