ROOT is a monolithic library/application/framework used in high-energy physics. Among other things, it provides a data format that is akin to protobufs, messagepack, etc. Use of this ROOT data format is a necessity when working in the (experimental) physics communities. However, this format is not natively supported by many other tools / frameworks.

gnuplot is a powerful graphing utility that is capable of producing publication quality plots. However, it cannot interop with ROOT data natively. I have previously written a small tool to convert ROOT data (histograms, graphs, etc.) to gnuplot text-based data files. However, it still adds a substantial overhead when an extra step is needed to convert the data before plotting. It also makes it potentially susceptible to data being out-of-date. The goal of this tool is to provide a drop-in “replacement” for gnuplot that can work directly on root data. This is accomplished by converting the data in the background and processing the gnuplot script altogether.

Usage

  1. Write gnuplot plotting scripts like normal
  2. Add a comment line in your script like this
# root2gnuplot input.root:histogram_name output.dat "x y xlow xhigh ylow yhigh"

this line instructs rnuplot how to convert your ROOT data. It uses an internal version of the root2gnuplot tool. See details here. You can control the format of the conversion for custom plotting types in gnuplot. You can also plot ‘directly’ from ROOT TTrees.

  1. Run your script with rnuplot instead of gnuplot and it will just work

Full usage details

Usage:
  rnuplot [OPTION...] [FILE]

  -c, --cache             Use cached data, set to true to use cached data
  -f, --file arg          File
  -d, --debug arg         Enable debugging
  -r, --root2gnuplot arg  Convert ROOT data using root2gnuplot (useful if
                          not specified in gnuplot script comment
  -h, --help              Print usage

By default the data is not cached - meaning that even if the data file exists

Example

set terminal pngcairo font "Helvetica, 18" size 1200,900 
set output 'demo.png'

set xlabel "𝛂" 
set ylabel "Counts"

set bars small  caps from error bars

# root2gnuplot input.root:histo_name h1.dat "x y xlow xhigh ylow yhigh"
plot 'h1.dat' u 1:2:3:4:($5):($6) with xyerr ls 2 pt 15 ps 0 lw 2 t 'ROOT histogram'

OR without modifying your gnuplot script at all you can:

rnuplot -r 'input.root:histo_name h1.dat "x y xlow xhigh ylow yhigh"' script.gnuplot

with a script like this:

set terminal pngcairo font "Helvetica, 18" size 1200,900 
set output 'h1.png'

set xlabel "x" 
set ylabel "y"

set bars small  caps from error bars
set style fill   solid 1.00 border

plot 'h1.dat' u ($1+($3-$4)/2.0):2  with fillsteps fc rgb "#aa00ff" t "h1", 'h1.dat' u 1:2:3:4:($5):($6) with xyerr ls 2 pt 15 ps 0 lw 2 lc rgb "#000000" notitle

Notice that these are valid gnuplot scripts. In fact, once the conversion step is done (first time) you can run future plots with gnuplot directly. Only comments with the root2gnuplot word are parsed for conversions

Build Steps

  1. clone the repo
  2. build with: make

Install

just put the rnuplot binary somewhere on the PATH.
Then you are ready to use rnuplot, just make sure gnuplot is on the PATH as well, since it is called internally

Requirements

  • c++14
  • ROOT (tested with v6-24-00@v6-24-00)
  • gnuplot (tested with v5.4) on the PATH

Uses