in my PyROOT script, I have a function to compute a median for each x-bin of a 2d histogram and fill the result into its own histogram. The 2d histograms are the result of a i[/i] t.Draw().
Now I would like to superimpose several of these “median curves”. For each, I
t.Draw() with option “goff”
i[/i] hist2d = GetHistogram(), store the result
convert the histogram to my median curve i[/i] hist_medians = medians(hist2d)
The second t.Draw() uses the y axis range as defined by the first hist_medians.Draw(). Because the range of this curve is rather limited, the second t.Draw() can have many entries in the y-underflow or overflow bins. Depending on how many entries then lie in these y-under-/overflow bins, this means that the second hist_medians.Draw() can be very wrong! (In the extreme case simply clipping the curve at the edge of the window, i.e. the range associated with the first curve.)
How do I fix this?
All the best,
is hist_medians only a pointer to hist2d or is it a copy of hist2d ?
No, it’s its own object. The “2d-to-1d converter” looks like this:
# To get X-axis range & labels, start out with ProjectionX
# For each X bin in the original hist
for i in range(1,hist.GetNbinsX()+1):
# Project to Y within that X bin, store in histogram hpy with appropriate title
# Calculate the median from this temporary hpy
# Set the median as the value for the corresponding X bin in the curve histogram
# Return this histogram
And I have a dictionary where I store
- explicitly creating new histograms TH2D(“name”,“title”,nbinsx,…)
- and using Draw("…>>name")
instead of going
and now all of the 1D histograms turn out fine.
The problem now seems to be that they still show up as lines being clipped to the lower edge of the Y axis range, as this range isn’t adjusted when you add another histogram with Draw(“same”).
TTree::Draw is really weird (to me) when making 2D plots. Apparently depending on whether you use “>>” to name the thing something other than the default name, it either makes a TGraph object or a TH2 object.
This thread has me being confused about it, and a few experts giving cryptic/1-line comments: TGraph saved to file shows up as TH2F