Extracting TObjArray from contour plot

Hey ROOT experts,

Following this documentation, I am trying to extract a TObjArray from a contour plot:
root.cern.ch/root/html/THistPainter.html

After trying the line:
TObjArray *conts = gROOT->GetListOfSpecials()->FindObject(“contours”)

my pointer to the TObjArray is null:
conts == NULL

How can I trace this problem? I using version 5.27/06b.

The relevant pieces of my lengthy macro are below.

Many thanks for any suggestions,
Will

TH2D hxsecminusxsec = new TH2D(“hxsecminusxsec”, “hxsecminusxsec”, 18, 100, 1000, 18, 50, 950);

TCanvas
c1 = new TCanvas(“c1”,“c1”,600,600);

Double_t contours[2];
contours[0] = 0.0;
contours[1] = 1e6;
hxsecminusxsec->SetContour(2, contours);

hxsecminusxsec->Draw(“cont2 list”)
c1->Update();
TObjArray conts = (TObjArray)gROOT->GetListOfSpecials()->FindObject(“contours”);

you should use CONT not CONT2 … like in the example in the doc

Hi Couet,

Thank you for your reply. Indeed, if I plot with CONT rather than CONT2, my pointer to the TObjArray is no longer null. I am now finding that my contours have no graphs. I can see a nice contour from my histogram draw command, however.

Do you have any suggestions on what I might be missing? All I am looking for is to be able to redraw my contour on other plots.

Many thanks,
Will

TObjArray conts = (TObjArray)gROOT->GetListOfSpecials()->FindObject(“contours”);
TList* contLevel = NULL;
Int_t nGraphs = 0;

for(i = 0; i < TotalConts; i++){
contLevel = (TList*)conts->At(i);
printf(“Contour %d has %d Graphs\n”, i, contLevel->GetSize());
nGraphs += contLevel->GetSize();
}

Output:
Contour 0 has 0 Graphs
Contour 1 has 0 Graphs

does the macro on the doc works for you ?

Hi Couet,

Thanks again for the reply. It turns out that the problem was that saving my canvas in between updating my canvas and the FindObject line was causing problems.

Anyway, many thanks for all of the help!
Will

hxsecminusxsec->Draw(“cont list”)
c1->Update();

c1->SaveAs(“xsecminusxsec.pdf”,“pdf”); <- Inserting this line was causing problems

TObjArray conts = (TObjArray)gROOT->GetListOfSpecials()->FindObject(“contours”);