I need help with this problem , I need to create a Ttree to read the columns of my Text file. My first column represents the events are taking place every 3 lines. In the second column have events in channel zero ( o) and channel 1 ( 1 ) .
My problem is being create a Ttree read the lines so you can decrease the channel 1 channel 0 and this result ride my graph . Always checking if there is data in the respective channels , and at the end plot 2 graphs . 1 with the data and another stating the number of events that did not have the two channels.
Can anybody help me? Explaining how do I read the lines of the text file to be able to mount these graphics.
you can run this script* to transform your input file in a ROOT file containing a TTree with two branches, one for each one of your channels.
As a side product, you’ll also have a txt file organised in columns. Ideally that is the output format of your apparatus if possible.
Cheers,
D
# We manipulate the file
with open("HV1150V_P860muW.dat") as ifile:
lines = ifile.readlines()
ofile = open("HV1150V_P860muW_column.dat","w")
ofile.write("channel0/L:channel1/L\n")
count_counter = 0
for rawline in lines:
line = rawline[:-1]
vals = line.split()
if len(vals) == 1: continue
counts = vals[1]
ofile.write(counts)
if count_counter == 0:
count_counter+=1
ofile.write(" ")
else:
count_counter=0
ofile.write("\n")
ofile.close()
# We write it in ROOT format
from ROOT import TFile, TTree
f = TFile("HV1150V_P860muW.root","RECREATE")
t = TTree("HV1150V_P860muW","HV1150V_P860muW")
t.ReadFile("HV1150V_P860muW_column.dat")
t.Write()
f.Close()