Hi, this is the first time i write on this forum, so i’m sorry if what i’m asking here could sound trivial for someone.
In order to analyze a certain data that was acquired as root file, I need to make histograms of each data set and save the histogram sum in a new branch of the existing file. So i wrote this program using pyroot:
from ROOT import * import sys f = TFile(sys.argv, "UPDATE") tree = f.Get("Data_R") c = TCanvas() tree.GetEntry(1) h = TH1F( "h", "h", tree.Samples.fN, 0, tree.Samples.fN ) #add new branch to tree, connect histogram to this branch #if hist.Maximum > 1750 then write to new branch i=0 for event in tree: for j in range( event.Samples.fN ): h.SetBinContent(j+1, 2**(14) - event.Samples.fArray[j]) if h.GetMaximum() > 1800: branch = tree.Branch( "Data_int", h, 'TH1F') branch.Fill() i += 1 if i % 100 == 0: print(i) if i == 1000: break branch.Write()
I’ve made a stop at 1000 entry just because i’m testing if the program work properly. In order to do so i’ve also wrote a program which should read the information i wrote on the root file and display the final histogram, but all i’ve got is a blank canvas. This is the second program:
from ROOT import * import sys f = TFile.Open( sys.argv, "READ") hData = f.Get("Data_int") entries = hData.GetEntries() print("entries", entries) c = TCanvas() hData = TH1F("hData", "hData", 1, 0, 248) hData.Draw() #print( "Data", hData ) input("Press enter")
My question is: is it wrong the way I store the data in the root file or the way i’m tryin to visualize what i’ve wrote? (or both?)
ROOT Version: 6.26.10
Platform: Not Linux (KDE Plasma)