-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpmtGainTXT.py
30 lines (22 loc) · 1.33 KB
/
pmtGainTXT.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
import argparse
import numpy as np
import tables as tb
from functools import partial
from invisible_cities.io.channel_param_io import subset_param_reader as spr
parser = argparse.ArgumentParser(description='Extract gain values from the param. hdf5 file.')
parser.add_argument('file_in', type=str, help='Name of the file') #positional argument
ns = parser.parse_args()
data_file = ns.file_in
run_number = data_file[data_file.find('R')+1:data_file.find('R')+5]
param_names = ['pedestal_sigma', 'poisson_mu', 'gain', 'gain_sigma', 'n_gaussians_chi2']
read_params = partial(spr, table_name='FIT_pmt_scaled_dark_pedestal',
param_names=param_names)
with open('pmtGain_R'+run_number+'.txt', 'w') as out_file:
with tb.open_file(data_file) as df:
for sens, (pars, errs) in read_params(df):
out_file.write(run_number+', 100000, ' +str(sens)+', '
+str(pars['pedestal_sigma' ])+', '+str(errs['pedestal_sigma'])+', '
+str(pars['poisson_mu' ])+', '+str(errs['poisson_mu' ])+', '
+str(pars['gain' ])+', '+str(errs['gain' ])+', '
+str(pars['gain_sigma' ])+', '+str(errs['gain_sigma' ])+', '
+str(errs['n_gaussians_chi2'])+'\n')