Skip to content

[Python] TH1 equality operator pythonization not appropriate for ROOT histograms #19038

Open
@guitargeek

Description

@guitargeek

Description

The UHI implementation of the equality operator only compares the histogram type, binning and counts.

ROOT histograms have way more properties, like drawing options, and even more crucially they store the sum-of-weights-squared, where different values make a big difference in the statistical interpretation (the errorbars are directly inferred from it).

Therefore, I think the currently-implemented equality check is oversimplifying things and therefore potentially dangerous.

Furthermore, the new equality operator marks a significant behavior change that is undocumented in the release notes, since previously it was doing a comparison by pointer. This should be documented in the release notes if we decide to keep the UHI implementation.

We have examples in the ROOT code base itself, where the equality operator wrongly assumed that it checks for pointer equality:

It's likely that there is user code that there is user code that makes the same assumption, which would be broken in 6.36 with the UHI.

Reproducer

import ROOT

hist1 = ROOT.TH1D("hist1", "hist1", 1, -1., 1.)
hist1.Fill(0., 2.)
hist1.Fill(0., 2.)
print(hist1.GetSumw2()[1])

hist2 = ROOT.TH1D("hist2", "hist2", 1, -1., 1.)
hist2.Fill(0., 4.)
print(hist2.GetSumw2()[1])

print(hist1 == hist2) # ROOT will tell you the histograms are identical, while they have different sumw2!

The output will be:

8.0
16.0
True

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions