make_norm_csv.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import ROOT as RT
4 from glob import glob as ls
5 from argparse import ArgumentParser as ap
6 
7 parser = ap()
8 
9 parser.add_argument( "-p", type=str, help='Path to files', default='./')
10 args = parser.parse_args()
11 
12 #print(ls(args.p))
13 
14 all_files = [i.split("/")[-1] for i in ls(args.p + "*")]
15 files = []
16 global_meds = []
17 for p in all_files:
18  if 'global_median' in p:
19  print(p)
20  global_meds.append(p)
21 runs = set([i.replace(".txt", "").split("_")[-1] for i in global_meds])
22 print(runs)
23 
24 for r in runs:
25  f0 = open(args.p + 'global_median_0_' + r + '.txt', 'r')
26  f1 = open(args.p + 'global_median_1_' + r + '.txt', 'r')
27  f2 = open(args.p + 'global_median_2_' + r + '.txt', 'r')
28 
29  info_0 = f0.readlines()[0]
30  info_1 = f1.readlines()[0]
31  info_2 = f2.readlines()[0]
32  print(info_0)
33  print(info_1)
34  print(info_2)
35 
36  run_num = info_0.split()[0]
37  norm_0 = info_0.split()[1]
38  norm_err_0 = str(float(norm_0)/10.)
39  print(run_num, norm_0, norm_err_0)
40 
41  norm_1 = info_1.split()[1]
42  norm_err_1 = str(float(norm_1)/10.)
43 
44  norm_2 = info_2.split()[1]
45  norm_err_2 = str(float(norm_2)/10.)
46 
47 
48  output = [
49  'channel,tv,norm,norm_err\n',
50  ','.join(['0', run_num, norm_0, norm_err_0+"\n" ]),
51  ','.join(['1', run_num, norm_1, norm_err_1+"\n" ]),
52  ','.join(['2', run_num, norm_2, norm_err_2+"\n" ])
53  ]
54  print(output)
55  outfile = open('globalmedians_run' + run_num + '.csv', 'w')
56  outfile.writelines(output)
57  outfile.close()
int open(const char *, int)
Opens a file descriptor.
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35