Incomplete tree when creating a rootfile

Dear Rooters,

I encounter a problem when trying to create a root file. I tried to do it the simplest way (I am a beginner) so I create one tree with several branches that contain only one leaf. The code compiles and runs fine but in the created rootfile, I have 2 trees. The tree I create is called “Data” and in the rootfile I have: “Data;2” and “Data;1” . “Data;2” is complete and contains all the information I need but “Data;1” contains only around half the events…

If I process less events or store less variables (branches), the problem disappears so it looks like a memory problem. I used valgrind to make sure I don’t have any memory leak but that didn’t solve the problem.

I attach my code, thank you for your help. (8.32 KB)