rootcnv

package
v0.32.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2022 License: BSD-3-Clause Imports: 2 Imported by: 1

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromH1D added in v0.15.0

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

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

func FromH2D added in v0.15.0

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

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

func FromS2D added in v0.15.0

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

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

func H1D

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

H1D creates a new H1D from a TH1x.

Example
package main

import (
	"fmt"
	"log"

	"go-hep.org/x/hep/groot"
	"go-hep.org/x/hep/groot/rhist"
	"go-hep.org/x/hep/hbook/rootcnv"
)

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

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

	var (
		root = obj.(*rhist.H1D)
		h    = rootcnv.H1D(root)
	)

	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())

}
Output:

name:    "h1d"
mean:    0.028120158262930028
std-dev: 2.5450388861661377
std-err: 0.025447023184829384

func H2D

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

H2D creates a new H2D from a TH2x.

Example
package main

import (
	"fmt"
	"log"

	"go-hep.org/x/hep/groot"
	"go-hep.org/x/hep/groot/rhist"
	"go-hep.org/x/hep/hbook/rootcnv"
)

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

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

	var (
		root = obj.(*rhist.H2D)
		h    = rootcnv.H2D(root)
	)

	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())

}
Output:

name:      "h2d"
x-mean:    -0.005792199729986178
x-std-dev: 2.270805729597938
x-std-err: 0.06540325772462689
y-mean:    0.8942018621292575
y-std-dev: 1.830794214602073
y-std-err: 0.05273014080318356

func S2D

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

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

Example
package main

import (
	"fmt"
	"log"

	"go-hep.org/x/hep/groot"
	"go-hep.org/x/hep/groot/rhist"
	"go-hep.org/x/hep/hbook/rootcnv"
)

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

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

	var (
		root = obj.(rhist.GraphErrors)
		g    = rootcnv.S2D(root)
	)

	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)
	}

}
Output:

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])

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL