Hi @etejedor,
Thank you! I was able to extract these values with no problem. However, there is now an issue with writing these values to the tree. Since this is a variable array that needs to be written, I have tried using the following code, which extracts the number of clusters (to be used as the range for the nested for
loop when looping over all of the entries in the tree) and then attempts to pass zeroes to the variable clustADCs
declared in the branch, and then write them to the tree (to see if this produces the expected output of a histogram with ~3 million entries with zero):
file_out = TFile.Open("myfile.root", 'update')
tree = file_out.Get("TCluster")
branch = tree.Branch("clustADCs", clustADCs, 'clustADCs[nclust]/F')
#Extract values in nclust leaf
nclust = []
for entry in tree.nclust:
nclust.append(entry)
index = []
for jj in range(0,199977):
index = nclust[jj]
print(index)
for bb in range(0,index):
clustADCs[0] = 0
branch.Fill()
file_out.Write("", TFile.kOverwrite)
file_out.Close()
There is an issue with the nclust
branch. I have tried many different ways to write this loop, but I can only get it to work using the method at Reading Values using PyROOT. When running the loop to get the value of nclust
, I receive the following error: TypeError: 'int' object is not iterable
. However, if the other method is used and the nclust
values are extracted, I can run the code:
for jj in range(0,199977):
index = nclust[jj]
print(index)
for bb in range(0,int(index)):
clustADCs[0] = 0
branch.Fill()
where nclust
is an array of floats cast to integers using nclust = numpy.array(nclustValues, dtype = int)
. When checking to see if the data were successfully written, a histogram with a mean of ~10^30 is produced which is certainly incorrect. Do you have any ideas or suggestions on how to correct this?
Best regards,
Stephen