I want to extract the maximum y value for a specific range on x-axis
gr.GetMaximum() always give -1110
gr.GetYaxis().GetXmin() seems to be works only for the whole range of x-axis.
func = TF1("func","*x + ",0,5)
for i in range(10):
# what if i want to find min,max of y-value for x in [3,7] ?
any suggestion ?
ROOT Version: 6.24 & 6.28.06
_Platform:(conda) Centos7 & MacOS ventura
Compiler: Not Provided
thank you for your question on the forum!
Could you please give us a minimal working reproducer of your programme, it is hard to tell what is wrong based on these two lines only.
Hi again @NgJunKai,
thank you for the reproducer.
What you are seeing for
GetMaximum() is expected. It was already discussed in the forum post here: TGraph GetMaximum() GetMinimum().
The suggested solution is to use ROOT::TMath class, which would look like this if I indeed set the range to be between 3 and 7:
func = ROOT.TF1("func","*x + ")
gr = ROOT.TGraph()
for i in range(3,8):
gr.SetPoint(gr.GetN(), i, func.Eval(i))
print(ROOT.TMath.MaxElement(gr.GetN(),gr.GetY())) # gives 15 as expected
print(ROOT.TMath.MinElement(gr.GetN(),gr.GetY())) # gives 7 as expected
You can explore more of the ROOT::TMath class if you need other quantities, ROOT: TMath Namespace Reference and more generally the Math class is documented here ROOT: Math.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.