Adding TH2D's with alphanumeric labels

Hi, I have this simple code:

TH2F *h1 = new TH2F("h1", "", 10, 0, 10, 1, 0, 1);
h1->Fill(3, "1", 1);
TH2F *h2 = new TH2F("h2", "", 10, 0, 10, 1, 0, 1);
h2->Fill(4, "2", 1);
h1->LabelsDeflate("Y");
h2->LabelsDeflate("Y");
h1->Add(h2);
h1->Draw();

Why do the two Y bins get merged even though they have different labels? Am I doing something wrong?

Thanks!

Hi @renyhp; I am sure @moneta can provide an answer for that.

Cheers,
J.

Read the documentation for Add, “…adding histogram with labels is not supported, histogram will be added merging them by bin number…”

Oh, thank you, that would explain the behaviour.

However, that still feels strange to me: when I use TH1D’s, the bins are not merged, and the number of labels in the axis increases; also, when I use the code I wrote, I get this info:

Info in <TH2F::Add>: Attempt to add histograms with different labels - trying to use TH1::Merge

which suggests it’s using Merge anyway, and so I would expect the two bins to stay separated.

But also, if I replace h1->Add(h2); with

auto mylist = new TList();
mylist->Add(h2);
h1->Merge(mylist);

(which is the actual way the docs suggest, and is what I’m trying to achieve) the result is still the same.

You need to use ROOT 6.24 (or newer).