Hadd problem merging Trees

Dear All

I merged ~1000 rootfiles containing one TDirectoryFile, in which there are two Trees, but I only got ~93k entries instead of ~320k entries. I found this out when I also merged the file in blocks of 200 rootfiles at a time. Rather strange is that the former result (~93k events) is 178MB, while the latter is 179MB. Does anyone have a comment on the reliability of hadd in this situation?

To avoid such unpleasant suprises I thought of using TChain. I am able to merge 1 Tree (the one I am interested in) from all rootfiles but I lost the original file structure: the TDirectoryFile. When trying to make first the TDirectoryFile and then do the TChain, it does not work and I am left with an empty file only containing the TDirectoryFile.

This is my script:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include “TChain.h”
#include “TString.h”
#include “TFile.h”
#include “TDirectoryFile.h”

void Test() {
TFile *fOut = new TFile(“myfinalrootfile.root”, “RECREATE”);
// fOut->mkdir(“tpTree”)->cd();
TChain * chain = new TChain(“tpTree/fitter_tree”,"");

This way my program works, but my merged tree is just named “fitter_tree” and is in the main directory. If I uncomment fOut->mkdir(“tpTree”)->cd();, my program does not work. I know, it is a bit naive (would rather prefer to say intuitive :wink: ), but I could not figure out how to do it properly.
Any comment would be really appreciated.