I have a program (using ROOT libraries, not a macro) which uses the TGraphErrors class. I initialize an object with data from a file (4 columns, x,y,ex,ey) and draw it. When I do, the errorbars don’t appear, although I know the error values are there because I can print them directly from the object.
This problem doesn’t happen with THist classes (don’t know if it is relevant).
Also, while I have this problem using ROOT 6, a friend of mine compiled it and ran it with ROOT 5 and obtains the graph with errorbars.
Does anyone know if this is common or what could be happening?
Danilo raised an interesting issue (note “DrawClone” instead of “Draw” in the previous post).
You seem to create your graph “on stack” (i.e. without “new”). It is possible that after you add it to your multigraph and before you draw (and print) your multigraph, the original graph gets “out of scope”, so it automatically gets destroyed (but the multigraph still keeps the “invalid” address of it).
I allocate both the TMultiGraph and the TGraphErrors with new, so I think I’m safe on that point. Also, I make modifications to the MultiGraph after drawing it (SetMinimum, SetMaximum) and using DrawClone gives a segmentation violation there.
Well, if DrawClone results in segmentation violation then I would say that there is at least one graph which no longer exists (a TMultiGraph owns graphs which were added, so you must not delete them yourself).
Note also that you could try something like:
TMultiGraph *MyClone = (TMultiGraph *)OriginalMultiGraph->DrawClone(“AP”);
gPad->Modified(); gPad->Update(); // make sure it’s really (re)drawn
MyClone->Set…Whatever…
gPad->Modified(); gPad->Update(); // make sure it’s really (re)drawn
Sorry, I wasn’t very clear. What I meant was that if I use DrawClone the following methods (i.e. SetMinimum) give segmentation violation. Not the DrawClone itself. At least that’s the line at which ROOT points.
I was making a simpler version of my error when and, while simplifying, I no longer had the problem. By trial and error, I found out that this:
gr1->SetLineWidth(0.5);
was the problem.
SetLineWidth accepts an integer as argument and, receiving a float, it simply truncated and used 0 as the width. My colleague with ROOT 5 had the same line of code but, apparently, it was being rounded up. Why the different behaviour, I still don’t know (I took a look at ROOT reference for both versions and the source code defining line width seemed the same…).
Anyway, problem solved. Thank you very much for your help (and time spent)!