I’m having quite a hard time trying to draw several objects on the same TPad. These objects are a THStack collection, a TH1D object and another TH1D…
I want to draw the THStack at the bottom of the graphics order, followed by one of the TH1D objects, and then the other. The final TH1D object is drawn with errorbars (“E”), this represents my data, and the other TH1D is simply a sum of all the objects in my THStack. (Total MC.)
I am aware that I cannot use anything to do with THStack->GetX/Yaxis() before drawing as the axis do not exist for THStack until they are drawn. (I don’t fully understand this.)
For example I can do
TH1D->GetYaxis()->SetRangeUser(...)
but not
THStack->GetYaxis()->SetRangeUser(...)
until THStack->Draw() is called.
Additionally, I don’t understand the difference between SetRangeUser() and SetMaximum() or SetMinimum(). Which of these should I be using as a drawing option to set the axis range on a plot? Or does it not matter and they do the same thing?
So my problem is this: I do not know how to set the axis limits of the THStack before drawing the other objects.
I tried drawing the “total MC” first using the drawing option “axis”, however my code then crashed later on. (I haven’t figured out why yet. The crash happens when I call TCanvas->SaveAs() I believe. Not 100% sure aboutt this yet.)
Any help/advice would be appreciated.
So to summarize, I want to
draw THStack
draw TH1D with option “hist”
draw TH1D with option “E”
do this such that my axis range is fixed between (for example) 0 and 1000
For your interest, this is what happens when it crashes… I really don’t know how to diagnose this further to help the developers fix the issue if there really is one, and it isn’t just caused by me doing something weird.
I can’t really provide you with a MWE, because this macro is about 2k lines long. I would have to ship you some data as well which would be inconvenient.
I might be able to create a MWE if you give me something to start from.
Are there any examples which do something like the following
Create data (several TH1D)
Create sum of data in new TH1D (Total)
Create another copy of this in new TH1D (Total2)
Add data in THStack
Plot with 3 TPad
Top pad: THStack, Total (“hist”) and Total2 (“E”)
Middle pad: Ratio plot
Bottom pad: Pull plot
Pull = Total2 - Total / sqrt(Total)
Ratio will be entirely 1 in this case, but will have non zero error bar length.
Pull will be entirely 0 in this case, and the errors are not drawn (set them to zero)
To avoid problems with 0 / 0 in lower TPad, manually set axis range to be -0.5, 0.5. (Hence question)
If I have more time, I will provide you with some code example if I am able to create such a thing and reproduce the issue. However I am extremely pushed for time at the moment so this will not be easy for me to do. Sorry about that.