Open reikdas opened 5 years ago
hi,
your Go code looks fine :) (even if go-hep
might not be installed in the expected location)
it's just that it is being hit by an hysteresis effect originating from hbook/rootcnv
.
hbook/rootcnv
is meant to convert ROOT
TH1x
(and TH2x
and TGraphs
) into their hbook
equivalent, and vice versa.
but hbook
objects are very barebones.
when converting your TH1F
into a hbook.H1D
, you loose the bin-label information.
here is a program that does not loose bin-label informations:
package main
import (
"flag"
"log"
"go-hep.org/x/hep/groot"
)
func main() {
fname := "test.root"
flag.Parse()
if flag.NArg() > 0 {
fname = flag.Arg(0)
}
r, err := groot.Open(fname)
if err != nil {
log.Fatal(err)
}
defer r.Close()
o, err := r.Get("hvar")
if err != nil {
log.Fatal(err)
}
w, err := groot.Create("out.root")
if err != nil {
log.Fatal(err)
}
defer w.Close()
err = w.Put("hvar", o)
if err != nil {
log.Fatal(err)
}
err = w.Close()
if err != nil {
log.Fatal(err)
}
}
that program is actually a slimmed down version of go-hep.org/x/hep/groot/cmd/root-cp:
$> root-cp test.root foo.root
$> python
>>> import ROOT
>>> f = ROOT.TFile.Open("foo.root")
>>> f.Get("hvar").GetXaxis().GetBinLabel(1)
'Hi'
Thanks!
hbook/rootcnv is meant to convert ROOT TH1x (and TH2x and TGraphs) into their hbook equivalent, and vice versa. but hbook objects are very barebones.
I noticed that you renamed the issue and didn't close it. Is hbook retaining ROOT bin labels something that is required though? (The way I created a histogram by first converting it to a hbook is obviously not the recommended way to do it)
I am still considering whether this is something that hbook/rootcnv
should do or not, and thus whether hbook.H{1,2}D
should have a way to "decorate" labels. (perhaps as an hbook.Annotation
?)
hbook
isn't concerned with displaying histograms, but it already provides the ability to give histos a name and a title, so...
Creating test.root (which has a labelled bin) -
Reading it and writing it back in Go - (I am absolutely new to Go so maybe the error is in my code?)
Reading it back in ROOT -
No label was found.
I am particularly curious because there seems to be code to write it - https://github.com/go-hep/hep/blob/master/groot/rhist/axis.go#L132 But the test - https://github.com/go-hep/hep/blob/master/groot/rhist/rhist_test.go has the labels always set to
nil
so maybe groot cannot write labels yet? If that is the case, is it because of some error in WriteObjectAny (https://github.com/go-hep/hep/blob/master/groot/rbytes/wbuffer.go#L136)? (I have been looking at WriteObjectAny as reference for a similar implementation in uproot)cc: @jpivarski