Getting TGraph from TChain

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

it is in the “htemp” histogram.

you can do:

htemp->SetTitle() …

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

Thank the both of you for the answers;)

[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;)


Andrea Demetrio