Skip to content

Usage: Histograms and Graphs

Andrey edited this page Apr 9, 2020 · 16 revisions

How to save histograms and graphs from Java/Groovy to ROOT file:

import org.jlab.jroot.ROOTFile
import org.jlab.groot.data.H1F
import org.jlab.groot.data.H2F
import org.jlab.groot.data.GraphErrors

def h1 = new H1F("h1","title h1",100,-3,3)
def h2 = new H2F("h2","title h2",100,-3,3,100,0,10)
def gr = new GraphErrors("gr")
// Fill the objects above

def ff = new ROOTFile('test0.root')
ff.addDataSet(h1)
ff.addDataSet(h2)
ff.addDataSet(gr)
ff.close()

The resulting ROOT file contains h1, h2 and gr objects

How to make subdirectories in ROOT file

import org.jlab.jroot.ROOTFile
import org.jlab.groot.data.H1F

def h1 = new H1F("h1","title h1",100,-3,3)

def ff = new ROOTFile('test0.root')
ff.mkdir("/root/xyz")
ff.cd("/root/xyz")
ff.addDataSet(h1)
ff.close()

How to specify subdirectories using object's name

import org.jlab.jroot.ROOTFile
import org.jlab.groot.data.H1F

def h1 = new H1F("/root/test/h1","title h1",100,-3,3)

def ff = new ROOTFile('test0.root')
ff.addDataSet(h1)
ff.close()