#!/usr/bin/python import os,sys,glob,re from fpformat import fix pass_dir = '/home/jbueno/pass8' nevts_fn = '/home/jbueno/QOD/Part1/nevts.txt' ## __________ def steal_numbers(my_string): return re.findall(r'(\d+)', my_string) ## __________ def get_n_fid(): n_fid = {} michel_logs = glob.glob(pass_dir+'/*.michel.log') michel_logs.sort() for l in michel_logs: l_clean = l.split('/')[-1] set = int(l_clean[3:5]) if set not in [68,70,71,72,74,75,76,83,84,86,87,91,92,93]: print 'ERROR: something wrong with this filename:' print l sys.exit(1) n_fiducial = None fl = file(l,'r').readlines() for i,l in enumerate(fl): if 'Data: HistoDesc' in l: n_fiducial = int(float(fl[i+1].split('=')[2]))/1E6 break if n_fiducial == None: print 'ERROR: could not find line in michel log file:' print l sys.exit(1) n_fid[set] = n_fiducial return n_fid ## __________ def get_good_set_ana(): sa = [] michel_logs = glob.glob(pass_dir+'/*.michel.log') for l in michel_logs: try: nums = steal_numbers(l.split('/')[-1]) sa.append((int(nums[0]),int(nums[1]))) except: print 'ERROR: weird format for michel log file:' print l sys.exit(1) return sa ## __________ def get_nevts(): nevts = {} f = file(nevts_fn,'r') for l in f: if not l.startswith('#'): ls = l.split() nevts[int(ls[0])] = int(float(ls[1])) return nevts ## __________ def count_nevts(sa,nevts,pathbit): counted = {} for (s,a) in sa: path = '/twist/tw00y/systematics/data/set'+str(s)+'/anal'+str(a)+'/'+pathbit+'/' print 'reading',path l = [] for r in glob.glob(path+'run*'): try: l.append(nevts[int(r.split('/')[-1][3:8])]) except KeyError: continue counted[s] = sum(l) return counted ## __________ if __name__=='__main__': n_fid = get_n_fid() sa = get_good_set_ana() #following are for the sets not used for MPs: # sa.extend([(73,8),(80,1),(82,2),(89,1)]) sa.extend([(73,8),(80,1),(89,1)]) nevts = get_nevts() n_pre_checks = count_nevts(sa,nevts,'root') n_post_checks = count_nevts(sa,nevts,'goodlinks') sets = [s for (s,a) in sa] sets.sort() for s in sets: print s, try: print fix(n_post_checks[s]/1E6,0), except KeyError: print '-','-', try: print fix(n_fid[s],0), except KeyError: print '-', print # /twist/data36/systematics/data/set68/anal2 # print set,fix(n_fiducial,0)