Copying a subset of a tree to a new file

Hello,

I am encountering problems with copying a subset of a tree, actually a chain into a new file. I have followed the tutorial:

root.cern.ch/root/html/examples/copytree2.C.html

but using a chain instead of a tree.

What happens is that I get several copies of the tree in the same file. I only want one copy of it, but it seems to duplicate itself. If the chain that I am copying is called FullRec0 I get in my new file trees called f.ex.

FullRec,21 and FullRec,22

I only want one tree called FullRec.

A short version of the code I am using is attached.

Appreciate any help.
Maiken
treeloopMacro_small.C (1.55 KB)

[quote]I only want one tree called FullRec. [/quote]Per se that is what you have :slight_smile:. This is actually one backup copy and one final copy of the meta data of the TTree (and not of the data). (Those are technically called ‘cycles’ (see the user’s guide for details)).

You can callmyfile->Purge();to remove the backup copy.

Cheers,
Philippe.

Thank you for your answer.

Yes, maybe this is just the backup copy. What has confused me though is that the trees now how f.ex. FullRec0;21 and FullRec0;22 instead of FullRec0;1 and FullRec0;2. I have an idea that it can be because I add so many root files in the chain. But If I add f.ex. 36 root files into the chain I do not get FullRec0;36, but f.ex. FullRec0;22. It is just a little odd.

So you think my code is doing what it is supposed to do, and not duplicating things unnessecary?

Thanks again:)
Maiken

[quote]So you think my code is doing what it is supposed to do, and not duplicating things unnessecary? [/quote]Indeed :slight_smile:

[quote]I do not get FullRec0;36, but f.ex. FullRec0;22. It is just a little odd. [/quote]The number of time it is saved depends on data size and not on the number of input files (see TTree::SetAutoSave).

Cheers,
Philippe.

Thank you very much for your replies! I will just continue with what I am doing then, and be happy that everything is ok.

Have a good easter, and good night!

Maiken