Ejemplo n.º 1
0
Archivo: divide.py Proyecto: xshi/dhad
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)
Ejemplo n.º 2
0
def para_argus(para, args):
    namestyle = 'fname'
    rnd = '0.01'
    tag = 's'

    rowName = para
    extbase = attr.fitbase
    ext = 'txt'

    dt_type = args[0]
    tab_A = args[1]
    tab_B = args[2]

    label_A = tab_A
    label_B = tab_B

    label = tools.parseopts_set(opts.set, 'label')
    if label:
        labels = label.split(',')
        label_A = labels[0]
        label_B = labels[1]
    tab = DHadTable()
    tab.column_append_from_dict('Mode', namestyle)
    tab.column_append_from_files(label_A, rowName, extbase, 'dir_'+tab_A, 
                                 dt_type, tag, ext, rnd=rnd)
    tab.column_append_from_files(label_B, rowName, extbase, 'dir_'+tab_B, 
                                 dt_type, tag, ext, rnd=rnd)
    tab.column_append_by_diff_pct('diff(%)', label_B, label_A, rnd=rnd)
    tab.output(_tabname)
Ejemplo n.º 3
0
def momentum(opts, tabname, args):
    if args[0] != 'resolution': 
        raise NameError(args)

    label = args[1] 
    dt_type = 'signal'
    tag = 'double'
    #ver = opts.analysis
    fitbase = attr.fitpath

    prefix = 'dir_%s/resolution' % label

    # Mode | sigma(MeV) | fa | fb | sa | sb | [sigmaE (MeV)]
    tab = DHadTable()
    tab.column_append_from_dict('Mode', 'fname')     
    tab.column_append_from_files(
        'sigma (MeV)', 'sigmacommon1', fitbase, prefix, 
        dt_type, tag,  'txt', rnd='.01', factor=1000)

    tab.column_append_from_files('fa', 'f1a',  fitbase, prefix, 
                                 dt_type, tag,  'txt', rnd='.001')
    tab.column_append_from_files('fb', 'f1b', fitbase, prefix, 
                                 dt_type, tag,  'txt', rnd='.0001')
    tab.column_append_from_files('sa', 's1a',  fitbase, prefix, 
                                 dt_type, tag,  'txt', rnd='.01')
    tab.column_append_from_files('sb', 's1b',  fitbase, prefix, 
                                 dt_type, tag,  'txt', rnd='.01')


    tab.output(tabname, test=opts.test)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def vary_argus_single(opts, tabname, label):
    tab = DHadTable()

    print tabname

    tabprefix0 = 'dir_818ipbv7/argus_low/fix_n1n2'
    tabprefix1 = 'dir_818ipbv7'
    tabprefix2 = 'dir_818ipbv7/argus_high/fix_n1n2'

    tab.column_append_from_dict('Mode', 'fname,fnamebar')
    titles = ['argus_low', 'std', 'argus_high']
    tab.column_append_from_files(titles[0], 'N1,N2', fitbase, tabprefix0, 'd',
                                 's', 'txt')
    tab.column_append_from_files(titles[1], 'N1,N2', fitbase, tabprefix1, 'd',
                                 's', 'txt')
    tab.column_append_from_files(titles[2], 'N1,N2', fitbase, tabprefix2, 'd',
                                 's', 'txt')

    std = titles[1]
    colA = titles[0]
    colB = titles[2]
    headA = 'diff(%s)' % colA
    headB = 'diff(%s)' % colB
    headC = 'max-diff(%)'
    tab.column_append_by_diff_pct(headA, colA, std)
    tab.column_append_by_diff_pct(headB, colB, std)
    tab.column_append_by_max(headC, headA, headB)
    #tab.columns_delete([headA, headB])
    tab.columns_trim(titles, rnd='1.')

    tab.output()  #tabname, texhead, outputtxt=True)
Ejemplo n.º 8
0
def evtfile(args):

    if args[0] not in ['signal', 'data'] :
	raise NameError(args)

    variable = 'yields'
    dt_type = args[0]
    tag = args[1]
    
    evt_A =  args[2]
    evt_B =  args[3]

    label_A, evtbase_A, prefix_A = tools.parse_evtname(opts, evt_A) 
    label_B, evtbase_B, prefix_B = tools.parse_evtname(opts, evt_B) 

    filelist_A = tools.set_file_list(evtbase_A, prefix_A, dt_type, tag, 'evt')
    filelist_B = tools.set_file_list(evtbase_B, prefix_B, dt_type, tag, 'evt')
    zipped = zip(filelist_A, filelist_B)

    for f in zipped:
        fa = f[0]
        fb = f[1]

        diff = tools.diff(fa, fb)
        print diff
    sys.exit()

    sys.stdout.write('dhad.tab : Compare %s between %s and %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_diff_sigma_pct('diff(%)', label_B,label_A, rnd=rnd)
    
    tab.output(_tabname)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
def argus(opts, tabname, args):
    if args[0] == 'slope':
        rowname_A = 'xi'
        rowname_B = 'xi'
        rowname_C = 'xi'

    if args[0] == 'power':
        rowname_A = 'p'
        rowname_B = 'p'
        rowname_C = 'p'
    
    label = args[1]
    
    if args[2] != 'desidebands':
        raise NameError(args)

    namestyle = 'fname'
    rnd = '0.01'
    tag = 's'
    extbase = attr.fitbase
    ext = 'txt'
    dt_type = 'data'

    label_A = label
    prefix_A = 'dir_%s' % label_A

    label_B = 'desideband_low'
    prefix_B = 'dir_%s/%s' % (label, label_B)

    label_C = 'desideband_high'
    prefix_C = 'dir_%s/%s' % (label, label_C)

    tab = DHadTable()
    tab.column_append_from_dict('Mode', namestyle)
    tab.column_append_from_files(label_A, rowname_A, extbase, prefix_A,
                                 dt_type, tag, ext, rnd=rnd)
    tab.column_append_from_files(label_B, rowname_B, extbase, prefix_B,
                                 dt_type, tag, ext, rnd=rnd)
    tab.column_append_from_files(label_C, rowname_C, extbase, prefix_C,
                                 dt_type, tag, ext, rnd=rnd)
    tab.output(tabname)