def divide_yields(args): if args[0] not in ['signal', 'data'] : raise NameError(args) variable = 'yields' rnd='.01' dt_type = args[0] tag = args[1] tab_A = args[2] tab_B = args[3] label_A, fitbase_A, prefix_A = tools.parse_tabname(_opts, tab_A) label_B, fitbase_B, prefix_B = tools.parse_tabname(_opts, tab_B) sys.stdout.write('dhad.tab : Divide %s of %s by %s:' %( variable, tab_A, tab_B)) tab = DHadTable() namestyle = 'fname,fnamebar' tab.column_append_from_dict('Mode', namestyle) tab.column_append_from_files(label_A, 'N1,N2', fitbase_A, prefix_A, dt_type, tag ,'txt', rnd='1.') tab.column_append_from_files(label_B, 'N1,N2', fitbase_B, prefix_B, dt_type, tag ,'txt', rnd='1.') tab.column_append_by_divide('%s/%s' %(label_A, label_B), label_A, label_B, rnd=rnd, err_type='Indp') tab.output(_tabname)
def yields(opts, tabname, args): if args[0] not in ['signal', 'data'] : raise NameError(args) rnd='.01' err_type=None diff = 'pct' sign = 1 if opts.set: for li in opts.set.split(':'): name = li.split('=')[0] value = li.split('=')[1] sys.stdout.write('Set %s = %s \n' % (name, value)) if name == 'diff': diff = value if name == 'err_type': err_type = value if name == 'sign': sign = value variable = 'yields' dt_type = args[0] tag = args[1] label_A = args[2] label_B = args[3] fitbase = attr.fitbase sys.stdout.write('dhad.tab : Compare %s between %s and %s:\n' %( variable, label_A, label_B )) tab = DHadTable() namestyle = 'fname,fnamebar' tab.column_append_from_dict('Mode', namestyle) tab.column_append_from_files(label_A, 'N1,N2', fitbase, 'dir_%s' %label_A, dt_type, tag ,'txt', rnd='1.') tab.column_append_from_files(label_B, 'N1,N2', fitbase, 'dir_%s' %label_B, dt_type, tag ,'txt', rnd='1.') if sign == '0': tab.rows_join_by_average(rnd='1.') if diff == 'pct': tab.column_append_by_diff_pct( 'diff(%)', label_B,label_A, rnd=rnd, err_type=err_type) elif diff == 'sigma_pct': tab.column_append_by_diff_sigma_pct('diff(%)', label_B,label_A, rnd=rnd) elif diff == 'sigma2_pct': tab.column_append_by_diff_sigma2_pct('diff(%)', label_B,label_A, rnd=rnd) elif diff == 'ratio': tab.column_append_by_divide( 'ratio', label_B,label_A, rnd=rnd, err_type='Indp') else: raise NameError(diff) tab.output(tabname, test=opts.test)
def eff_kkpi_comp(opts, tabname, label): tab = DHadTable() tabprefix = 'dir_' + label mode = 205 tab.column_append_from_dict('Mode', 'fname,fnamebar', mode=mode) tab.column_append([20000, 20000], 'Generated') tab.column_append_from_files('Yield', 'N1,N2', fitbase, tabprefix, 's', 's', 'txt', rnd='1.', mode=mode) tab.column_append_by_divide('Eff(%)', 'Yield', 'Generated', 'Efcy', '.01', 100) tab.columns_delete(['Generated', 'Yield']) def get_eff(subdir): logname = 'signal_Single_%s.txt' % modes[mode]['fname'] logpath = os.path.join(attr.logpath, label, subdir, 'yld') logfile = tools.set_file(extbase=logpath, comname=logname) for line in file(logfile): if 'selected' in line: total = int(line.split()[-1].replace('.', '')) break t = DHadTable() t.column_append([total, total], 'Generated') t.column_append_from_files('Yield', 'N1,N2', fitbase, '%s/%s' % (tabprefix, subdir), 's', 's', 'txt', rnd='1.', mode=mode) t.column_append_by_divide('%s(%%)' % subdir, 'Yield', 'Generated', 'Efcy', '.01', 100) return t.column_get('%s(%%)' % subdir) for subdir in ['phipi', 'k0star', 'phsp']: tab.column_append(get_eff(subdir)) #head_diff = subdir #col = '%s(%%)' % subdir #std = 'Eff(%)' #tab.column_append_by_diff_pct(head_diff, col, std) tab.output(tabname, label=label)
def divide_yields(args): if args[0] not in ['signal', 'data']: raise NameError(args) variable = 'yields' rnd = '.01' dt_type = args[0] tag = args[1] tab_A = args[2] tab_B = args[3] label_A, fitbase_A, prefix_A = tools.parse_tabname(_opts, tab_A) label_B, fitbase_B, prefix_B = tools.parse_tabname(_opts, tab_B) sys.stdout.write('dhad.tab : Divide %s of %s by %s:' % (variable, tab_A, tab_B)) tab = DHadTable() namestyle = 'fname,fnamebar' tab.column_append_from_dict('Mode', namestyle) tab.column_append_from_files(label_A, 'N1,N2', fitbase_A, prefix_A, dt_type, tag, 'txt', rnd='1.') tab.column_append_from_files(label_B, 'N1,N2', fitbase_B, prefix_B, dt_type, tag, 'txt', rnd='1.') tab.column_append_by_divide('%s/%s' % (label_A, label_B), label_A, label_B, rnd=rnd, err_type='Indp') tab.output(_tabname)
def get_eff(subdir): logname = 'signal_Single_%s.txt' % modes[mode]['fname'] logpath = os.path.join(attr.logpath, label, subdir, 'yld') logfile = tools.set_file(extbase=logpath, comname=logname) for line in file(logfile): if 'selected' in line: total = int(line.split()[-1].replace('.', '')) break t = DHadTable() t.column_append([total, total], 'Generated') t.column_append_from_files('Yield', 'N1,N2', fitbase, '%s/%s' % (tabprefix, subdir), 's', 's', 'txt', rnd='1.', mode=mode) t.column_append_by_divide('%s(%%)' % subdir, 'Yield', 'Generated', 'Efcy', '.01', 100) return t.column_get('%s(%%)' % subdir)