Adding histograms from multiple files

Hello,

I have histograms in multiple files that I would like to add together, then write the summed histograms as one histogram to a new file. I do:

TFile *F1 = new TFile(“newfile.root”,“RECREATE”);
TFile f1(“path/to/file_0.root”);
TH2F h1 = (TH2F)f1.Get(“hist1”);

N=4;
for (int i=0; i<N; i++){
char Path[512];
sprintf(Path,"/path/to/file_%d.root",i);
TFile f(Path);
h= (TH2F*)f.Get(“hist1”);
h1->Add(h);
}

h1->SetDirectory(F1);
F1->Write();
F1->Close();

The output is an empty histogram, along with the following error messages:

Error in TStreamerInfo::WriteBuffer: The element TAxis::fTimeDisplay type 218 (Bool_t) is not supported yet

Any ideas as to what I am doing wrong/how to make it right? Thanks a lot.

-eric

Which version of ROOT are you using? This must be an unstable version.
Use 4.04/02 or newer.

We provide a standard tool to merge files containing histograms or Trees.

Note that in your example, the loop should be
for (Int_t i=1;i<n and not i=0

Rene

Thanks, Rene. I had been using version 4.02/00, but I upgraded to 4.04/02, and now the macro works as expected.

-eric