I have been using hadd (and therefore TH…::Merge) since a long time and I am very happy with it. it is able to handle many cases I have in the files I want to combine like automatically rebinned histograms differently rebinned in the different files or different TDirectory structures.
Now I think I have reached the limit and I want to be sure if there is a simple way out.
I have a TH1F and a TH2F which are created with 10 bin (from 0 to 10) and with 10x10 (from 0 to 10 in both axis) and with TH1::kCanRebin set.
They are both filled with alphanumeric values like
Fill(string,w) and Fill(stringx,stringy,w). In the different files I want to combine the values of string or of stringx and stringy can be different and can occur in a different order. It is even possible that in some of these files there is no entry.
Firstly, I’d like to know if there is any chance that Merge is able to produce a correct result. Clearly, given the fact that the order in which the different values of string occur is different I do not expect that the resulting histograms reproduce any specific order: I am just interested that the number of entries associated to the bin with label “string” or label (“stringx”,“stringy”) is the correct one.
Then when I try to combine these files I got a few error messages:
Warning in TH1F::Merge: Not all histograms have labels. I will ignore labels, falling back to bin numbering mode
I suspect this is due to the case when in one of the files the TH1F histograms is not filled with any entry. Any suggestion to avoid it? Would it help if I book the histogram with zero bin to start with and I let the rebin option to create new bins when a new “string” value is filled?
Error in TH2F::Merge: Cannot merge histograms - the histograms have different limits and undeflows/overflows are present. The initial histogram is now broken!
any idea what is the cause of this error and if I can avoid it?
I am still using 5.22 since I use what it the default version used by the CMS software framework.
If I want to try your fixes should I use 5.28 or a more recent version? Would it be a problem to use it to try to merge histograms produced with 5.22? Is there a description of your fixes?
Your problem could caused by the empty histograms. You can either to create the label at book time or use the trick by fill with a dummy label and zero weight. This will created automatically the label
I’m also having a problem with hadd and alphanumeric bin labels. I’m using root 5.28/00a.
an() {
file1 = new TFile("out1.root","RECREATE");
hfile1 = new TH1F("h1","h1",2,0,1);
// hfile1->SetBit(TH1::kCanRebin);
hfile1->Fill("foo",1);
hfile1->Fill("bar",3);
hfile1->Fill("baz",2);
// hfile1->LabelsDeflate();
file1->Write();
file1->Close();
file2 = new TFile("out2.root","RECREATE");
hfile2 = new TH1F("h1","h1",2,0,1);
// hfile2->SetBit(TH1::kCanRebin);
hfile2->Fill("qux",2);
// hfile2->LabelsDeflate();
file2->Write();
file2->Close();
}
If I run without LabelsDeflate the result is the following:
$ rm *root; root -l an.C -q && hadd -f merge.root out1.root out2.root
root [0]
Processing an.C...
Info in <TCanvas::Print>: file hfile1.png has been created
Info in <TCanvas::Print>: file hfile2.png has been created
Target file: merge.root
Source file 1: out1.root
Source file 2: out2.root
Target path: merge.root:/
No warning message, but:
“baz” has now 0 entries!
If I enable LabelsDeflate the result is as expected. However there are two trailing bins.
Is this fixed in trunk? If LabelsDeflate is mandatory could “hadd” issue a warning?
There is currently no support in ROOT for merging TProfile’s with labels. It is something we should add for the next release. I’ll let you know when it will be implemented