# Reading hist from a TTree

**URL:** <https://root-forum.cern.ch/t/reading-hist-from-a-ttree/46038>\
**Category:** Newbie\
**Created:** [July 28, 2021, 2:56am UTC](https://root-forum.cern.ch/t/reading-hist-from-a-ttree/46038 "2021-07-28T02:56:00Z")\
**Posts on this page:** 4\
**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:** [July 28, 2021, 2:56am UTC](https://root-forum.cern.ch/t/reading-hist-from-a-ttree/46038/1 "2021-07-28T02:56:00Z")

</div>

I have a root file named “filename.root” with the tree named “treename”. There is a histogram named “histname” in this tree. I am trying to read this histogram but nothing is showing up. Please let me know my error. Here’s my code.

```auto
void TFileRead()
{
        TFile *filename = new TFile("filename.root", "READ"); //READ
        TTree *treename = (TTree*)filename->Get("treename");

// TH1F* histname = (TH1F*)treename->GetHistogram("histname");

        treename->Draw("histname");
        treename->GetHistogram();
}

```

---

<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:** [July 28, 2021, 6:45am UTC](https://root-forum.cern.ch/t/reading-hist-from-a-ttree/46038/2 "2021-07-28T06:45:33Z")

</div>

Can you give more details ? Which error message do you get ? May be post the file `filename.root` here ?

---

<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:** [July 28, 2021, 7:44pm UTC](https://root-forum.cern.ch/t/reading-hist-from-a-ttree/46038/3 "2021-07-28T19:44:08Z")

</div>

Hi Couet, here are the all the files. Thank you.

[filename.root](https://root-forum.cern.ch/uploads/short-url/pCL3jxXkspa73R6ad1jWhSxprfK.root) (6.7 KB)  
[TFileCreate.C](https://root-forum.cern.ch/uploads/short-url/t9Z9GYCZoAW6tCl0amdfazesbha.C) (469 Bytes)  
[TFileRead.C](https://root-forum.cern.ch/uploads/short-url/aDiX2f1sESPPmIjyyTjRB5iK1uo.C) (306 Bytes)

---

<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:** [July 29, 2021, 6:25am UTC](https://root-forum.cern.ch/t/reading-hist-from-a-ttree/46038/4 "2021-07-29T06:25:08Z")

</div>

`histname` is not in the tree. It seats in the root file. Simply do:

```auto
% root filename.root 
   ------------------------------------------------------------------
  | Welcome to ROOT 6.25/01 https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Jul 05 2021, 04:58:33 |
  | From heads/master@v6-25-01-1526-g96258cd49b |
  | With Apple clang version 12.0.5 (clang-1205.0.22.11) |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

root [0] 
Attaching file filename.root as _file0...
(TFile *) 0x7fb08e33a170
root [1] _file0->ls()
TFile** filename.root	
 TFile* filename.root	
  KEY: TTree	treename;1	treetitle
  KEY: TH1F	histname;1	histtitle
root [2] histname->Draw()

```
