# TTree pointer initialization

**URL:** <https://root-forum.cern.ch/t/ttree-pointer-initialization/35042>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [July 7, 2019, 9:52pm UTC](https://root-forum.cern.ch/t/ttree-pointer-initialization/35042 "2019-07-07T21:52:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteliosK](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/steliosk/32/19155_2.png) [@SteliosK](https://root-forum.cern.ch/u/SteliosK)\
**Post date:** [July 7, 2019, 9:52pm UTC](https://root-forum.cern.ch/t/ttree-pointer-initialization/35042/1 "2019-07-07T21:52:57Z")

</div>

I was given a root file WZmc.root with data produced using MadGraph and Delphes. I want to use the MakeClass function but first I need to read the root file. To do so I typed:

> TFile f (“WZmc.root”);  
> TTree\* t;  
> f.GetObject(“t”,t);

But when tried any further step I get null pointer error so I tried to initialize the t TTree pointer by typing:

> TTree \*t = new TTree(“t”,“staff data from ascii file”);

instead of just TTree\* t;  
I dont get error but its not working properly since my t TTree is emply when I Scan() it.  
Please I need some help on how to do this properly.  
P.S. when I was learning about trees I had created some very simple ones which I would read by creating a null TTree pointe (as I tried now at first place) with no errors, so I dont;t know what happed this time.  
Thanks for helping me.  
[WZmc.root](https://root-forum.cern.ch/uploads/short-url/9DB7kjc80VfogPYxESAR0fpiBml.root) (1.9 MB)

---

<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:** [July 8, 2019, 4:43am UTC](https://root-forum.cern.ch/t/ttree-pointer-initialization/35042/2 "2019-07-08T04:43:12Z")

</div>

Hi,  
The tree’s name inside the file is “tree”, not “t”, so you need to do:

```cpp
f.GetObject("tree",t);

```
