this result in the TTree object to be deleted. [You can avoid this by call SetDirectory(0) but then the TTree no longer has access to it data … you can work-around that calling LoadBaskets but then you might run out of memory … )
This is the expected behavior of your code per se. However not that what is ‘duplicated’ is not the data but the much smaller meta-data (the TTree object itself). This is due to both the ROOT file support for ‘backups’ (or cycle) of objects and
The first statement will periodically take snapshot of the TTree meta data (to allow for file recovery if the process crashes) and it has no choice but to store it using the old name. And then the 2nd statement store the meta-data one last time (with complete information) under the new name.
What you can do instead is:
// Add tree to list if max sample threshold is not reached
many thanks for the explanation. Your suggestion worked such that the backup data is not visible anymore.
Concerning the deletion of the tree input files, I don’t understand why the code is running though the TTree object is deleted.