How to plot Graph from root file

I want to access the graph from the root file to then get the maximum value on the Y axis. After digging in the forum, I managed to write this code. What should be added or removed here?

c = ROOT.TCanvas()
myfile = ROOT.TFile.Open(“/home/erg/2022.12/2022.12.01/Dec01031235.root”)
tree = myfile.Get(“FADCData 939”)
g = ROOT.TGraph()
g = g.gPad.GetPrimitive(“Graph”)
print(ROOT.TMath.MaxElement(10230, g.GetY()))

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided




produces a histogram, not a TGraph.

I tried something new. But it gives an empty canvas.

c = ROOT.TCanvas()
f = ROOT.TFile(“/home/erg/2022.12/2022.12.01/Dec01031235.root”)
tree = f.Get(“FADCData 939”)
g = ROOT.TGraph()
g = tree.GetBranch(“Channel1”)

Let’s simplify a bit. Why do you need a TGraph? Why does not a TH1 suffice?

I used to think I was working with histograms too. I even made a code that allows you to get their maximums. But some of the values were different from the true ones. Recently I realized that I am dealing with graphs with time on the X axis. However, tree.Draw() produces the same images as when calling rootbrowse. Now I need to write a program that will output all the correct values of the maxima. I attach a file here.
Dec01031235.root (120.3 KB)

Then it is something like this:

c = ROOT.TCanvas()
f = ROOT.TFile("Dec01031235.root")
tree = f.Get("FADCData 939")
myh = ROOT.gPad.GetPrimitive("htemp");
print "Maximum of the histogram is", myh.GetMaximum()

1 Like

Thank you very much, sir! You’ve helped me a lot! Now you can save a lot of time when processing files.

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