Source code for tesfdmtools.utils.reventlist
#!/usr/bin/env python3
#
'''
.. module:: spectrumfit
:synopsis: fit the Holzer alpha and beta Mn54 lines to the spectrum
.. moduleauthor:: Cor de Vries <c.p.de.vries@sron.nl>
'''
import numpy
[docs]def reventlist(ifile):
'''
Read eventlist file (contains index, optimal filters fits, baseline and pulse-peak,
and optionally rise and fall times ).
Eventlist files can be produced by 'HDF_Eventpar'
Args:
* `ifile` = name of eventlist file
Returns:
* `recn` = list of record numbers of clean events in HDF5 file
* `ofit` = list of optimal filter fits for events
* `base` = list of baseline levels for events
* `peak` = list of peak values for the event pulses
* `hdf` = tuple containing parameters of the HDF file:
* `hdf[0]` = full name of HDF5 file from which this eventlist is taken
* `hdf[1]` = channel number from which the eventlist is taken
* `hdf[2]` = frequency (pixel) number from wich the eventlist is taken
* `rtimes` = rise times when present, otherwise **None**
* `ftimes` = fall times when present, otherwise **None**
* `energies` = fitted energies of the events when present, otherwise **None**
'''
bn=500000
ofit=numpy.zeros(bn,dtype=float)
base=numpy.zeros(bn,dtype=float)
recn=numpy.zeros(bn,dtype=int)
peak=numpy.zeros(bn,dtype=int)
rtimes=None
ftimes=None
energies=None
hdf=None
channel=None
pixel=None
inf=open(ifile,'r')
i=0
tt=False
ee=False
crise=4
cfall=5
for ll in inf.readlines():
l1=ll.strip(' \n')
if l1[0] == '#':
if l1.find('inputfile:') > 0:
hdf=l1.split(':')[1].strip(' ')
elif l1.find('channel:') > 0:
channel=int(l1.split(':')[1].strip(' '))
elif l1.find('pixel:') > 0:
pixel=int(l1.split(':')[1].strip(' '))
elif l1.find('opt.fit') > 0:
colnames=ll.split()
for j,cn in enumerate(colnames):
if cn == 'risetime' :
tt=True
rtimes=numpy.zeros(bn,dtype=float)
ftimes=numpy.zeros(bn,dtype=float)
crise=j
cfall=(j+1)
if cn == 'energy(eV)' :
energies=numpy.zeros(bn,dtype=float)
cenergy=j
ee=True
else:
its=l1.split()
recn[i]=int(its[0])
ofit[i]=float(its[1])
base[i]=float(its[2])
peak[i]=int(its[3])
if tt:
rtimes[i]=float(its[crise])
ftimes[i]=float(its[cfall])
if ee:
energies[i]=float(its[cenergy])
i=i+1
inf.close()
if tt:
rtimes=rtimes[0:i]
ftimes=ftimes[0:i]
if ee:
energies=energies[0:i]
return (recn[0:i],ofit[0:i],base[0:i],peak[0:i],(hdf,channel,pixel),rtimes,ftimes,energies)