The lack of TFileMerger documentation makes using the class problematic. I tried it, and it appears to execute:
G4String workfile = "work_" + filename;
// Rename the output file to the temporary work file name.
gSystem->Rename(filename,workfile);
TFileMerger* merger = new TFileMerger(kFALSE);
merger->AddFile(workfile);
merger->OutputFile(filename);
merger->Merge();
// Remove the work file; it just wastes disk space at this point.
gSystem->Unlink(workfile);
The status message appears in the program output:
[TFile::Cp] Total 5.09 MB |====================| 100.00 % [146.4 MB/s]
But all the ntuples in the output file are now corrupted:
root [0]
Attaching file gramsg4.root as _file0...
(TFile *) 0x5632e50c04b0
root [1] TrackInfo->Scan()
Error in <TBufferFile::ReadClassBuffer>: Could not find the StreamerInfo for version 5 of the class TTree, object skipped at offset 77
Error in <TBufferFile::CheckByteCount>: object of class TTree read too few bytes: 2 instead of 9348
There’s probably some enum or boolean I have to set somewhere, but it’s not clear what it should be.