# Saving Histogram in a Tree

**URL:** <https://root-forum.cern.ch/t/saving-histogram-in-a-tree/51038>\
**Category:** Newbie\
**Created:** [August 1, 2022, 8:54pm UTC](https://root-forum.cern.ch/t/saving-histogram-in-a-tree/51038 "2022-08-01T20:54:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheScientist](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@TheScientist](https://root-forum.cern.ch/u/TheScientist)\
**Post date:** [August 1, 2022, 8:54pm UTC](https://root-forum.cern.ch/t/saving-histogram-in-a-tree/51038/1 "2022-08-01T20:54:23Z")

</div>

I am trying to create a root file with a tree and save a generated histogram in there. It is not working. Here is my code. Thank you.

```auto
void TFileCreate()
  4 {
  5 TFile *filename = new TFile("filename.root", "RECREATE");
  6 TTree *treename = new TTree("treename", "treetitle");
  7 
  8 TH1F *histname = new TH1F("histname", "histtitle", 100, 0, 10); 
  9 histname->FillRandom("gaus",1000);
 10 // histname->Draw();
 11 
 12 treename->Get(histname);
 13 treename->Write();
 14 
 15 filename->Close();

```

---

<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:** [August 2, 2022, 8:51am UTC](https://root-forum.cern.ch/t/saving-histogram-in-a-tree/51038/2 "2022-08-02T08:51:33Z")

</div>

Why do you want to save the histogram “in the tree”? why don’t you simply save it in the file “filename.root” ?

---

<div class="post-metadata">

**Author:** ![TheScientist](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@TheScientist](https://root-forum.cern.ch/u/TheScientist)\
**Post date:** [August 2, 2022, 11:05am UTC](https://root-forum.cern.ch/t/saving-histogram-in-a-tree/51038/3 "2022-08-02T11:05:56Z")

</div>

I have 128 plots for each event so I am trying to create a tree for each event and fill it with associated plots. Right now, my root file has this format.  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/a/ca0f28de7d1ea70aa5acfdc68f7833a45724a79c.png)  
e0chn0 - e78chn16 means Event 0, chn 0 to Event 78 chn16  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/9/79d5f0863a62a4308cc5ed790fb18bc894f32377.png)
