Merge root files

Hi there,

is there a simple way to merge root files with different histogramms (TH1D and TH2D) in it?
Example:
I have a file A.root and a file B.root

In A.root I have
hist1
hist2
histC (some fraction of the whole luminosity in it)

In B.root I have
hist3
hist4
and again histC (some other fraction of the whole luminosity in it)

and I want one file, lets say C.root with
hist1
hist2
hist3
hist4
histC (with the total luminosity)

hadd gives me
hist1
hist2
histC (with the total luminosity)

Thanks a lot
cheers
Chris

Hi Chris,

Unfortunately no. hadd (and thus TFileMerger) only merge with the content of the first file. To ‘work around’ the limitation I suppose you could populate the original file with ‘empty’ version of hist3 and hist4.

Cheers,
Philippe.

Sorry to contradict Philippe, but hadd was designed to be able to cope with this use case.
May be changes were done in the latest versions removing this essential functionality.

Rene

Hi,

As always Rene is correct. hadd does indeed support this case and actually works as expected on all the example I tried.

So you are encountering so other issue and we would more details example to investigate it further.

Cheers,
Philippe.

Could you give me an example how you were able to manage that?

I created two root files. File A.root with two TH1D: a and b
And one file B.root with one TH1D called c

After using hadd.C I get a result root file with only a and b in it.

The test TH1D´s are empty… is this a problem?

Hi,

Do not use hadd.C which is only a tutorials/example. Instead use $ROOTSYS/bin/hadd (or the class TFileMerger).

Cheers,
Philippe.

Hi,

Oh my god, thank you two so much. It works!

cheers
chris