scikit-hep / hepconvert

BSD 3-Clause "New" or "Revised" License
8 stars 1 forks source link

`hepconvert add` seems to create histogram with visualization errors #81

Closed matthewfeickert closed 3 months ago

matthewfeickert commented 3 months ago

In hepconvert v1.3.3 the hepconvert add CLI API runs without errors, though it seems to produce a file that, while does contain valid bin contents, can't be visualized correctly.

Minimal reproducible example:

# generate_hist_root.py
import ROOT

gauss_1 = ROOT.TH1I("name", "title", 5, -4, 4)
gauss_1.FillRandom("gaus")
gauss_1.Sumw2()
gauss_1.SetDirectory(0)
outHistFile = ROOT.TFile.Open("hist1.root", "RECREATE")
outHistFile.cd()
gauss_1.Write()
outHistFile.Close()
$ pixi global install hepconvert
$ python generate_hist_root.py
$ cp hist1.root hist2.root
$ hepconvert add output.root hist1.root hist2.root 

The histogram in the file does have valid bin content:

# check_values.py
import uproot

with uproot.open("hist1.root") as read_file:
    hist = read_file["name"]
    print(f"hist1 values:  {hist.values()}")

with uproot.open("output.root") as read_file:
    hist_out = read_file["name"]
    print(f"output values: {hist_out.values()}")
$ python check_values.py 
hist1 values:  [  44 1031 2833 1042   50]
output values: [  88 2062 5666 2084  100]

but when I try to inspect it with a TBrowser, the histogram fails to render on the TCanvas

$ root -l output.root 
root [0] 
Attaching file output.root as _file0...
(TFile *) 0x6276606d0140
root [1] TBrowser b
(TBrowser &) Name: Browser Title: ROOT Object Browser

image

and root gives a warning in the terminal

root [2] Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: Canvas_1 width changed from 0 to 10

Error in <TGaxis::PaintAxis>: wmin (0.000000) == wmax (0.000000)

As a secondary check, if I use my local version of ROOT

$ root --version
ROOT Version: 6.30/02
Built for linuxx8664gcc on Jan 11 2024, 05:45:32
From tags/v6-30-02@
$ command -v root
/home/feickert/bin/root-cern/bin/root
$ command -v hadd
/home/feickert/bin/root-cern/bin/hadd

to try to do the same thing with hadd

$ hadd output_hadd.root hist1.root hist2.root 
hadd Target file: output_hadd.root
hadd compression setting for all output: 1
hadd Source file 1: hist1.root
hadd Source file 2: hist2.root
hadd Target path: output_hadd.root:/

then things work fine as expected

$ root -l output_hadd.root 
root [0] 
Attaching file output_hadd.root as _file0...
(TFile *) 0x6137e4df7a70
root [1] TBrowser b
(TBrowser &) Name: Browser Title: ROOT Object Browser

image


Aside: If I call the visualization commands from the ROOT repl, I get similar, but different errors:

$ root -l output.root 
root [0] 
Attaching file output.root as _file0...
(TFile *) 0x6194b30ae0c0
root [1] hist = (TH1F*) _file0->Get("name")
(TH1F *) 0x6194b30ac180
root [2] hist->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 width changed from 0 to 10

Error in <TGaxis::PaintAxis>: wmin (0.000000) == wmax (0.000000)
root [3] Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 width changed from 0 to 10

Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 width changed from 0 to 10

root [3]