I don’t understand why the following code has a bug. In the cout I see correctly Event001,Event002, Event003 etc etc but I get “Unknown directory Event001”, “Unknown directory Event002” “Unknown directory Event003” etc etc
sprintf(c, "%03d", j);
TString stringa = "Event"+ string(c);
TDirectoryFile *hpx = new TDirectoryFile(stringa,"");
cout << stringa << " ." << endl;
please look up the TDirectoryFile constructor (http://root.cern.ch/root/html/TDirectoryFile.html#TDirectoryFile:TDirectoryFile@2). It takes a pointer to the mother directory as 4th argument and defaults to 0 (i.e. no mother directory) if it isn’t explicitly given. You want your directories to be below hfile, so that’s their mother directory.
TDirectoryFile *hpx = new TDirectoryFile(stringa,"", "", hfile);