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 bkg_names(opts, args): debug_ = opts.debug test_ = opts.test set_ = opts.set prefix = None if args[0] == 'peak': prefix = 'peak' args = args[1:] parsed = yld.parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] limit = None if set_ != None and 'min' in set_: min_ = set_.split('=')[1] limit = '>%s' %min_ bkgmodes = 20 if set_ != None and 'bkgmodes' in set_: bkgmodes = int(set_.split('=')[1]) for mode in modes: tabname = 'bkg_names_%s_%s_%s' %( datatype, mode, label) if prefix != None: tabname = 'bkg_names_%s_%s_%s_%s' %( prefix, datatype, mode, label) tabname = tabname.replace('/', '_') tab = DHadTable() modename = get_orgname_from_fname(mode) bkg_names, bkg_numbers = bkg_names_single_mode( datatype, mode, label, limit, bkgmodes, debug_, prefix) tab.column_append(bkg_names, title='Backgrounds for %s' %modename) tab.column_append(bkg_numbers, title='Number of Events') tab.sort_by_column('Number of Events', reverse=True) orgfooter = ': '+sys.argv[0].split('/')[-1]+\ ' tab backgrounds names %s %s %s ' %( datatype, mode, label) if prefix != None: orgfooter = ': '+sys.argv[0].split('/')[-1]+\ ' tab backgrounds names %s %s %s %s ' %( prefix, datatype, mode, label) tab.output(tabname, orgfooter=orgfooter, test=test_)
def mctruth_names(opts, args): debug_ = opts.debug test_ = opts.test set_ = opts.set prefix = None if args[0] == 'peak': prefix = 'peak' args = args[1:] parsed = yld.parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] limit = None if set_ != None and 'min' in set_: min_ = set_.split('=')[1] limit = '>%s' % min_ mctruthmodes = 50 if set_ != None and 'mctruthmodes' in set_: mctruthmodes = int(set_.split('=')[1]) for mode in modes: tabname = 'mctruth_names_%s_%s_%s' % (datatype, mode, label) if prefix != None: tabname = 'mctruth_names_%s_%s_%s_%s' % (prefix, datatype, mode, label) tabname = tabname.replace('/', '_') tab = DHadTable() modename = get_orgname_from_fname(mode) mctruth_names, mctruth_numbers = mctruth_names_single_mode( datatype, mode, label, limit, mctruthmodes, debug_, prefix) tab.column_append(mctruth_names, title='MC Truth for %s' % modename) tab.column_append(mctruth_numbers, title='Number of Events') tab.sort_by_column('Number of Events', reverse=True) orgfooter = ': '+sys.argv[0].split('/')[-1]+\ ' tab mctruth names %s %s %s ' %( datatype, mode, label) if prefix != None: orgfooter = ': '+sys.argv[0].split('/')[-1]+\ ' tab mctruth names %s %s %s %s ' %( prefix, datatype, mode, label) tab.output(tabname, orgfooter=orgfooter, test=test_)
def brf_data_results(opts, tabname, args): ''' ----------------------------- Results of the Data Fit ----------------------------- ''' label_A = args[0] label_B = args[1] verbose = opts.verbose bffilename = 'bf_stat_sys' labels = [] labels.append(label_A) labels.append(label_B) tab = DHadTable() paras = False for label in labels: if '281ipb' in label: factor = 0.000001 elif '537ipb' in label: factor = 0.000001*281/537 elif '818ipb' in label or 'v13' in label: factor = 0.000001*281/818 else: raise NameError(label) if '818ipb' in label_A and '818ipb' in label_B: factor = 0.000001 if '818ipb' in label_A and 'v13' in label_B: factor = 0.000001 bffile = os.path.join(attr.brfpath, label, bffilename) if not paras: tab.column_append(tools.parse_result(bffile, 'paras'), 'Parameters') paras = True tab.column_append(tools.parse_result(bffile, 'value'), 'value', rnd='.00001' ) tab.column_append(tools.parse_result(bffile, 'stat'), 'stat') tab.column_append(tools.parse_result(bffile, 'syst'), 'syst') tab.columns_join3('Fitted Value', 'value', 'stat', 'syst') tab.column_trim('Fitted Value', row=['ND0D0Bar', 'ND+D-'], rnd='.0001', factor=factor, opt='(cell)x1E6') tab.column_trim('Fitted Value', rnd='.00001', except_row=['ND0D0Bar', 'ND+D-']) tab.column_append(tools.parse_result(bffile, 'err_frac'), 'Frac. Err', rnd='.1', opt='(cell%)') tab.columns_join(label, 'Fitted Value','Frac. Err', str=' ') tab.column_append_by_diff_sigma('Difference', label_B,label_A) tab.output(tabname, test=opts.test)
def fitResultsMC(opts, tabname, label): bffilename = 'bf_stat' bffile = tools.set_file(extbase=attr.brfpath, prefix='dir_' + label, comname=bffilename) if '281ipbv0' in label and '/generic' in label: generated = attr.Generic281v0_NBF power = '10E6' factor = 0.000001 elif '281ipbv12' in label and '/generic' in label: generated = attr.Generic281_NBF power = '10E7' factor = 0.0000001 elif '818ipbv12' in label and '/generic' in label: generated = attr.Generic818_NBF power = '10E7' factor = 0.0000001 else: raise NameError(label) tab = DHadTable() tab.column_append(parse_result(bffile, 'paras'), 'Parameters') tab.column_append(parse_result(bffile, 'value_err'), 'Fitted Value') tab.column_append(generated, 'Generated Value') tab.column_append_by_diff_sigma('Difference', 'Fitted Value', 'Generated Value') tab.column_trim('Fitted Value', row=['ND0D0Bar', 'ND+D-'], rnd='.001', factor=factor, opt='(cell)x%s' % power) tab.column_trim('Fitted Value', rnd='.00001', except_row=['ND0D0Bar', 'ND+D-']) tab.column_append(parse_result(bffile, 'err_frac'), 'Frac. Err', rnd='.1', opt='(cell%)') tab.columns_join('Fitted Value', 'Fitted Value', 'Frac. Err', str=' ') tab.column_trim('Generated Value', row=['ND0D0Bar', 'ND+D-'], rnd='.001', factor=factor, opt='cellx%s' % power) tab.output(tabname, label=label)
def brf_data_syst(args): print args label_A = args[0] label_B = args[1] bffilename = 'bf_stat_sys' tab = DHadTable() bffileA = os.path.join(attr.brfpath, label_A, bffilename) tab.column_append(tools.parse_result(bffileA, 'paras'), 'Parameters') tab.column_append(tools.parse_result(bffileA, 'value'), 'value_A') tab.column_append(tools.parse_result(bffileA, 'syst'), label_A) bffileB = os.path.join(attr.brfpath, label_B, bffilename) tab.column_append(tools.parse_result(bffileB, 'value'), 'value_B') tab.column_append(tools.parse_result(bffileB, 'syst'), label_B) #tab.column_append_by_diff_sigma_pct('diff(%)', label_B,label_A, rnd=rnd) tab.output()
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)
def pdg2009(args): ''' -------------------------------------------------------- Results of the Data Fit Compare with PDG 2009 -------------------------------------------------------- ''' label = args[0] verbose = opts.verbose bffilename = 'bf_stat_sys' bffile = os.path.join(attr.brfpath, label, bffilename) tab = DHadTable() tab.column_append(tools.parse_result(bffile, 'paras'), 'Parameters') tab.column_append(tools.parse_result(bffile, 'value'), 'value') tab.column_append(tools.parse_result(bffile, 'stat'), 'stat') tab.column_append(tools.parse_result(bffile, 'syst'), 'syst') tab.columns_join3('Fitted Value', 'value', 'stat', 'syst') tab.column_trim('Fitted Value', row = ['ND0D0Bar', 'ND+D-'], rnd = '.001', factor = 0.000001, opt = '(cell)x10E6') tab.column_trim('Fitted Value', rnd = '.0001', except_row = ['ND0D0Bar', 'ND+D-']) tab.column_append(tools.parse_result(bffile, 'err_frac'), 'Frac. Err', rnd = '.1', opt = '(cell%)') tab.columns_join('Fitted Value','Fitted Value','Frac. Err', str=' ') tab.column_append(attr.PDG2009_NBF, 'PDG 2009') tab.column_append_by_diff_sigma('Difference', 'Fitted Value', 'PDG 2009') tab.output(_tabname)
def get_brs_from_file(label): tab = DHadTable() bffilename = 'bf_stat_sys' bffile = os.path.join(attr.brfpath, label, bffilename) tab.column_append(parse_result(bffile, 'paras'), 'Parameters') tab.column_append(parse_result(bffile, 'value'), 'value') tab.column_append(parse_result(bffile, 'stat'), 'stat') tab.column_append(parse_result(bffile, 'syst'), 'syst') tab.rows_delete(['Parameters', 'ND0D0Bar', 'ND+D-']) content = [] n = 0 for row in tab.data: n += 1 line = 'exec addData %s %s %s %s \n' %( n, row[1], row[2], row[3]) content.append(line) return content