I wrote a code that outputs a list of values corresponding to the maxima of histograms for a separate branch for all files from the folder. But I noticed that not all values are correct. As an example, I attach two histograms. For a wide one, the correct value is obtained. For a narrow one, no. How to solve this problem?
def ch7_939(y):
c = ROOT.TCanvas()
myfile = ROOT.TFile.Open("/home/erg/2022.12/2022.12.01/"+y)
tree = myfile.Get("FADCData 939")
h = ROOT.TH1D("h", "histogram with channel 7", 100, 0., 0.)
tree.Draw("Channel7 >> h")
return h.GetMaximum(maxval=100000.0)
second = []
chan7_939 =[]
m = os.listdir("/home/erg/2022.12/2022.12.01")
for i in range(len(m)):
second.append(m[i])
second.sort()
print(second)
for j in range(len(m)):
chan7_939.append(ch7_939(second[j]))
chan7_939.sort()
print(chan7_939)
The problem is that your "h"histogram with automatic bins uses the default “buffer size” of 1000 (and then the automatically computed x-axis limits may be “narrow” when the first 1000 entries are near the maximum).
import ROOT
f = ROOT.TFile("Dec01031235.root")
t = f.Get("FADCData 939")
ROOT.gROOT.cd()
# ROOT.TH1.SetDefaultBufferSize(100000) # either before creating any histogram
h = ROOT.TH1D("h", "histogram with channel 7", 100, 0., 0.)
# h.SetBuffer(100000) # or after creating this histogram
t.Draw("Channel7 >> h")