Contour Plot / access contours


I’m trying to produce a contour plot and access the contours as TGraph objects. I followed the User Guide, p. 32, and did:

TObjArray *contours = gROOT->GetListOfSpecials()->FindObject(“contours”);
TList list = (TList)contours->At(1);
TGraph gr1 = (TGraph)list->First();

This does not compile - I get:

g++ -O2 -Wall -fPIC -pthread -I/usr/root/include -c -o TEventViewTool.o TEventViewTool.C
TEventViewTool.C: In member function void TEventViewTool::scanEff(double, double, double, double, double)': TEventViewTool.C:1552: error: invalid conversion fromTObject*’ to `TObjArray*'
gmake: *** [TEventViewTool.o] Error 1

So I naively tried instead

TObject *contours = gROOT->GetListOfSpecials()->FindObject(“contours”);
TList list = (TList)contours;
TGraph gr1 = (TGraph)list->First();

This compiles, but when executing I get a segmentation fault because of the line for drawing the TGraph, see below.

Thanks for your help!

*** Break *** segmentation violation
Generating stack trace…
0x41729a81 in TEventViewTool::scanEff(double, double, double, double, double) + 0x16b1 from /usr/athena/testarea/MyEventViewAnalysis/./
0x41717b6a in from /usr/athena/testarea/MyEventViewAnalysis/./
0x40745f2d in G__call_cppfunc + 0x2c6 from /usr/root/lib/
0x40734a18 in G__interpret_func + 0x7ac from /usr/root/lib/
0x407174eb in G__getfunction + 0x13f0 from /usr/root/lib/
0x407b4182 in G__getstructmem + 0x8b4 from /usr/root/lib/
0x407aab90 in G__getvariable + 0x4fe from /usr/root/lib/
0x4070d8e3 in G__getitem + 0x52a from /usr/root/lib/
0x4070c321 in G__getexpr + 0x7c05 from /usr/root/lib/
0x4075f597 in G__exec_function + 0xc7 from /usr/root/lib/
0x40767721 in G__exec_statement + 0x337f from /usr/root/lib/
0x40736240 in G__interpret_func + 0x1fd4 from /usr/root/lib/
0x40717cc7 in G__getfunction + 0x1bcc from /usr/root/lib/
0x4070d913 in G__getitem + 0x55a from /usr/root/lib/
0x4070c321 in G__getexpr + 0x7c05 from /usr/root/lib/
0x4075f597 in G__exec_function + 0xc7 from /usr/root/lib/
0x40767721 in G__exec_statement + 0x337f from /usr/root/lib/
0x406f35c7 in G__exec_tempfile_core + 0x2f9 from /usr/root/lib/
0x406f379e in G__exec_tempfile_fp + 0x22 from /usr/root/lib/
0x40770510 in G__process_cmd + 0x4dd4 from /usr/root/lib/
0x401b1971 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0xaf from /usr/root/lib/
0x400fe5ff in TApplication::ProcessLine(char const*, bool, int*) + 0x699 from /usr/root/lib/
0x40d6b408 in TControlBarButton::Action() + 0x38 from /usr/root/lib/
0x41323be0 in TRootControlBar::ProcessMessage(long, long, long) + 0x22 from /usr/root/lib/
0x41296c9a in TGFrame::HandleClientMessage(Event_t*) + 0x36 from /usr/root/lib/
0x4129a22c in TGMainFrame::HandleClientMessage(Event_t*) + 0x22 from /usr/root/lib/
0x412969d4 in TGFrame::HandleEvent(Event_t*) + 0x2ec from /usr/root/lib/
0x4126ec44 in TGClient::HandleEvent(Event_t*) + 0xfe from /usr/root/lib/
0x4126e876 in TGClient::ProcessOneEvent() + 0x74 from /usr/root/lib/
0x4126e995 in TGClient::HandleInput() + 0x2d from /usr/root/lib/
0x4126d02e in TGInputHandler::Notify() + 0x1e from /usr/root/lib/
0x4025b299 in TUnixSystem::DispatchOneEvent(bool) + 0x6b from /usr/root/lib/
0x4016b98a in TSystem::InnerLoop() + 0x18 from /usr/root/lib/
0x4016b92a in TSystem::Run() + 0x7a from /usr/root/lib/
0x400fee34 in TApplication::Run(bool) + 0x32 from /usr/root/lib/
0x410fece0 in TRint::Run(bool) + 0x3d4 from /usr/root/lib/
0x08048d77 in main + 0x67 from /usr/root/bin/root.exe
0x00545e23 in __libc_start_main + 0xd3 from /lib/tls/
0x08048c89 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x31 from /usr/root/bin/root.exe
Root > Function scanEff() busy flag cleared

The line

TObjArray *contours = gROOT->GetListOfSpecials()->FindObject("contours"); should be

TObjArray *contours = (TObjArray)gROOT->GetListOfSpecials()->FindObject("contours");

Hi Rene,

Thanks for your quick reply!

did not work, so I tried

This compiles, but I get the same segmentation fault as before for the line

or alternatively, for

Btw… the contour plot is drawn and there are definitely some contour lines, the list should therefore have some entries…

Can you send me a small running macro reproducing your problem ?

Here you go:

File cont.c

void cont()

  h_cont = new TH2D("h_cont","test", 10, 0, 10, 10, 0, 10);

  for (int i=0; i<10; i++){
    for (int j=0; j<10; j++){
  TCanvas *c1 = new TCanvas("c1","ctest");

  TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
  TList *list = (TList*)contours->At(0);

  TGraph *gr1 = (TGraph*)list->First();



Processing cont.c…
Error: illegal pointer to class object contours 0x0 34 FILE:cont.c LINE:23
*** Interpreter error recovered ***

If you remove TList… and all the following lines, then

  cout << contours->GetSize() << endl;

returns the proper value - 20.


You should do:


to have the contour list available.

Thanks a lot… that does the job!
Now I just have to figure out why the graph disappears as soon as I try to resize the canvas window and then I’ll be happy :wink:

  TGraph *gr1 = (TGraph*)list->First();
  gc = (TGraph*)gr1->Clone();