I have created this function in pyroot turn my raw data into a ROOT Tree. ChanNames is a list with all the channels available in my detector. I dont know why but I am only saving the real data from the first event in the first channel. In the rest, the branches for each channel are filled with zeros or with a constant value. Not the real data. I don’t what could be wrong
def create_tree(filepath, chanNames, det,nevents):
myreader = rawio.RawDataReader(filepath)
events = myreader.read_events(output_format = 2,
skip_empty = True,
nb_events = nevents,
#dump_nums=[1,2,3,4,5,6,7,8,9,10],
trigger_types = [1],
detector_nums = [det],
channel_names = chanNames)
sampling_interval = 1./625.
t = TTree('content_events', '')
baseline = {}
std_bl = {}
bcontent={}
for chan in chanNames:
# Defining the TTree branches using python arrays of length = 1
bcontent[chan]=array('f', [0.0])
baseline[chan] = array('f', [0.0])
std_bl[chan] = array('f', [0.0])
t.Branch('bcontent_'+chan, bcontent[chan],'bcontent_'+chan+'\F')
print('Start!')
print('')
for id in range(len(events)):
if id%1000 == 0 and id > 0:
print('Event', id)
traces = events[id]['Z'+str(det)]
for chan in chanNames:
# Filling the "baseline" and "std_bl" lists
bl = []
time = np.arange(0, len(traces[chan])*sampling_interval, sampling_interval)
i=0
bcontent[chan][0]=0
while time[i] <= 23:
i+=1
bl.append(traces[chan][i])
baseline[chan][0] = float(np.mean(bl))
std_bl[chan][0] = float(np.std(bl))
#print(chan+' baseline= ', baseline[chan][0])
for j in range(len(time)):
bcontent[chan][0]=float(traces[chan][j]-baseline[chan][0])
t.Fill()
f = TFile('content_events.root', 'recreate')
t.Write()
return f