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.
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.
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+
I think we have a misunderstanding here. I would like:
the usual statistics information (no. of entries, RMS, mean, …) for the upper histogram
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.
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…
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?
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().