Np.max(histo_list) strange behaviour

I have a list of histograms which I read in from a TFile:

histo_list=([root_file.Get(f"Histo{ch}") for ch in x_channels])

I then plot them:

canvas= TCanvas("canvas","canvas",1800,1400)
canvas.Divide(4,4)
for i_plot in range(16):
    canvas.cd(i_plot+1)
    x_histo=histo_list[i_plot]
    x_histo.Rebin(200)
    x_histo.Draw()
    x_histo.SetTitle(";;")
    x_histo.GetYaxis().SetRangeUser(-4000,55000)
    #x_histo.Fit("pol0")
    horizontal_zero_line.Draw("same")

If I run this in an interactive python environment and then ask numpy what the maximum value of any of these histograms is

np.max(histo_list)

It gives me a number which I believe is correct.
If I don’t plot it and I ask numpy what the max is, or if I get the np.max() before I plot it, it gives me a completely different (wrong) number.

My first question is therefore, what is it that makes the difference? And is there a quick, simple way of getting the maximum of the maxima of a list of histograms?

Hi,

Thanks for the interesting post.
Could you please define “maximum of a list of histograms”? E.g. what is the metric? Maximum number of entries, maximum bin content, maximum number of bins?

Cheers,
D

Thanks for the response, what I want is one number which is the maximum of the maximima of the bin contents of all the histograms
I suppose it would be equivalent to something like:
np.max([histo.GetMaximum() for histo in histo_list])

Which may already be the answer to my second question I suppose, but it would still be nice to know why doing the same thing before/after plotting the histograms produces different behaviour

Update: GetMaximum() is also giving wrong numbers before the histograms are plotted

My fault! I forgot the rebin(200) in the loop. No wonder I’m getting different answers!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.