hep: go-hep.org/x/hep/hbook/rootcnv Index | Examples | Files

package rootcnv

import "go-hep.org/x/hep/hbook/rootcnv"

Package rootcnv provides tools to convert ROOT histograms and graphs to go-hep/hbook ones.



Package Files


func FromH1D Uses

func FromH1D(h1 *hbook.H1D) *rhist.H1D

FromH1D creates a new ROOT TH1D from a 1-dim hbook histogram.

func FromH2D Uses

func FromH2D(h2 *hbook.H2D) *rhist.H2D

FromH2D creates a new ROOT TH2D from a 2-dim hbook histogram.

func FromS2D Uses

func FromS2D(s2 *hbook.S2D) rhist.GraphErrors

FromS2D creates a new ROOT TGraphAsymmErrors from 2-dim hbook data points.

func H1D Uses

func H1D(h1 rhist.H1) (*hbook.H1D, error)

H1D creates a new H1D from a TH1x.


f, err := groot.Open("testdata/gauss-h1.root")
if err != nil {
defer f.Close()

obj, err := f.Get("h1d")
if err != nil {

root := obj.(*rhist.H1D)
h, err := rootcnv.H1D(root)
if err != nil {
    log.Fatalf("error converting TH1D: %v\n", err)

fmt.Printf("name:    %q\n", root.Name())
fmt.Printf("mean:    %v\n", h.XMean())
fmt.Printf("std-dev: %v\n", h.XStdDev())
fmt.Printf("std-err: %v\n", h.XStdErr())


name:    "h1d"
mean:    0.028120161729965475
std-dev: 2.5450388581847907
std-err: 0.025447022905060374

func H2D Uses

func H2D(h2 rhist.H2) (*hbook.H2D, error)

H2D creates a new H2D from a TH2x.


f, err := groot.Open("testdata/gauss-h2.root")
if err != nil {
defer f.Close()

obj, err := f.Get("h2d")
if err != nil {

root := obj.(*rhist.H2D)
h, err := rootcnv.H2D(root)
if err != nil {
    log.Fatalf("error converting TH2D: %v\n", err)

fmt.Printf("name:      %q\n", root.Name())
fmt.Printf("x-mean:    %v\n", h.XMean())
fmt.Printf("x-std-dev: %v\n", h.XStdDev())
fmt.Printf("x-std-err: %v\n", h.XStdErr())
fmt.Printf("y-mean:    %v\n", h.YMean())
fmt.Printf("y-std-dev: %v\n", h.YStdDev())
fmt.Printf("y-std-err: %v\n", h.YStdErr())


name:      "h2d"
x-mean:    -0.005792200073827981
x-std-dev: 2.2708057036302542
x-std-err: 0.06540325697671126
y-mean:    0.894201827242525
y-std-dev: 1.8307942514179008
y-std-err: 0.05273014186354511

func S2D Uses

func S2D(g rhist.Graph) (*hbook.S2D, error)

S2D creates a new S2D from a TGraph, TGraphErrors or TGraphAsymmErrors.


f, err := groot.Open("../../groot/testdata/graphs.root")
if err != nil {
defer f.Close()

obj, err := f.Get("tgae")
if err != nil {

root := obj.(rhist.GraphErrors)
g, err := rootcnv.S2D(root)
if err != nil {
    log.Fatalf("error converting TGraphErrors: %v\n", err)

fmt.Printf("name:  %q\n", g.Annotation()["name"])
fmt.Printf("title: %q\n", g.Annotation()["title"])
fmt.Printf("#pts:  %v\n", g.Len())
for i, pt := range g.Points() {
    x := pt.X
    y := pt.Y
    xlo := pt.ErrX.Min
    xhi := pt.ErrX.Max
    ylo := pt.ErrY.Min
    yhi := pt.ErrY.Max
    fmt.Printf("(x,y)[%d] = (%+e +/- [%+e, %+e], %+e +/- [%+e, %+e])\n", i, x, xlo, xhi, y, ylo, yhi)


name:  "tgae"
title: "graph with asymmetric errors"
#pts:  4
(x,y)[0] = (+1.000000e+00 +/- [+1.000000e-01, +2.000000e-01], +2.000000e+00 +/- [+3.000000e-01, +4.000000e-01])
(x,y)[1] = (+2.000000e+00 +/- [+2.000000e-01, +4.000000e-01], +4.000000e+00 +/- [+6.000000e-01, +8.000000e-01])
(x,y)[2] = (+3.000000e+00 +/- [+3.000000e-01, +6.000000e-01], +6.000000e+00 +/- [+9.000000e-01, +1.200000e+00])
(x,y)[3] = (+4.000000e+00 +/- [+4.000000e-01, +8.000000e-01], +8.000000e+00 +/- [+1.200000e+00, +1.600000e+00])

Package rootcnv imports 3 packages (graph) and is imported by 4 packages. Updated 2018-11-11. Refresh now. Tools for package owners.