Saving All Graphs as PNG Files


ROOT Version: 5.34/10
Platform: Ubuntu 18.04 LTS
Compiler: Not Provided


Hello,

Is there a way to save all graphs as PNG files by inputting a root file?

My code creates around 100 histograms, and I was able to create PNG files for all of them. However, I run the code 257 times, with different input files (TFile infile(“job_0.root”), TFile infile(“job_2.root”), … ,TFile infile(“job_256.root”)). To combine all the root files from the different input files, I use the command “hadd combinedrootfiles.root /*.root” which combines all the root files into one root file, which superimposes all the graphs.

However, I cannot create PNG files from the combinedrootfile.root that I created. Is there a way to save all 100 graphs from this combinedrootfile.root to PNG files?

Before, I was screenshotting all 100 graphs, twice for different data sets, and it was becoming very annoying and time-consuming.

Thank you very much and I really appreciate any help,
ppajarillo

May be the command line tool footprint can help you.

$ rootprint --help
usage: rootprint [-h] [-d DIRECTORY] [--divide DIVIDE] [-D DRAW] [-f FORMAT]
                 [-o OUTPUT] [-s SIZE] [-S STYLE] [-v]
                 FILE [FILE ...]

Print ROOT files contents on ps,pdf or pictures files

positional arguments:
  FILE                  Input file

optional arguments:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory DIRECTORY
                        put output files in a subdirectory named DIRECTORY.
  --divide DIVIDE       divide the canvas ont the format 'x','y' (ex: 2,2)
  -D DRAW, --draw DRAW  specify draw option
  -f FORMAT, --format FORMAT
                        specify output format (ex: pdf, png).
  -o OUTPUT, --output OUTPUT
                        merge files in a file named OUTPUT (only for ps and
                        pdf).
  -s SIZE, --size SIZE  specify canvas size on the format 'width'x'height'
                        (ex: 600x400)
  -S STYLE, --style STYLE
                        specify a C file name which define a style
  -v, --verbose         print informations about the running

Examples:
- rootprint example.root:hist
  Create a pdf file named 'hist.pdf' which contain the histogram 'hist'.

- rootprint -d histograms example.root:hist
  Create a pdf file named 'hist.pdf' which contain the histogram 'hist' and put it in the directory 'histograms' (create it if not already exists).

- rootprint -f png example.root:hist
  Create a png file named 'hist.png' which contain the histogram 'hist'.

- rootprint -o histograms.pdf example.root:hist*
  Create a pdf file named 'histograms.pdf' which contain all histograms whose name starts with 'hist'. It works also with postscript.

1 Like

Hello, thank you so much for your help! Unfortunately, this command does not work since I have an older version of ROOT (5.34/10). I created a function to convert the histogram and it works, however, I need to find a way to create an array of the names of the histograms so I can input it to the function. Do you have an idea on how to do this? Thank you very much!

${ROOTSYS}/tutorials/io/loopdir.C

if you’re stuck with a ROOT version that doesn’t have rootprint, you could still use “my” root-print:

$> root-print -h
Usage: root-print [options] file.root [file.root [...]]
ex:
 $> root-print -f pdf ./testdata/histos.root
 $> root-print -f pdf ./testdata/histos.root:h1
 $> root-print -f pdf ./testdata/histos.root:h.*
 $> root-print -f pdf -o output ./testdata/histos.root:h1

options:
  -f string
    	output format for plots (pdf, png, svg, ...) (default "pdf")
  -o string
    	output directory for plots
  -v	enable verbose mode

I have put binaries over there:

but if you have a Go installation (Go is installed on lxplus, for instance), it’s as simple as:

$> go get -v go-hep.org/x/hep/rootio/cmd/root-print

hth,
-s

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.