Documentation
¶
Overview ¶
Package rsql provides a convenient access to ROOT files/trees as a database.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Scan ¶
Scan executes a query against the given tree and runs the function f within that context.
Example ¶
package main import ( "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql" "go-hep.org/x/hep/groot/rtree" ) func main() { f, err := groot.Open("../testdata/simple.root") if err != nil { log.Fatal(err) } defer f.Close() o, err := f.Get("tree") if err != nil { log.Fatal(err) } tree := o.(rtree.Tree) var data []float64 err = rsql.Scan(tree, "SELECT two FROM tree", func(x float64) error { data = append(data, x) return nil }) if err != nil { log.Fatal(err) } fmt.Printf("tree[%q]: %v\n", "two", data) }
Output: tree["two"]: [1.1 2.2 3.3 4.4]
Example (NVars) ¶
package main import ( "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql" "go-hep.org/x/hep/groot/rtree" ) func main() { f, err := groot.Open("../testdata/simple.root") if err != nil { log.Fatal(err) } defer f.Close() o, err := f.Get("tree") if err != nil { log.Fatal(err) } tree := o.(rtree.Tree) var ( v1s []int32 v2s []float64 v3s []string ) err = rsql.Scan(tree, "SELECT (one, two, three) FROM tree", func(x int32, y float64, z string) error { v1s = append(v1s, x) v2s = append(v2s, y) v3s = append(v3s, z) return nil }) if err != nil { log.Fatal(err) } fmt.Printf("tree[%q]: %v\n", "one", v1s) fmt.Printf("tree[%q]: %v\n", "two", v2s) fmt.Printf("tree[%q]: %q\n", "three", v3s) }
Output: tree["one"]: [1 2 3 4] tree["two"]: [1.1 2.2 3.3 4.4] tree["three"]: ["uno" "dos" "tres" "quatro"]
func ScanH1D ¶
ScanH1D executes a query against the tree and fills the histogram with the results of the query. If h is nil, a (100-bins, xmin, xmax+ULP) histogram is created, where xmin and xmax are inferred from the content of the underlying database.
Example ¶
package main import ( "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql" "go-hep.org/x/hep/groot/rtree" ) func main() { f, err := groot.Open("../testdata/simple.root") if err != nil { log.Fatal(err) } defer f.Close() o, err := f.Get("tree") if err != nil { log.Fatal(err) } tree := o.(rtree.Tree) h, err := rsql.ScanH1D(tree, "SELECT two FROM tree", nil) if err != nil { log.Fatal(err) } fmt.Printf("entries: %v\n", h.Entries()) fmt.Printf("x-axis: (min=%v, max=%v)\n", h.XMin(), h.XMax()) fmt.Printf("x-mean: %v\n", h.XMean()) fmt.Printf("x-std-dev: %1.3f\nx-std-err: %1.3f\n", h.XStdDev(), h.XStdErr()) }
Output: entries: 4 x-axis: (min=1.1, max=4.400000000000001) x-mean: 2.75 x-std-dev: 1.420 x-std-err: 0.710
Example (WithH1D) ¶
package main import ( "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql" "go-hep.org/x/hep/groot/rtree" "go-hep.org/x/hep/hbook" ) func main() { f, err := groot.Open("../testdata/simple.root") if err != nil { log.Fatal(err) } defer f.Close() o, err := f.Get("tree") if err != nil { log.Fatal(err) } tree := o.(rtree.Tree) h, err := rsql.ScanH1D(tree, "SELECT two FROM tree", hbook.NewH1D(100, 0, 10)) if err != nil { log.Fatal(err) } fmt.Printf("entries: %v\n", h.Entries()) fmt.Printf("x-axis: (min=%v, max=%v)\n", h.XMin(), h.XMax()) fmt.Printf("x-mean: %v\n", h.XMean()) fmt.Printf("x-std-dev: %1.3f\nx-std-err: %1.3f\n", h.XStdDev(), h.XStdErr()) }
Output: entries: 4 x-axis: (min=0, max=10) x-mean: 2.75 x-std-dev: 1.420 x-std-err: 0.710
func ScanH2D ¶
ScanH2D executes a query against the ntuple and fills the histogram with the results of the query. If h is nil, a (100-bins, xmin, xmax+ULP) (100-bins, ymin, ymax+ULP) 2d-histogram is created, where xmin, xmax and ymin,ymax are inferred from the content of the underlying database.
Example ¶
package main import ( "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql" "go-hep.org/x/hep/groot/rtree" ) func main() { f, err := groot.Open("../testdata/simple.root") if err != nil { log.Fatal(err) } defer f.Close() o, err := f.Get("tree") if err != nil { log.Fatal(err) } tree := o.(rtree.Tree) h, err := rsql.ScanH2D(tree, "SELECT (one, two) FROM tree", nil) if err != nil { log.Fatal(err) } fmt.Printf("entries: %v\n", h.Entries()) fmt.Printf("x-axis: (min=%v, max=%v)\n", h.XMin(), h.XMax()) fmt.Printf("x-mean: %v\n", h.XMean()) fmt.Printf("x-std-dev: %1.3f\nx-std-err: %1.3f\n", h.XStdDev(), h.XStdErr()) fmt.Printf("y-axis: (min=%v, max=%v)\n", h.YMin(), h.YMax()) fmt.Printf("y-mean: %v\n", h.YMean()) fmt.Printf("y-std-dev: %1.3f\ny-std-err: %1.3f\n", h.YStdDev(), h.YStdErr()) }
Output: entries: 4 x-axis: (min=1, max=4.000000000000001) x-mean: 2.5 x-std-dev: 1.291 x-std-err: 0.645 y-axis: (min=1.1, max=4.400000000000001) y-mean: 2.75 y-std-dev: 1.420 y-std-err: 0.710
Example (WithH2D) ¶
package main import ( "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql" "go-hep.org/x/hep/groot/rtree" "go-hep.org/x/hep/hbook" ) func main() { f, err := groot.Open("../testdata/simple.root") if err != nil { log.Fatal(err) } defer f.Close() o, err := f.Get("tree") if err != nil { log.Fatal(err) } tree := o.(rtree.Tree) h, err := rsql.ScanH2D(tree, "SELECT (one, two) FROM tree", hbook.NewH2D(100, 0, 10, 100, 0, 10)) if err != nil { log.Fatal(err) } fmt.Printf("entries: %v\n", h.Entries()) fmt.Printf("x-axis: (min=%v, max=%v)\n", h.XMin(), h.XMax()) fmt.Printf("x-mean: %v\n", h.XMean()) fmt.Printf("x-std-dev: %1.3f\nx-std-err: %1.3f\n", h.XStdDev(), h.XStdErr()) fmt.Printf("y-axis: (min=%v, max=%v)\n", h.YMin(), h.YMax()) fmt.Printf("y-mean: %v\n", h.YMean()) fmt.Printf("y-std-dev: %1.3f\ny-std-err: %1.3f\n", h.YStdDev(), h.YStdErr()) }
Output: entries: 4 x-axis: (min=0, max=10) x-mean: 2.5 x-std-dev: 1.291 x-std-err: 0.645 y-axis: (min=0, max=10) y-mean: 2.75 y-std-dev: 1.420 y-std-err: 0.710
Types ¶
This section is empty.