# ROOT creating multiple trees

**URL:** <https://root-forum.cern.ch/t/root-creating-multiple-trees/63711>\
**Category:** Newbie\
**Created:** [June 11, 2025, 1:01pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711 "2025-06-11T13:01:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [June 11, 2025, 1:01pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/1 "2025-06-11T13:01:25Z")

</div>

_ROOT Version:_ 6.32.04  
_Platform:_ WSL2 Ubuntu

Hello! I am generating 1E5 events in Pythia and storing particle data into a ROOT file. However, as shown below, why does ROOT make more than one tree?

![image](https://root-forum.cern.ch/uploads/default/original/3X/b/a/ba5caf2cbcb05a1b528ccde41dc56e2ffb4033c6.png)

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/b/a/ba8acc2c26f1ecaca1ca5e86df348422ba058588.png)

The `tree_raw;1` stores 55901 entries and the `tree_raw;2` stores 1E5 entries. Is there a memory limit of one tree? And does this affect the reading process?

Thanks in advance. Cheers.

---

<div class="post-metadata">

**Author:** ![devajith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/devajith/32/37165_2.png) [@devajith](https://root-forum.cern.ch/u/devajith)\
**Post date:** [June 11, 2025, 2:07pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/2 "2025-06-11T14:07:53Z")

</div>

Hi @phylmath, thank you for your question.

> [@phylmath](#):
>
> Is there a memory limit of one tree?

The default max size is 100 Gigabytes (and you can increase the limit!) - [ROOT: TTree Class Reference](https://root.cern.ch/doc/master/classTTree.html#a3ab4006402ddbc3950e1ddab5e3aadd6)

I’m adding @pcanal in the loop.

Cheers,  
Dev

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [June 11, 2025, 9:37pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/3 "2025-06-11T21:37:17Z")

</div>

those are two cycles of the same tree. It’s like a backup history.  
You can use Write(TObject::kOverwriteDelete) to only store the last cycle.

---

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [October 1, 2025, 2:15pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/4 "2025-10-01T14:15:21Z")

</div>

Hi ferhue. Thank you very much for the response. How do I write this in my code? I have a `tree→Fill()` at the end of each loop iteration and an `output→Write()` at the end of the code. Where do I add the `TObject::kOverwriteDelete` as you stated?

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [October 1, 2025, 4:06pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/5 "2025-10-01T16:06:33Z")

</div>

kOverwriteDelete is not in the [TObject documentation](https://root.cern/doc/master/classTObject.html); maybe you mean kWriteDelete?

@phylmath : In any case, maybe kOverwrite will do; just write the tree, not the file (supposing output is a TFile):

```auto
output->cd();
tree->Write("tree_raw",TObject::kOverwrite);
output->Close();

```

If kOverwrite does not do what you want, try kWriteDelete.

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [October 1, 2025, 5:39pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/6 "2025-10-01T17:39:59Z")

</div>

Yep sorry, kWriteDelete

---

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [October 16, 2025, 12:59pm UTC](https://root-forum.cern.ch/t/root-creating-multiple-trees/63711/7 "2025-10-16T12:59:20Z")

</div>

Thanks all. I solved by adding `tree→SetAutoSave(0)` to the beginning of my code.
