TH1::Draw() or TH1::DrawCopy()?

Dear ROOT friends,

I have a rather peculiar problem: in my application (a GUI), I am drawing a histogram at some point, by using the TH1::Draw() method. Now recently I realized that ROOT crashes inside the Draw() method in certain situations. After some debugging and forum searching, I simply gave DrawCopy() a try and this indeed solved my problem. I was happy for a short while, but then realized that now in certain other situations the applications crashes in DrawCopy() (where it works perfectly fine with Draw()). (I also tried DrawClone() but that gave completely strange results.) So my questions are:

  1. What are the general rules for using Draw() versus DrawCopy()?

  2. Is there a way to “ask” the histogram whether it wants to be drawn with Draw() or with DrawCopy()? Any property that would give me a hint which one I should use?

Unfortunately, I cannot easily isolate the problem in macro. I could post the full application if necessary.

Many thanks in advance,

Thomas

I just realized that when I clone the histogram manually, I get the expected behavior in all cases (so far…). In other words, if I replace (TString drawOpt defined earlier)

histo->Draw(drawOpt);

or

histo->DrawCopy(drawOpt);

(which each work in some cases, but not in others) by

TH1D* cloneHisto = (TH1D*)histo->Clone();
cloneHisto->Draw(drawOpt);

the drawing works for all cases. So there are three possibilities!(?)

So, essentially I am happy for now, but still very puzzled… It just doesn’t make much sense to me.

Thomas

1 Like