Draw command does not work

Dear rooters,

My program creates an array of TGraphError, then point values are set.

I would like to Draw a graph in the array created. But the draw command does not work, while these other commands, such as GetN(), GetPoint(), work properly. t.C (410 Bytes)

Could you please help me to solve this problem.

Thank you,
ROOT Version: 5.34/32
Platform: Windows 7
Compiler: Not Provided

Try this:

	TGraphErrors *gr[24];

and use “->” for the TGraph methods (gr[i]->SetPoint… etc).


indeed, @dastudillo has a good intuition as to what the problem is:
If you declare the TGraphErrors on the stack, they are deleted when the function returns, and will therefore disappear from everything you draw. Look up C++ memory management (stack / heap) if you want to know more.

There are two solutions:

  • Declare them as pointers and use new (so they are still alive after the function returns)
  • Use DrawCopy to only draw copies.

Note also that this is not valid C++ (you cannot assign a pointer to a TGraphErrors object):

  4         TGraphErrors gr[24];
  5         for (int i=0; i<24; i++)  gr[i] = new TGraphErrors();

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.