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.
Thank you in advance .
HV1150V_P860muW.dat (46.3 KB)
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.
# We manipulate the file
with open("HV1150V_P860muW.dat") as ifile:
lines = ifile.readlines()
ofile = open("HV1150V_P860muW_column.dat","w")
count_counter = 0
for rawline in lines:
line = rawline[:-1]
vals = line.split()
if len(vals) == 1: continue
counts = vals
if count_counter == 0:
# We write it in ROOT format
from ROOT import TFile, TTree
f = TFile("HV1150V_P860muW.root","RECREATE")
t = TTree("HV1150V_P860muW","HV1150V_P860muW")
Are you assuming PyRoot in your answer?