-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSourceWrapper_Threshold_Scan.py
More file actions
151 lines (119 loc) · 6.11 KB
/
SourceWrapper_Threshold_Scan.py
File metadata and controls
151 lines (119 loc) · 6.11 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import argparse
import logging
import beam_test
import os
import numpy as np
import time
from astropix import astropixRun
def change_all_TuneDACs(file,TuneDAC):
with open(file, 'r') as stream:
data=stream.readlines()
for i,line in enumerate(data):
if 'row' in line and len(line)>50:
for column in range(16):
line=line[:35+6*column]+bin(TuneDAC)[2:].zfill(3)[::-1]+line[38+6*column:]
data[i]=line
with open(file,'w') as stream:
stream.writelines(data)
def change_VPDAC(file,VPDAC):
with open(file, 'r') as stream:
data=stream.readlines()
for i,line in enumerate(data):
if 'vpdac' in line:
line=line[:36]+str(VPDAC)+']\n'
data[i]=line
with open(file,'w') as stream:
stream.writelines(data)
parser = argparse.ArgumentParser(description='Astropix Driver Code')
parser.add_argument('-n', '--name', default='', required=False,
help='Option to give additional name to output files upon running')
parser.add_argument('-o', '--outdir', default='.', required=False,
help='Output Directory for all datafiles')
parser.add_argument('-y', '--yaml', action='store', required=False, type=str, default = 'testconfig',
help = 'filepath (in config/ directory) .yml file containing chip configuration. Default: config/testconfig.yml (All pixels off)')
parser.add_argument('-V', '--chipVer', default=2, required=False, type=int,
help='Chip version - provide an int')
parser.add_argument('-s', '--showhits', action='store_true',
default=False, required=False,
help='Display hits in real time during data taking')
parser.add_argument('-p', '--plotsave', action='store_true', default=False, required=False,
help='Save plots as image files. If set, will be saved in same dir as data. Default: FALSE')
parser.add_argument('-c', '--saveascsv', action='store_true',
default=False, required=False,
help='save output files as CSV. If False, save as txt. Default: FALSE')
parser.add_argument('-f', '--newfilter', action='store_true',
default=False, required=False,
help='Turns on filtering of strings looking for header of e0 in V4. If False, no filtering. Default: FALSE')
parser.add_argument('-i', '--inject', action='store', default=None, type=int, nargs=2,
help = 'Turn on injection in the given row and column. Default: No injection')
parser.add_argument('-v','--vinj', action='store', default = None, type=float,
help = 'Specify injection voltage (in mV). DEFAULT None (uses value in yml)')
parser.add_argument('-a', '--analog', action='store', required=False, type=int, default = 0,
help = 'Turn on analog output in the given column. Default: Column 0.')
parser.add_argument('-t', '--threshold', type = float, action='store', default=None,
help = 'Threshold voltage for digital ToT (in mV). DEFAULT value in yml OR 100mV if voltagecard not in yml')
parser.add_argument('-E', '--errormax', action='store', type=int, default='100',
help='Maximum index errors allowed during decoding. DEFAULT 100')
parser.add_argument('-r', '--maxruns', type=int, action='store', default=None,
help = 'Maximum number of readouts')
parser.add_argument('-M', '--maxtime', type=float, action='store', default=None,
help = 'Maximum run time (in minutes)')
parser.add_argument('--timeit', action="store_true", default=False,
help='Prints runtime from seeing a hit to finishing the decode to terminal')
parser.add_argument('-L', '--loglevel', type=str, choices = ['D', 'I', 'E', 'W', 'C'], action="store", default='I',
help='Set loglevel used. Options: D - debug, I - info, E - error, W - warning, C - critical. DEFAULT: I')
parser.add_argument
args = parser.parse_args()
logname = "./runlogs/AstropixRunlog_" + time.strftime("%Y%m%d-%H%M%S") + ".log"
# Sets the loglevel
ll = args.loglevel
if ll == 'D':
loglevel = logging.DEBUG
elif ll == 'I':
loglevel = logging.INFO
elif ll == 'E':
loglevel = logging.ERROR
elif ll == 'W':
loglevel = logging.WARNING
elif ll == 'C':
loglevel = logging.CRITICAL
# Logging
formatter = logging.Formatter('%(asctime)s:%(msecs)d.%(name)s.%(levelname)s:%(message)s')
fh = logging.FileHandler(logname)
fh.setFormatter(formatter)
sh = logging.StreamHandler()
sh.setFormatter(formatter)
logging.getLogger().addHandler(sh)
logging.getLogger().addHandler(fh)
logging.getLogger().setLevel(loglevel)
logger = logging.getLogger(__name__)
#If using v2, use injection created by injection card
#If using v3, use injection created with integrated DACs on chip
onchipBool = True if args.chipVer > 2 else False
threshold_array=np.arange(40,241,5 ) ###### can change step here
for VPDAC in [10,20,30,40]:
# for VPDAC in [10]:
change_VPDAC(f'config/{args.yaml}.yml',VPDAC)
for TuneDAC in [0,1,2,3,4,5,6,7]:
change_all_TuneDACs(f'config/{args.yaml}.yml', TuneDAC)
time.sleep(1)
for col in [0,1,2,3,4,5,6,7,8,9,10,11,12]:
# for col in [9]:
args.inject=[1,col]
### outdir is currently specific to the machine used to run at goddard, change before running
args.outdir=f'E:/data/VPDAC_Testing_With_Grant/scan4/VPDAC_{VPDAC}/TuneDAC_{TuneDAC}/Col_{col}'
os.makedirs(args.outdir)
for threshold in threshold_array:
args.name=f'threshold_{threshold}mV'
print(f'{args.name}')
args.threshold=float(threshold)
success_bool=False
# beam_test.main(args)
while success_bool==False:
try:
beam_test.main(args)
success_bool=True
except:
print(f'An error occured on threshold {threshold}mV')
success_bool=False
time.sleep(1)