Putting histos from 2 different files into one file

Hello!

Is there an easy way to put histos from two different files into one file.
The histos are all different so it is no merging required. I just want to have them in one file instead of two.

It would also be great to be able and put a subset of all histos in file A and a subset of histos in file B into file C.

Thanks a lot
Andi

P.S.: I guess this is somehow done with the clone function?

Hi all,

I almost solved the problem but now I need to save the histograms in the new file in a certain directory and that just does not work!!!

I need to have them in “REF/t3333”

I try:
TFile* combinedFile = new TFile(“newfilesignal.root”, “recreate”);

// does not work …
combinedFile->mkdir(“REF/t3333”);
combinedFile->cd(“REF/t3333”);
histo1D->Write();

// does not work either …
combinedFile->mkdir(“REF”);
combinedFile->cd(“REF”);
combinedFile->mkdir(“t3333”);
combinedFile->cd(“t3333”);
histo1D->Write();

Anyone knows how it works?

Thanks for any help
Andi

Hi Andy,
this should work:[code]TFile* combinedFile = new TFile(“newfilesignal.root”, “recreate”);

combinedFile->mkdir(“REF”);
gDirectory->cd(“REF”);
gDirectory->mkdir(“t3333”);
gDirectory->cd(“t3333”);
histo1D->Write();[/code]
In your first version, mkdir did not create subdirs (see doc, where it says “may not contain slashes”). For your second option: the file’s location doesn’t change (like $HOME), so calling cd on it will always move relative to where the file itself is (again, it’s in the doc, see the part on relative paths). So the second cd was trying to move into newfilesignal.root/t3333. gDirectory, on the other hand, is where you are right now (like $PWD), so that gets updated by cd.
Axel.