TH2D from TCanvas

Hi rooters,

I have had some trouble with accessing a histogram from a root file that has a canvas in it. I have followed several recipes found online, but none worked for me. I would ultimately like to get the TH2D and do some processing on it (projections, fits etc).

I attach the file I want to read and my code with the different versions of solutions I’ve tried. Solutions 1 and 3 give me an empty histogram of the correct range in the axes, while 2 and 4 give me a segmentation violation.

I would be grateful of any suggestion on that.

George
CMakeLists.txt (741 Bytes)
Analysis.cc (1.55 KB)
Image___Iteration__0___1.root (91.2 KB)

what is the name of this histogram ?
I can see it, but the name seems screwed up …

It is “Image - Iteration: 0”. You re right, it is a bit odd, I wouldn’t really go for that, but it is written in the file from a third party software which uses ROOT (so not my choice).

George

I can do:

{
   TFile *f = new TFile("Image___Iteration__0___1.root");
//   f->ls();
   TList *l=Image___Iteration__0___1->GetListOfPrimitives();
//   l->ls();
   TH2D *h = (TH2D*)l->FindObject("Image - Iteration: 0");
h->Print();
}

but Draw does not work.

Here we are:

{
   TFile *f = new TFile("Image___Iteration__0___1.root");
   TCanvas *c= (TCanvas *)f->Get("Image___Iteration__0___1");
   TList *l=c->GetListOfPrimitives();
   TH2D *h = (TH2D*)l->FindObject("Image - Iteration: 0");
   TCanvas cc;;
   h->Draw("col")
}

Hi,

thanks for the fast reply. It all works, I tried colz before seeing your last email and I get exactly the histo I get from the file via the TBrowser.

Thanks a lot,
George