Get a graph pointer using GetPrimitive from a TCanvas

I am a TCanvas saved to a root file (see attachment). On the canvas, there are couples of TGraphErrors objects. I want to get those graphs using:


It returns a null pointer. I try to dump the graph info (see below). It looks a normal graph. I am curious why I cannot get the graph?

sum_spec.root (28.6 KB)

{ TFile *f = TFile::Open("sum_spec.root"); f->ls(); TCanvas *c; f->GetObject("sum_spec", c); c->ls(); TMultiGraph *mg = ((TMultiGraph *)(c->FindObject("mg"))); mg->GetListOfGraphs()->ls(); TGraphErrors *g = ((TGraphErrors *)(mg->GetListOfGraphs()->FindObject("gTally14"))); TCanvas *c_gTally14 = new TCanvas("c_gTally14", "c_gTally14"); g->Draw("ALP"); }

Yeah, thanks.

I realized that the graphs are put together to a TMultiGraph and the MG is plotted on the canvas.