-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaler_mon.py
126 lines (102 loc) · 3.31 KB
/
scaler_mon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
from iceboot.iceboot_session import getParser, startIcebootSession
import os
import sys
import numpy as np
import scope
import tables
import time
import datetime
from addparser_iceboot import AddParser
import matplotlib.pyplot as plt
from mkplot import plotSetting
from pulserCalib import getThreshold, getData
from tqdm import tqdm
def main(parser):
(options, args) = parser.parse_args()
snum = options.mbsnum
if len(snum.split('/')) > 1:
print('Do not use "/" in the MB serial number. Exit.')
sys.exit(0)
date = datetime.date.today()
index = 1
prepath = f'results/ScalerMon/{snum}/{date}/Run'
path = prepath + str(index)
while os.path.isdir(path):
index = index + 1
path = prepath + str(index)
print(f'=== File path is: {path}. ===')
os.system(f'mkdir -p {path}')
doScaler(parser, path)
def doScaler(parser, path='.'):
(options, args) = parser.parse_args()
snum = options.mbsnum
if options.filename is None:
print ('Requires option: --filename.')
print ('Quit.')
return
datapath = f'{path}/raw'
os.system(f'mkdir -p {datapath}')
channel = int(options.channel)
if channel < 0 or channel > 1:
return
baseline = 0
threshold = 0
baselineset = 30000
if len(options.dacSettings)==2:
print(options.dacSettings)
dacSet = options.dacSettings[0]
baselineset = int(dacSet[1])
if options.threshold is None:
baseline = getThreshold(parser, channel, baselineset, 0, path)
print(f'Observed baseline: {baseline}')
if options.bsthres is not None:
if baseline - int(baseline) > 0.5:
baseline = int(baseline) + 1
else:
baseline = int(baseline)
threshold = int(baseline) + int(options.bsthres)
else:
threshold = int(baseline + 14)
else :
threshold = int(options.threshold)
print(f'Set threshold: {threshold}')
with open(f'{datapath}/memo','w') as f:
f.write(f'Set threshold: {threshold}')
durationUS = 100000
counts = []
session = startIcebootSession(parser)
setchannel = 'A'
if channel == 1:
setchannel = 'B'
session.setDAC(setchannel,baselineset)
session.setDEggTriggerConditions(channel, threshold)
session.enableDEggTrigger(channel)
session.enableScalers(channel,durationUS,24)
time.sleep(5)
for i in tqdm(range(int(options.nevents))):
try:
scaler_count = session.getScalerCount(channel)
except:
tqdm.write(f'{i}: getScalerCount failed.')
counts.append(-1)
time.sleep(2)
continue
if int(scaler_count) > 30:
tqdm.write(f'Iteration {i}: {scaler_count/durationUS*1e6} Hz')
counts.append(int(scaler_count))
time.sleep(durationUS/1e6)
npcounts = np.array(counts)
np.save(f'{datapath}/{options.filename}',npcounts)
fig = plt.figure()
plt.xlabel('Measurement ID')
plt.ylabel('Rate [Hz]')
xdata = np.arange(len(npcounts))
plt.plot(xdata,npcounts/durationUS*1e6,marker='o',ls='')
plt.savefig(f'{path}/nr_fig_{channel}.pdf')
plt.show()
return
if __name__ == "__main__":
parser = getParser()
scope.AddParser(parser)
main(parser)