# Getting TGraph from TChain

**URL:** <https://root-forum.cern.ch/t/getting-tgraph-from-tchain/17904>\
**Category:** ROOT\
**Created:** [July 14, 2014, 3:28pm UTC](https://root-forum.cern.ch/t/getting-tgraph-from-tchain/17904 "2014-07-14T15:28:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Demetrio](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@Andrea\_Demetrio](https://root-forum.cern.ch/u/Andrea_Demetrio)\
**Post date:** [July 14, 2014, 3:28pm UTC](https://root-forum.cern.ch/t/getting-tgraph-from-tchain/17904/1 "2014-07-14T15:28:18Z")

</div>

Good evening everyone,  
I’m working with a TChain object and don’t know how to extract the TGraph object drawn.  
I’ll be more specific by pointing it out with a code snippet:

`TCanvas c;
TChain chain("tree","chain");
chain.Add("SomeGenericFile.root");
chain.Draw("x:y","x > 10"); //A TGraph with a scatter plot is generated and drawn on the canvas
`  
Now, if I wanted to get the resulting TGraph object and edit it via code (e.g. set its title or whatever), what should I do?

Both CINT and compiled C++ mode work fine for me.

Thanks in advance,

Andrea Demetrio

---

<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 14, 2014, 3:53pm UTC](https://root-forum.cern.ch/t/getting-tgraph-from-tchain/17904/2 "2014-07-14T15:53:37Z")

</div>

it is in the “htemp” histogram.

you can do:

htemp-\>SetTitle() …

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 14, 2014, 3:54pm UTC](https://root-forum.cern.ch/t/getting-tgraph-from-tchain/17904/3 "2014-07-14T15:54:36Z")

</div>

TGraph \*g = ((TGraph \*)((c.GetPrimitive(“Graph”)).Clone(“MyNewGraph”)));  
TGraph \*g = ((TGraph \*)((c.FindObject(“Graph”)).Clone(“MyNewGraph”)));

---

<div class="post-metadata">

**Author:** ![Andrea\_Demetrio](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@Andrea\_Demetrio](https://root-forum.cern.ch/u/Andrea_Demetrio)\
**Post date:** [July 15, 2014, 7:15am UTC](https://root-forum.cern.ch/t/getting-tgraph-from-tchain/17904/4 "2014-07-15T07:15:01Z")

</div>

Thank the both of you for the answers;)  
Anyways…

[quote=“couet”]it is in the “htemp” histogram.

you can do:

htemp-\>SetTitle() …[/quote]  
This was the first method I’ve tried, but didn’t work properly (the title remained the very same, for some odd reasons) and this is why I’ve posted my request. Now, I’ve tried it again (very same command, without modifications - I’ve double checked it) and it worked. Has ROOT been drunk when I first tried it?!

[quote=“Wile E. Coyote”]TGraph \*g = ((TGraph \*)((c.GetPrimitive(“Graph”)).Clone(“MyNewGraph”)));  
TGraph \*g = ((TGraph \*)((c.FindObject(“Graph”)).Clone(“MyNewGraph”)));[/quote]  
Yes, this was exactly what I was looking for.  
I’ve tested it and it worked well, so my question can be ticked as solved;)

Thanks,

Andrea Demetrio
