How to merge two TList of two different TFiles?

Hi everyone.
I’m trying to merge two TLists (that contain 1D e 2D histograms) of two different TFiles in one new TFile.
Anyone could help me?
Thanks in advance


Have you tried to use the command line tool “hadd” ?

At the shell command line, simply type “had” to get online help.

Best Regards


simply do simething like

TFile f("file.root","recreate"); list1->Write(); list2->Write();

Actually I have two files:
TFile* AnalysisResults410.root
KEY: TDirectoryFile PWG3_D2H_Lc2pK0S_0;1 PWG3_D2H_Lc2pK0S_0

TFile* AnalysisResults409.root
KEY: TDirectoryFile PWG3_D2H_Lc2pK0S_10;1 PWG3_D2H_Lc2pK0S_10

If I open these two TDirectoryFile I have, for the first file:
TDirectoryFile* PWG3_D2H_Lc2pK0S_0 PWG3_D2H_Lc2pK0S_0
KEY: TList chist0;1 Doubly linked list

for the second:
TDirectoryFile* PWG3_D2H_Lc2pK0S_10 PWG3_D2H_Lc2pK0S_10
KEY: TList chist10;1 Doubly linked

chist0 and chist10 have the same histrograms inside, for example chist0:
OBJ: TH1F fCEvents conter : 0 at: 0x1008330
OBJ: TH2F histoprotonBachSigmaVspTOF histoprotonBachSigmaVspTOF : 0 at: 0x10cf230
OBJ: TH2F histoprotonBachSigmaVspTPC histoprotonBachSigmaVspTPC : 0 at: 0x1102310
OBJ: TH2F histoprotonBachSigmaVspTOFsgn histoprotonBachSigmaVspTOFsgn : 0 at: 0x1120960
OBJ: TH2F histoprotonBachSigmaVspTPCsgn histoprotonBachSigmaVspTPCsgn : 0 at: 0x113efb0
OBJ: TH2F histoprotonBachSigmaVspTOFbkg histoprotonBachSigmaVspTOFbkg : 0 at: 0x115d600
OBJ: TH2F histoprotonBachSigmaVspTPCbkg histoprotonBachSigmaVspTPCbkg : 0 at: 0x117bc50
OBJ: TH1F hCandidateSelection : 0 at: 0x119a2d0
OBJ: TH1F hEventsWithCandidates conter : 0 at: 0x119b290
OBJ: TH1F hSwitchOnCandidates1 : 0 at: 0x119c480
OBJ: TH1F hSwitchOnCandidates2 : 0 at: 0x119c970
OBJ: TH1F hSwitchOnCandidates3 : 0 at: 0x119ce60
OBJ: TH1F hSwitchOnCandidates4 : 0 at: 0x119d350

I would have a new file AnalysisResultsMerge, with a new TDirectoryFile PWG3_D2H_Lc2pK0S with a TList “chist” in wich i would merge all the histrograms in chist0 and chist10.