How to get the content of a TPad/TCanvas

Hello, if I run the cc.C subroutine, I get a TCanvas with two TPads where there is inside of each of them a TH2D.
I would like to get the TH2D without knowing its name a priori.
To do that, I use a piece of code like that

TCanvas *c = NULL; TH2D *hh = NULL; vector <TCanvas*> canvasV; vector <TH2D*> histoV; for(int i=0 ; i<gROOT->GetListOfCanvases()->GetSize() ; i++) { TObject *obj = gROOT->GetListOfCanvases()->At(i); if ( obj->IsA()->InheritsFrom( TCanvas::Class() ) ) { c = (TCanvas*)obj; canvasV.push_back(c); } } c = canvasV[0]; // it is just to give an idea for(int i=0 ; i<c->GetListOfPrimitives()->GetSize() ; i++) { TObject *obj = c->GetListOfPrimitives()->At(i); if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) { hh = (TH2D*)obj; histoV.push_back(hh); } }
The code above is not perfect but gives an idea of what I do.
The problem is that if you do

.x cc.C gROOT->GetListOfCanvases()->At(0)->GetListOfPrimitives()->At(0)->Print()
You will get a TPad and I do not succed to get the content of what is inside of the TPad. Do you have any idea?

PS: sorry if my problem is not very clear. I will try to reexplain better if so.
cc.C (317 KB)

gROOT->GetListOfCanvases()->ls() gROOT->GetListOfCanvases()->At(0)->ls() ((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->ls() ((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->ls() ((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)->ls() ((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->ls() ((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->GetListOfPrimitives()->ls() ((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->GetListOfPrimitives()->Print() ((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->GetListOfPrimitives()->At(1)->ls() ((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->GetListOfPrimitives()->At(1)->Print() ((TH2D*)(((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->GetListOfPrimitives()->At(1)))->ls() ((TH2D*)(((TPad*)(((TCanvas*)(gROOT->GetListOfCanvases()->At(0)))->GetListOfPrimitives()->At(0)))->GetListOfPrimitives()->At(1)))->Print()

Thank you Wile. I did not use the cast step. That is why it did not work here before. :confused: