# How to save canvas (or histogram) in a tree?

**URL:** <https://root-forum.cern.ch/t/how-to-save-canvas-or-histogram-in-a-tree/50169>\
**Category:** Newbie\
**Created:** [May 29, 2022, 5:14pm UTC](https://root-forum.cern.ch/t/how-to-save-canvas-or-histogram-in-a-tree/50169 "2022-05-29T17:14:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divyang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/7ea924/32.png) [@Divyang](https://root-forum.cern.ch/u/Divyang)\
**Post date:** [May 29, 2022, 5:14pm UTC](https://root-forum.cern.ch/t/how-to-save-canvas-or-histogram-in-a-tree/50169/1 "2022-05-29T17:14:02Z")

</div>

I am just curious to know if it is possible to save the canvas or histogram in a tree. I mean currently, I am writing the canvas (or histogram) directly in a root file, without creating a tree. Here is the pseudo-code of what I am doing,

```auto
TFile *f1 = new TFile("test.root", "RECREATE");
TCanvas *can = new TCanvas("can", "can", 750, 500);
// Add histogram to the canvas
can -> Write();

```

As you can notice, there is no `TTree` in the code. It would be more organized if I can save this canvas in different branches of a tree.

Please suggest something. Because my analysis involves a lot of plots.

Thanks,  
Divyang.

---

<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:** [May 30, 2022, 6:21am UTC](https://root-forum.cern.ch/t/how-to-save-canvas-or-histogram-in-a-tree/50169/2 "2022-05-30T06:21:00Z")

</div>

Saving a Canvas in a ROOT file is the normal way to proceed. Why do you want to save it in a tree?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [May 31, 2022, 10:42am UTC](https://root-forum.cern.ch/t/how-to-save-canvas-or-histogram-in-a-tree/50169/3 "2022-05-31T10:42:25Z")

</div>

TTree is meant for datasets with many values per branch, if you only fill each branch with one canvas that’s probably not the right structure.

To mimic the organization of TTree and branches you can save different canvases in different sub-directories of a TFile.

Cheers,  
Enrico
