# Gettin correct values of histograms

what’s wrong?

The code output the same result: 1541 and 1533

These are the correct values when the “bin size” = 1.

But it should be 9718 and 1533.

In this case, the first histogram has the “bin size” bigger than 1 (the second histogram has 1).
Try: `h.GetBinWidth(h.GetMaximumBin())`

It output only 1.0 for all histograms.

And the same place, what do you get from:
`h.GetMaximumBin()`
`h.GetBinCenter(h.GetMaximumBin())`
`h.GetBinWidth(h.GetMaximumBin())`
`h.GetBinContent(h.GetMaximumBin())`

Well, can i get real values of h.GetMaximumBin(), if i use
h = ROOT.TH1D(“h”, “histogram with channel 7”, 100, 0., 0.) ?

You can also get meaningful results when you use:

``````# Br    8 :Channel7  : ch7[size]/s
name = "ch7" # the leaf name
xmin = ROOT.Int_t(tree.GetMinimum(name)) # needs the leaf name here
xmax = ROOT.Int_t(tree.GetMaximum(name)) + 1 # needs the leaf name here
h = ROOT.TH1D("h", name + " histogram", (xmax - xmin), xmin, xmax) # fix bin size = 1
tree.Project("h", name) # can use the branch name or the leaf name here
``````

h.GetMaximum() output 0.0, 0.0

I corrected it (the problem is that your “branch name” != “leaf name”).

``````def ch7_939(y):
c = ROOT.TCanvas()
myfile = ROOT.TFile.Open("/home/erg/2022.12/2022.12.01/"+y)
ROOT.gROOT.cd()
name = "ch7"
xmin = int(tree.GetMinimum(name))
xmax = int(tree.GetMaximum(name)) + 1
h = ROOT.TH1D("h", name + " histogram", (xmax - xmin), xmin, xmax)
tree.Project("h", name)
h.BufferEmpty(1)
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]))

print(chan7_939)
``````

Is it correct? Because i obtain the same result.

``````def ch7_939(y):
myfile = ROOT.TFile.Open("/home/erg/2022.12/2022.12.01/"+y)
ROOT.gROOT.cd() # newly created histograms should go here
name = "ch7"
xmin = int(tree.GetMinimum(name))
xmax = int(tree.GetMaximum(name)) + 1
h = ROOT.TH1D("h", name + " histogram", (xmax - xmin), xmin, xmax)
tree.Project("h", name)
return h.GetMaximum()
``````

Regrettably, that didn’t help either.

I hope you get the correct values 1541 and 1533.

Correct only 1533. The first value should be 9718 according to the original histogram.

I guess it’s time you discuss it with your supervisor.

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