I am needing to overlay several histograms in several different ROOT files. I am trying to accomplish this in pyROOT. I am first trying just to import a histogram from an existing ROOT file and saving it as a png image. I can’t even seem to get this far. The png saves as just a blank image according to the pixel dimensions I specified. For reference, here is my Python code:
import ROOT
def overlay_test():
file1 = ROOT.TFile.Open("Baylor/root/local_runs/1050_2023_HB3_ped.root")
canvas = file1.Get("HB3Charge/HB3/HB3-2-Charge")
if not canvas:
print("Failed to retrieve TCanvas.")
return
# Check the type of the retrieved object
if not isinstance(canvas, ROOT.TCanvas):
print("The object retrieved is not a TCanvas.")
return
new_canvas = ROOT.TCanvas("TEST", "imported canvas", 1196, 772)
canvas.Draw()
new_canvas.Update()
new_canvas.SaveAs("testCanvas.png")
file1.Close()
overlay_test()
Very simple, it would seem. But it only produces a blank image. Below is an image from the ROOT browser indicating the file hierarchy of the root file I am trying to import from.
I am also including a screenshot of the canvas I am trying to import. The ultimate goal is to overlay the corresponding histograms from several canvases like the one uploaded here. So, I also want to ask, what is the best way for accomplishing that? Is it possible to be able to import many canvases like this one and somehow overlay them via pyROOT? Or do I need to do it another way? Thank you in advance for any help!
–Ben
_ROOT Version: 6.30/04
Platform: MacOS 13.6
Compiler: Not Provided