
import tables
import sys

my_file=tables.open_file(sys.argv[1])
import pylab
import numpy as np

pylab.figure()
ctime = my_file.root.FlasherShiftedPulses.cols.time[:]
charge = my_file.root.FlasherShiftedPulses.cols.charge[:]
rstr = my_file.root.FlasherShiftedPulses.cols.string[:]
rdom = my_file.root.FlasherShiftedPulses.cols.om[:]
cut = (charge[:]>0)&(rstr[:]==73)&(rdom[:]==23) #you can adapt this to whatever receiver you want
#flasherinfo =  my_file.root.FlasherInfo.cols.om[:]
flasherinfo =  rdom
#print len(flasherinfo)

# this normalizes the charge to the number of flashers, so you can compare data to simulation
# or compare different runs
weightvec = [i/float(len(flasherinfo)) for i in charge[cut]]

# this saves the histogram contents as an array which you can then use to make calculations
# such as total charge, etc.
h,edges = np.histogram(ctime[cut],weights=weightvec,bins=100,range=[0,1000])

pylab.hist(ctime[cut],weights=charge[cut],bins=100,range=[0,1000],alpha=0.5,color='red')

pylab.xlim(0,1000)
pylab.xlabel('time (ns)')
pylab.show()
#pylab.savefig(sys.argv[3])
