# Creating trees or branches from histograms

**URL:** <https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795>\
**Category:** Newbie\
**Created:** [October 20, 2023, 1:38pm UTC](https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795 "2023-10-20T13:38:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elemental](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/elemental/32/34841_2.png) [@elemental](https://root-forum.cern.ch/u/elemental)\
**Post date:** [October 20, 2023, 1:38pm UTC](https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795/1 "2023-10-20T13:38:57Z")

</div>

Hi,

I am performing analysis over a dataset and it usually entails creating a load of histograms (atleast 30-40). I wish to be able to group/bunch these histograms into branches like we do in trees-\>braches-\>leafs structure so as to have a one branch for each category of histograms.

Could you suggest any suitable approach if such a thing is possible. A pseudo code will help in case there is a solution for this query.

thanks in advance.

\_ROOT Version:6.28/06  
\_Platform: macOS  
\_Compiler: cling 0.9

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 20, 2023, 1:50pm UTC](https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795/2 "2023-10-20T13:50:22Z")

</div>

Welcome to the ROOT forum

I guess @pcanal can help you.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 20, 2023, 8:59pm UTC](https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795/3 "2023-10-20T20:59:50Z")

</div>

Unless you have multiple version of these histograms, `TTree` would not be beneficial. In this case, you would be better serve organizing the `TFile` in sub-directories (see `TFile::mkdir`) for each categories.

Alternative you could also store the raw data of the histograms in branches.

Also you can simply store the histogram in unsplit branches:

```auto
tree->Branch(branchname, &histptr, 32000, 0 /* splitlevel */);

```

---

<div class="post-metadata">

**Author:** ![elemental](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/elemental/32/34841_2.png) [@elemental](https://root-forum.cern.ch/u/elemental)\
**Post date:** [January 10, 2024, 5:40pm UTC](https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795/4 "2024-01-10T17:40:17Z")

</div>

Hi @pcanal,  
Could you please provide a sample code or an example how to put histograms as branches of a tree ? Sorry, I am pretty new to root here.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 10, 2024, 6:29pm UTC](https://root-forum.cern.ch/t/creating-trees-or-branches-from-histograms/56795/5 "2024-01-10T18:29:17Z")

</div>

The best is not put the histogram but the raw data in the TTree. See for example [ROOT: Tree tutorials](https://root.cern.ch/doc/v610/group __tutorial__ tree.html)

You can also read [Trees - ROOT](https://root.cern/manual/trees/) and [Dataframes - ROOT](https://root.cern/manual/data_frame/)
