Question about Draw->("box") of TH2

Hi ROOTers,

I have a question as to Draw->(“box”) of a TH2D. Maybe I’m missing something obvious-
I’m running ROOT 5.22.00 on a Scientific Linux OS.
I narrowed down the problem to a piece of code which is attached to this post.

it comes down to the following: I fill one bin of a 3x3bin TH2D and then try to Draw the TH2D. Depending on which order of magnitude (absolute) the bin limits of the x-axis are, the filled bin is drawn or not. I thought such a dependence is not reasonable.

The single filled bin is not drawn if the x-axis binlimits are smaller than 1.0 . Another condition for the bin not to show up is that it has to be one ‘involving the first x-bin’- the filled bin is not drawn for all y-bins which have their x-coordinate in the first x-bin.

If I draw the same histogram with Draw->(“col”), the bin would always be drawn.

Attached are gifs of two 2x2 canvases which are produced by the attached code, to illustrate the above oddities-

The file ‘th2ddrawtest_c1drawbox.gif’ shows the above described problem with Draw(“box”). The single rows of pads sort of belong together-
The top left pad has an array of x bin limits smaller than one. I fill the (x,y) bin (1,2), and this is reflected in the statistics box of the TH2D, but Draw(“box”) doesn’t produce the colored bin where it should show up.
The top right pad shows the same histogram, only that now the (x,y) bin (2,2) is filled. The bin is properly drawn by Draw(“box”).
The bottom left pad shows the same histogram as in the top left plot, only now with the x axis bin limits scaled up by a factor of 1000. The bin (1,2) is filled, and also properly drawn by Draw(“box”).
The bottom right pad, in analogy to the above, shows a histogram with the bin (2,2) filled, and the histogram its properly drawn by Draw(“box”).

The file ‘th2ddrawtest_c1drawcol.gif’ shows the very same thing as the above, only now everything is drawn with Draw(“col”). All filled bins are drawn correctly.

In the application I want to use the whole thing for, I noticed that for Draw(“box”) of TH2D, the first bin column never got filled, and my x-axis bin limits have values smaller than 1.0 . What I want to do is I want to plot the value of flags on a bin grid, where I can assign defined colors to the different values. So for each value of that flag, I fill a TH2D with those bins which have that flag value, and I set a specific fill color. Then I Draw(“box same”) all histograms on top of each other to get the eventual plot. I could draw the whole thing with Draw(“col”), but then I would not be able to assign one specific color to a specific flag value.

Any comments are highly appreciated.

Thanks very much,


th2dtest.C (1.59 KB)

I’ll check

I see that the box option doesn’t display anything in the following example whereas the other options do. I am investigating … that’s weird

  TCanvas *c1 = new TCanvas();

  double yarr[] = { 1.0, 2.0, 3.0, 4.0 };

  double xarrsmallerthanone[] = { 0.01, 0.02, 0.03, 0.04 };

  TH2D *h = new TH2D("h","h",3,xarrsmallerthanone,3,yarr);


  c1->cd(1); h->Draw("box");
  c1->cd(2); h->Draw("surf");
  c1->cd(3); h->Draw("col");
  c1->cd(4); h->Draw("lego");

This bug is now fixed in the SVN trunk. Thanks for reporting it.

Thanks very much for the quick checking. :slight_smile: