Skip to content

TH1::Merge does not extend axes properly for certain histograms with labels #10828

@ponyisi

Description

@ponyisi

In ROOT 6.24/06 we see that merging produces unexpected results for the following situation:

  • 2D histogram, Y axis has labels, X axis does not, SetCanExtend is set for the X axis
  • h2 has more bins in X
  • h1.Merge is called with a TList containing h2. The result has only the bins from h1 and is not extended to match h2.

If the Y axis does not have labels, the X axis is correctly extended by the merge.

A Python test case follows:

from ROOT import TH2F, TList

NBINSX = 5
NBINSY = 1

horig = TH2F('horig', 'histogram', NBINSX, 0, NBINSX, NBINSY, 0, NBINSY)
yax = horig.GetYaxis()
# if labels are not set for the y axis, the output is what is expected
for i in range(NBINSY):
    yax.SetBinLabel(i+1, f'{i+1}')
horig.GetXaxis().SetCanExtend(True)

hclone = horig.Clone()
hclone.LabelsInflate('X')
hclone.Fill(NBINSX-1, 0)

l = TList()
l.Add(hclone)
horig.Merge(l)

print(f'Number of X bins in merged histogram: {horig.GetNbinsX()} (expected {hclone.GetNbinsX()})')

Metadata

Metadata

Assignees

Labels

experimentAffects an experiment / reported by its software & computimng experts

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions