Compare commits
2 commits
e35dc88dc8
...
1eb0157ddb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eb0157ddb | ||
|
|
2fccdf4e50 |
2 changed files with 101 additions and 70 deletions
61
bananas.py
61
bananas.py
|
|
@ -2,16 +2,7 @@
|
||||||
|
|
||||||
from seth_classes import *
|
from seth_classes import *
|
||||||
import argparse
|
import argparse
|
||||||
from cycler import cycler
|
|
||||||
import numpy as np
|
|
||||||
import pandas as pd
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
# get colormap
|
|
||||||
cmap=plt.cm.gist_rainbow
|
|
||||||
# build cycler with 5 equally spaced colors from that colormap
|
|
||||||
c = cycler('color', cmap(np.linspace(0,1,24)) )
|
|
||||||
# supply cycler to the rcParam
|
|
||||||
plt.rcParams["axes.prop_cycle"] = c
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog='bananas.py')
|
parser = argparse.ArgumentParser(prog='bananas.py')
|
||||||
parser.add_argument('filepath')
|
parser.add_argument('filepath')
|
||||||
|
|
@ -21,35 +12,27 @@ args = parser.parse_args()
|
||||||
fp = args.filepath
|
fp = args.filepath
|
||||||
v = args.verbose
|
v = args.verbose
|
||||||
|
|
||||||
channel_names = {0:'A2', 1:'A1', 2:'A0', 3:'B2', 4:'B1', 5:'B0', 6:'C2', 7:'C1',
|
|
||||||
8:'C0', 9:'D2', 10:'D1', 11:'D0', 12:'E1', 13:'E2', 14:'F2', 15:'E0',
|
|
||||||
16:'F0', 17:'F1', 18:'G1', 19:'G2', 20:'H2', 21:'G0', 22:'H0', 23:'H1'
|
|
||||||
} # connects shaper (key) to ADC (value)
|
|
||||||
|
|
||||||
|
|
||||||
def make_hist(dataframe):
|
|
||||||
mask_slice0 = dataframe['sl'] == '0'
|
|
||||||
mask_slice1 = dataframe['sl'] == '1'
|
|
||||||
cut_high = dataframe['pha'] <= 60000
|
|
||||||
cut_low = dataframe['pha'] >= -100
|
|
||||||
dataframe = dataframe[cut_high]
|
|
||||||
dataframe = dataframe[cut_low]
|
|
||||||
for ch in range(24):
|
|
||||||
hist = {}
|
|
||||||
print(f"Working on channel {ch}")
|
|
||||||
for index, row in dataframe.iterrows():
|
|
||||||
if row['channel'] == ch:
|
|
||||||
if row['pha'] not in hist.keys():
|
|
||||||
hist.setdefault(row['pha'], 1)
|
|
||||||
else:
|
|
||||||
hist[row['pha']] += 1
|
|
||||||
plt.plot(hist.keys(), hist.values(), 'x', label=f'{ch}')
|
|
||||||
|
|
||||||
plt.yscale("log"); plt.ylabel("Occurence"); plt.xlabel("Energy in arb. units.")
|
|
||||||
plt.grid(); plt.legend()
|
|
||||||
plt.title(f"{fp}")
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
test = ReadSeth(fp, v)
|
test = ReadSeth(fp, v)
|
||||||
|
upper = {}
|
||||||
|
lower = {}
|
||||||
for event in test:
|
for event in test:
|
||||||
print(event)
|
if (not event.upper_td) or (not event.lower_td):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if event.upper_td[0] in upper:
|
||||||
|
upper[event.upper_td[0]] += 1
|
||||||
|
if event.lower_td[0] in lower:
|
||||||
|
lower[event.lower_td[0]] += 1
|
||||||
|
else:
|
||||||
|
lower.setdefault(event.lower_td[0], 1)
|
||||||
|
else:
|
||||||
|
upper.setdefault(event.upper_td[0], 1)
|
||||||
|
if event.lower_td[0] in lower:
|
||||||
|
lower[event.lower_td[0]] += 1
|
||||||
|
else:
|
||||||
|
lower.setdefault(event.lower_td[0], 1)
|
||||||
|
|
||||||
|
plt.bar(upper.keys(), upper.values())
|
||||||
|
plt.xlabel('Detector')
|
||||||
|
plt.ylabel('Counts')
|
||||||
|
plt.show()
|
||||||
|
|
|
||||||
110
seth_classes.py
110
seth_classes.py
|
|
@ -4,21 +4,6 @@ import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
class Banana:
|
|
||||||
|
|
||||||
def read_from_file(self, filepath):
|
|
||||||
d={'clock':[], 'sl':[], 'channel':[], 'dtime':[], 'lost':[], 'a':[], 'b':[], 'phase':[], 'banana':[], 'pha':[]} # slice (sl) is called det in ahepamfile.c
|
|
||||||
keys = list(d.keys())
|
|
||||||
with open(filepath) as file:
|
|
||||||
for line in file:
|
|
||||||
ll = line.split()
|
|
||||||
if ll[0] == 'EDB' and 'nan' not in ll and '-nan' not in ll and 'inf' not in ll and '-inf' not in ll:
|
|
||||||
contents = [float(num) for num in line.split()[1:]]
|
|
||||||
for i in range(10):
|
|
||||||
d[keys[i]].append(contents[i])
|
|
||||||
return pd.DataFrame(d)
|
|
||||||
|
|
||||||
|
|
||||||
class ReadSeth:
|
class ReadSeth:
|
||||||
def __init__(self, filename, verbose = False):
|
def __init__(self, filename, verbose = False):
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
|
@ -33,35 +18,98 @@ class ReadSeth:
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
while not self.complete:
|
while not self.complete:
|
||||||
self.read_more()
|
self.read_more()
|
||||||
if not self.read_more():
|
if self.read_more() == "EOF":
|
||||||
raise StopIteration
|
raise StopIteration # if end of file has been reached, stop iterating
|
||||||
event = SethEvent(self.complete[0])
|
event = SethEvent(self.complete[0])
|
||||||
self.complete[0]=[]
|
self.complete=[]
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
time_old=100
|
time_old=100
|
||||||
|
|
||||||
def read_more(self):
|
def read_more(self):
|
||||||
time_window = 5
|
time_window = 5 # ticks, 1 tick = 2 us
|
||||||
l = self.file.readline()
|
l = self.file.readline()
|
||||||
if not l:
|
if not l: # if line is empty, close file and say end of file reached
|
||||||
self.file.close()
|
self.file.close()
|
||||||
return False
|
return "EOF"
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(l, l[0])
|
print(l, l[0])
|
||||||
if l[0] == 'E':
|
if l[0] == 'E': # works on EDB, EDS, and ED lines
|
||||||
line = [float(num) for num in l.split(r'\s+')[1:]]
|
#print(l)
|
||||||
print(line)
|
line = [float(num) for num in l.split()[1:]] # split contents into floats
|
||||||
if not self.partial or line[0] + time_window <= self.partial[0][0]:
|
#print(line)
|
||||||
self.partial.append(line)
|
if not self.partial or line[0] <= self.partial[0][0] + time_window: # if list is empty or new line is not older than 5 ticks relative to first line in event
|
||||||
self.complete.append(self.partial)
|
self.partial.append(line)
|
||||||
self.partial = []
|
else:
|
||||||
|
self.complete.append(self.partial)
|
||||||
|
self.partial = []
|
||||||
|
self.partial.append(line)
|
||||||
|
|
||||||
|
|
||||||
class SethEvent:
|
class SethEvent:
|
||||||
def __init__(self, event: list):
|
def __init__(self, event: list):
|
||||||
self.event = event
|
diode_dictionary = {# can be found in ahepam/nmahepam_channels.md
|
||||||
|
#dorn_channel:seth_diode
|
||||||
|
16:13,
|
||||||
|
8:16,
|
||||||
|
0:17,
|
||||||
|
17:20,
|
||||||
|
9:7,
|
||||||
|
1:10,
|
||||||
|
18:1,
|
||||||
|
10:4,
|
||||||
|
2:19,
|
||||||
|
19:2,
|
||||||
|
11:'HET',
|
||||||
|
3:'BGO1',
|
||||||
|
12:'BGO2',
|
||||||
|
20:'BGO3',
|
||||||
|
21:8,
|
||||||
|
4:5,
|
||||||
|
5:6,
|
||||||
|
13:3,
|
||||||
|
14:9,
|
||||||
|
22:12,
|
||||||
|
23:11,
|
||||||
|
6:14,
|
||||||
|
7:15,
|
||||||
|
15:18
|
||||||
|
}
|
||||||
|
sl = 1 # for clearer referencing in event line
|
||||||
|
ch = 2
|
||||||
|
self._event = event
|
||||||
|
self.upper_td = ()
|
||||||
|
self.BGOB = [0, 0, 0]
|
||||||
|
self.HETA = 0
|
||||||
|
self.HETB = 0
|
||||||
|
self.BGOD = [0, 0, 0]
|
||||||
|
self.lower_td = ()
|
||||||
|
for detector in event:
|
||||||
|
detector[ch] = int(detector[ch])
|
||||||
|
if detector[sl] == 0: # slice 0
|
||||||
|
if detector[ch] == 11: # dorn channel 11
|
||||||
|
self.HETB = detector[9]
|
||||||
|
if detector[ch] == 3:
|
||||||
|
self.BGOD[0] = detector[9]
|
||||||
|
if detector[ch] == 12:
|
||||||
|
self.BGOD[1] = detector[9]
|
||||||
|
if detector[ch] == 20:
|
||||||
|
self.BGOD[2] = detector[9]
|
||||||
|
if int(detector[ch]) not in [3,11,12,20] and abs(detector[ch]) < 24:
|
||||||
|
self.lower_td = (diode_dictionary[detector[ch]], detector[9]) # tuple of (seth_diode, pha) for seth_diode see Jaspers thesis
|
||||||
|
|
||||||
def __get__(self):
|
else: # slice 1
|
||||||
return self.event
|
if detector[ch] == 11: # dorn channel 11 is
|
||||||
|
self.HETA = detector[9]
|
||||||
|
if detector[ch] == 3:
|
||||||
|
self.BGOB[0] = detector[9]
|
||||||
|
if detector[ch] == 12:
|
||||||
|
self.BGOB[1] = detector[9]
|
||||||
|
if detector[ch] == 20:
|
||||||
|
self.BGOB[2] = detector[9]
|
||||||
|
if detector[ch] not in [3,11,12,20] and abs(detector[ch]) < 24:
|
||||||
|
self.upper_td = (diode_dictionary[detector[ch]], detector[9]) # tuple of (seth_diode, pha) for seth_diode see Jaspers thesis
|
||||||
|
|
||||||
|
def get_event(self):
|
||||||
|
return self._event
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue