TH...::Merge and alphanumeric bin labels

Hello,

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:

  1. 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?

  2. 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?

                                                            Thanks and ciao

                                                                   Andrea

Ciao Andrea,

Which version are you using ? I have recently (few weeks ago, after 5.28) fixed a bug and applied other changes in TH1::Merge for alphanumeric labels.

Lorenzo

Hi Lorenzo,

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?

                                                   Thanks and ciao

                                                         Andrea

5.28 and earlier version have a bug, see
savannah.cern.ch/bugs/index.php?75902

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

Ciao
Lorenzo

Hi!

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?

Thanks in advance,

Sebastian

Hi,

Yes, the bug is fixed in the trunk and you should not have to call LabelsDeflate,

Best Regards

Lorenzo

Hi!

Thanks. For the meantime (I cannot use trunk now) - does LabelsDeflate help in all cases or could it still be that merging produces wrong results?

Best regards,

Sebastian

Hi,
It might help but I am not sure. I would use it only in the trunk. If I move the fix in the 5.28 patches, will it be better for you ?

Lorenzo

Dear Lorenzo!

I just tried trunk and can confirm that my initial problem is solved. Unfortunately I’m facing another one.

an() {

    file1 = new TFile("out1.root","RECREATE");

    hfile1 = new TH1F("h1","h1",2,0,1);

    hfile1->Fill("foo",1);

    c1 = new TCanvas;
    hfile1->Draw();
    c1->Print("hfile1.png");

    file1->Write();
    file1->Close();

    file2 = new TFile("out2.root","RECREATE");

    hfile2 = new TH1F("h1","h1",2,0,1);

    hfile2->Fill("qux",2);

    c2 = new TCanvas;
    hfile2->Draw();
    c2->Print("hfile2.png");

    file2->Write();
    file2->Close();

    file3 = new TFile("out3.root","RECREATE");

    hfile3 = new TH1F("h1","h1",2,0,1);

    // empty histogram
    // hfile3->Fill("quux",1);

    c3 = new TCanvas;
    hfile3->Draw();
    c3->Print("hfile3.png");

    file3->Write();
    file3->Close();

}

The third histogram is empty. The result of the merge depends on the order of the input files:

$ rm *root; root -l an.C -q && hadd -f merge.root out1.root out2.root out3.root

works fine. Although I get “Warning in TH1F::Merge: Not all histograms have labels. I will ignore labels, falling back to bin numbering mode.”

But if I move out3.root to the front the following happens.

$ rm *root; root -l an.C -q && hadd -f merge.root out3.root out2.root out1.root

Could you please have a look?

Thanks in advance,

Sebastian

Hi,

There was a bug in case one of the histogram is empty. It should be fixed now in the trunk. Could you retry with the latest version ?

Thanks for reporting this problem

Lorenzo

Hi

I came across the same problem… But this time with TProfile histograms. I am trying to merge some TProfiles with alphanumeric bin labels.

I am using the trunk
ROOT 5.31/01 trunk@40452

The merging works fine with the TH1. Here is a test code to compare TH1F and TProfile outputs

alphaNumericTest()
{
    TProfileTest();
    TH1Test();
}

Could some one have a look into this.. 

thanks 

Rohin


TProfileTest(){
    TRandom2 rand(0);

    unsigned int k =0;

    for(int i =0; i < 10; i++)
    {
        TFile *f = new TFile(Form("TProfile_%d.root",i),"RECREATE");
        TProfile *p = new TProfile("h1","name",10,0,10);
        for(int j =0; j < 1000; j++)
        {
            unsigned int weight = rand.Uniform(10,20);
            p->Fill(Form("s%d",k),weight);
        }
        p->Write();
        f->Close();
        k++;
    }
}

TH1Test()
{
    TRandom2 rand(0);

    unsigned int k =0;

    for(int i =0; i < 10; i++)
    {
        TFile *f = new TFile(Form("TH1_%d.root",i),"RECREATE");
        TH1F *h = new TH1F("h1","name",10,0,10);
        for(int j =0; j < 1000; j++)
        {
            unsigned int weight = rand.Uniform(10,20);
            h->Fill(Form("s%d",k),weight);
        }
        h->Write();
        f->Close();
        k++;
    }
}

TH1 merge results produces expected result


TProfile does not. It looks like the mean of all the bins are put in the first bin.


could some one have a look into this

thanks

Rohin

Hi,

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

Best Regards

Lorenzo