Drag & drop with two pads and two statistics boxes

Hi,

I have a canvas with two pads in which I draw two histograms (top: background overlaid with data, bottom: ratio data/background). In the bottom plot, I do a fit as well.

I do something like:

[code]pad1->cd();
gStyle->SetOptStat(1111);
hist1->Draw();

pad2->cd();
gStyle->SetOptStat(0);
gStyle->SetOptFit(1111);
hist2->Fit(“pol0”);[/code]
The canvas appears with the two histograms as intended. But here’s the problem:

When I click on the top histogram and move it by a pixel or so with the mouse, the statistics box of the upper histogram disappears.

Why is this, and how do I solve it?

Thanks,
Peter

Can you post a small running macro showing the problem ?
I cannot reproduce it with the histograms I have.

Hi Couet,

Here’s an example macro. The resulting plots are very ugly, but I’ve tried to remove any code that is purely cosmetic.

The histograms are each drawn several times (for example to draw error bands etc., or get the histogram frame in the foreground after all other drawing is done). I am not sure if that’s important to solve my problem, but I didn’t remove that code just in case it’s relevant.

I am running the code using root -l plotFromTreeTest.C+

Also, this is ROOT 5.34/09.

Thank you for looking into it.

Best,
Peter
plotFromTreeTest.C (1.48 KB)

At the end of your macro replace:

        gStyle->SetOptStat(0);

by:

        hRatio->SetStats(0); 

If I do this, the second statistics box with the fit information is not drawn, so this is not a solution. Do you have any other ideas?

Ah… ok you want both stats … in that case remove that line completely …

Hi Couet,

I think we have a misunderstanding here. I would like:

  1. the usual statistics information (no. of entries, RMS, mean, …) for the upper histogram
  2. only the fit information (and not RMS, mean, …) in the lower histogram

If I

  • change the line as you proposed, I only get the first box
  • remove the line, the second box contains other statistical information as well

… so that’s not what I want. Do you know how I can achieve the above?

Some speculation about the reasons (not sure if it’s of any use):
It seems to me that when the upper graphics are updated (trigged by dragging the frame) when SetOptStat(0) was called before drawing the second histogram, this setting gets applied to the first histogram during the update. Now, since SetOptStat(0) prevents the drawing of the box, the first box now disappears when this graphics update is run.
For some reason, this interaction between histograms only occurs when setting SetOptStat to 0. When using 10 or something like that, the two histograms are independent.

Best,
Peter

Ok, let me explain. When using gStyle it is a global setting you do for all histograms.
If you want to set a particular value for the stats for one histogram (like 111).
You should use SetStats on this histogram, not the global setting.
I thought my examples made it quite clear … sorry if not…

Hi Couet,

I understand, but TH1::SetStats() only takes a boolean argument to turn the statistics box on and off, but it does not allow specifying settings for the statistics box for a particular histogram.

So, do I understand correctly that there is no way to do what I would like to do?

Thanks,
Peter

Do you need to actually do mouse-clicking for the first pad after it is drawn? It won’t update unless you actually click it or do a gPad->Modified();gPad->Update();, letting use the “old” global stat option, while the second pad is drawn with the “new” global stat option.

If you don’t actually need to modify it with the mouse, you can use gPad->SetEditable method to make sure you don’t accidentally click it, but it’ll still update if you draw new stuff or do a gPad->Update().

Jean-François

{
   TH2D *h = new TH2D("h","h",20,-4,4,20,-4,4);
   h->FillRandom("gaus",10000);
  h->Draw("box");
   gPad->Update();
   TPaveStats *ps = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
   ps->SetOptStat(221112211);
   gPad->Modified();
   gPad->Update();
}

No, but the problem also appeared when saving the canvas to a .pdf file.

Couet’s last suggestion solved the problem. Thanks!