コード例 #1
0
ファイル: compare.py プロジェクト: zhixing1996/dhad
def parsefile(f, lowmass, highmass, indict):
    x0 = lowmass
    x1 = highmass
    xc = (x0 + x1) / 2.

    tab = DHadTable(f)
    N1 = float(tab.cell_get('N1', 'Value'))
    N2 = float(tab.cell_get('N2', 'Value'))

    if N1 > 1000 or N2 > 1000:
        return

    indict['x'].append(xc)
    indict['exl'].append(xc - x0)
    indict['exh'].append(x1 - xc)

    N = N1 + N2

    err_low_N1 = float(tab.cell_get('N1', 'Low'))
    err_low_N2 = float(tab.cell_get('N2', 'Low'))

    err_low = (err_low_N1**2 + err_low_N2**2)**.5

    err_high_N1 = float(tab.cell_get('N1', 'High'))
    err_high_N2 = float(tab.cell_get('N2', 'High'))
    err_high = (err_high_N1**2 + err_high_N2**2)**.5

    yc = float(N)
    yl = float(err_low)
    yh = float(err_high)

    indict['y'].append(yc)
    indict['eyl'].append(yl)
    indict['eyh'].append(yh)
コード例 #2
0
ファイル: compare.py プロジェクト: xshi/dhad
def parsefile(f, lowmass, highmass, indict):
    x0 = lowmass
    x1 = highmass
    xc = (x0 + x1)/2.

    tab     = DHadTable(f)
    N1      = float(tab.cell_get('N1', 'Value'))
    N2      = float(tab.cell_get('N2', 'Value'))

    if N1 > 1000 or N2 > 1000 :
        return

    indict['x'].append(xc)
    indict['exl'].append(xc-x0)
    indict['exh'].append(x1-xc)

    N = N1 + N2
    
    err_low_N1 = float(tab.cell_get('N1', 'Low'))
    err_low_N2 = float(tab.cell_get('N2', 'Low'))

    err_low = (err_low_N1**2 + err_low_N2**2)**.5

    err_high_N1 = float(tab.cell_get('N1', 'High'))
    err_high_N2 = float(tab.cell_get('N2', 'High'))
    err_high = (err_high_N1**2 + err_high_N2**2)**.5

    yc = float(N)
    yl = float(err_low)
    yh = float(err_high)

    indict['y'].append(yc)
    indict['eyl'].append(yl)
    indict['eyh'].append(yh)
コード例 #3
0
def get_paras(dt_type, label, fname):

    prefix='dir_'+label+'/crossfeeds'
        
    tabname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fname)
    tabfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=tabname)

    tab = DHadTable(tabfile)
    mass = tab.cell_get('mass', 'Value')
    sigma = tab.cell_get('sigma', 'Value')
    n = tab.cell_get('n', 'Value')
    alpha = tab.cell_get('alpha', 'Value')

    return  alpha, mass, n, sigma
コード例 #4
0
ファイル: __init__.py プロジェクト: xshi/dhad
def get_argus_paras_single(label, dt_type, tag, mode):
    if 'argus' in label:
        prefix = 'dir_' + label.replace('argus', 'desideband')

    argus_para_base = attr.fitpath
    tabfile =  tools.set_file('txt', dt_type, mode, tag,
                              prefix=prefix,
                              extbase=argus_para_base)

    sys.stdout.write('Loading ARGUS parameters from %s ...\n' %tabfile)    
    tab     = DHadTable(tabfile)
    xi      = float(tab.cell_get('xi', 'Value'))
    p       = float(tab.cell_get('p', 'Value'))
                  
    return xi, p
コード例 #5
0
ファイル: sigeffs.py プロジェクト: zhixing1996/dhad
def get_generated_numbers_single(i, prefix=''):
    if '281ipb' in prefix:
        mult_fact = 10
    elif '537ipb' in prefix:
        mult_fact = 20
    elif '818ipb' in prefix or 'v13' in prefix:
        mult_fact = 30
    else:
        raise NameError(prefix)

    mode = i[0]
    sign = i[1]
    tag_number = modes[mode]['tag_num_s']
    count = tag_number * mult_fact
    if mode == 205:
        if sign == 1:
            count = 29972  # 30000
        if sign == -1:
            count = 35969  # 36000

    if 'noFSR' in prefix:
        mode = i[0]
        sign = i[1]
        logfile = tools.set_file('log',
                                 's',
                                 mode,
                                 's',
                                 sign,
                                 prefix,
                                 extbase=evtlogbase)
        tab = DHadTable(logfile)
        FSR = tab.cell_get('FSR', 'Value')
        count = count - int(FSR)

    return count
コード例 #6
0
ファイル: sigeffs.py プロジェクト: zhixing1996/dhad
def get_generated_numbers_double(pair, prefix=''):
    if '281ipb' in prefix:
        mult_fact = 10
    elif '537ipb' in prefix:
        mult_fact = 20
    elif '818ipb' in prefix or 'v13' in prefix:
        mult_fact = 30
    else:
        raise NameError(prefix)

    i = pair[0]
    j = pair[1]

    #genpath = attr.genpath
    #print genpath
    #sys.exit()
    #if attr.analysis == '10.1' and '281ipbv0' in prefix :
    #    genpath = '/nfs/cor/user/ponyisi/cleog/scripts-summerconf/'

    tag_number = 2000
    count = tag_number * mult_fact
    if 'v13' in prefix:
        fname = modes[i]['fname']
        fnamebar = modes[j]['fnamebar']
        modename = 'Double_%s__%s' % (fname, fnamebar)
        if modename == 'Double_Dp_to_KKpi__Dm_to_KKpi':
            count = 47966
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kpipipi0':
            count = 58403
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kpipi':
            count = 57954
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kspipi0':
            count = 57969
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kspipipi':
            count = 24693
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kspi':
            count = 57953
        if modename == 'Double_Dp_to_Kpipi__Dm_to_KKpi':
            count = 59952
        if modename == 'Double_Dp_to_Kpipipi0__Dm_to_KKpi':
            count = 55955
        if modename == 'Double_Dp_to_Kspi__Dm_to_KKpi':
            count = 57954
        if modename == 'Double_Dp_to_Kspipi0__Dm_to_KKpi':
            count = 57956
        if modename == 'Double_Dp_to_Kspipipi__Dm_to_KKpi':
            count = 57954

    if 'noFSR' in prefix:
        logfile = tools.set_file('log',
                                 's',
                                 pair,
                                 'd',
                                 prefix=prefix,
                                 extbase=evtlogbase)
        tab = DHadTable(logfile)
        FSR = tab.cell_get('FSR', 'Value')
        count = count - int(FSR)

    return count
コード例 #7
0
ファイル: sigeffs.py プロジェクト: xshi/dhad
def get_generated_numbers_single(i, prefix=''):
    if '281ipb' in prefix:
        mult_fact = 10
    elif '537ipb' in prefix:
        mult_fact = 20
    elif '818ipb' in prefix or 'v13' in prefix:
        mult_fact = 30
    else:
        raise NameError(prefix)
    
    mode = i[0]
    sign = i[1]
    tag_number = modes[mode]['tag_num_s']
    count = tag_number*mult_fact
    if mode == 205: 
        if sign == 1:
            count = 29972 # 30000
        if sign == -1: 
            count = 35969 # 36000

    if 'noFSR' in prefix:
        mode = i[0]
        sign = i[1]
        logfile =  tools.set_file('log', 's',  mode, 's', sign, prefix,
                                      extbase=evtlogbase)
        tab = DHadTable(logfile)
        FSR = tab.cell_get('FSR', 'Value')
        count = count - int(FSR)
        
    return count
コード例 #8
0
ファイル: datayields.py プロジェクト: zhixing1996/dhad
def data_yields_double(fo, prefix, opt='', label='', verbose=0):
    dt_type = 'd'
    tag = 'd'
    mode_pair_list = attr.PossibleDoubleTags
    n = 0

    for mode_pair in mode_pair_list:
        i = mode_pair[0]
        j = mode_pair[1]
        txtfile = tools.set_file('txt',
                                 dt_type,
                                 mode_pair,
                                 tag,
                                 prefix=prefix,
                                 extbase=attr.fitpath)
        tab = DHadTable(txtfile)
        N = tab.cell_get(1, 'Value')
        N_err = tab.cell_get(1, 'Error')

        if 'DCSD_0' in opt:
            dcsd_sys = 0

        if opt == 'statonly':
            syerrmul = 0

        else:
            syerrmul = 0
            if i in (0, 1, 3):
                dcsd_sys, dcsd_cor = get_dcsd_sys(label, i, j)
                syerrmul += dcsd_sys**2
                if dcsd_cor != None:
                    sys.stdout.write(
                        'Correcting mode (%s %s) with %s +/- %s ...\n' %
                        (i, j, dcsd_cor, dcsd_sys))
                    N = str(float(N) * dcsd_cor)

            syerrmul = syerrmul**.5

        N_err_sys = str(float(N) * syerrmul)
        fo.write('%s\n%s\n%s\n' % (N, N_err, N_err_sys))
        n += 1
        if verbose > 1:
            print '%s +/- %s +/- %s' % (N, N_err, N_err_sys)

    if verbose > 0:
        print 'Total double tag data yield lines ... %s' % n
コード例 #9
0
ファイル: __init__.py プロジェクト: zhixing1996/dhad
def get_argus_paras_single(label, dt_type, tag, mode):
    if 'argus' in label:
        prefix = 'dir_' + label.replace('argus', 'desideband')

    argus_para_base = attr.fitpath
    tabfile = tools.set_file('txt',
                             dt_type,
                             mode,
                             tag,
                             prefix=prefix,
                             extbase=argus_para_base)

    sys.stdout.write('Loading ARGUS parameters from %s ...\n' % tabfile)
    tab = DHadTable(tabfile)
    xi = float(tab.cell_get('xi', 'Value'))
    p = float(tab.cell_get('p', 'Value'))

    return xi, p
コード例 #10
0
ファイル: sigeffs.py プロジェクト: xshi/dhad
def get_generated_numbers_double(pair, prefix=''):
    if '281ipb' in prefix:
        mult_fact = 10
    elif '537ipb' in prefix:
        mult_fact = 20
    elif '818ipb' in prefix or 'v13' in prefix:
        mult_fact = 30
    else:
        raise NameError(prefix)

    i = pair[0]
    j = pair[1]

    #genpath = attr.genpath
    #print genpath
    #sys.exit()
    #if attr.analysis == '10.1' and '281ipbv0' in prefix :
    #    genpath = '/nfs/cor/user/ponyisi/cleog/scripts-summerconf/'

    tag_number = 2000
    count = tag_number * mult_fact
    if 'v13' in prefix: 
        fname = modes[i]['fname']
        fnamebar = modes[j]['fnamebar']
        modename = 'Double_%s__%s' %(fname, fnamebar)
        if modename == 'Double_Dp_to_KKpi__Dm_to_KKpi': 
            count = 47966
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kpipipi0':
            count = 58403
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kpipi': 
            count = 57954
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kspipi0': 
            count = 57969
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kspipipi': 
            count = 24693
        if modename == 'Double_Dp_to_KKpi__Dm_to_Kspi': 
            count = 57953
        if modename == 'Double_Dp_to_Kpipi__Dm_to_KKpi':
            count = 59952
        if modename == 'Double_Dp_to_Kpipipi0__Dm_to_KKpi':
            count = 55955
        if modename == 'Double_Dp_to_Kspi__Dm_to_KKpi':
            count = 57954
        if modename == 'Double_Dp_to_Kspipi0__Dm_to_KKpi':
            count = 57956
        if modename == 'Double_Dp_to_Kspipipi__Dm_to_KKpi':
            count = 57954
 
    if 'noFSR' in prefix:
        logfile =  tools.set_file('log', 's',  pair, 'd', prefix=prefix,
                                  extbase=evtlogbase)
        tab =DHadTable(logfile)
        FSR = tab.cell_get('FSR', 'Value')
        count = count - int(FSR)

    return count
コード例 #11
0
ファイル: __init__.py プロジェクト: zhixing1996/dhad
def get_resolution_paras(mode, label):
    if 'resolution' in label:
        Sigma = 0.005
        Fa = 0.05
        Fb = 0.05
        Sa = 2.0
        Sb = 2.0

    else:
        tab_name = 'para_momentum_resolution'
        short_label = label.split('/')[0]
        if short_label in [
                '281ipbv0', '281ipbv12', '537ipbv12', '818ipbv12', '818ipbv13',
                'v13'
        ]:
            tab_name = '%s/%s' % (short_label, tab_name)
        else:
            raise NameError(label)

        tab_prefix = ''
        tab_opt_sigma = 'value'
        tab_opt_fa = 'value'
        tab_opt_fb = 'value'
        tab_opt_sa = 'value'
        tab_opt_sb = 'value'

        tabfile = tools.set_file(extbase=attr.tabpath,
                                 prefix=tab_prefix,
                                 comname=tab_name,
                                 ext='txt')
        sys.stdout.write('Loading lineshape parameters from %s... \n' %
                         tabfile)
        tab = DHadTable(tabfile)
        line_no = attr.mode_line_dict[mode]
        Sigma = float(tab.cell_get(line_no, 'sigma (MeV)',
                                   tab_opt_sigma)) / 1000
        Fa = float(tab.cell_get(line_no, 'fa', tab_opt_fa))
        Fb = float(tab.cell_get(line_no, 'fb', tab_opt_fb))
        Sa = float(tab.cell_get(line_no, 'sa', tab_opt_sa))
        Sb = float(tab.cell_get(line_no, 'sb', tab_opt_sb))

    return Sigma, Fa, Fb, Sa, Sb
コード例 #12
0
ファイル: datayields.py プロジェクト: zhixing1996/dhad
def data_yields_single(fo, prefix, opt='', label='', verbose=0):
    sys_err, sys_err_by_mode = attr.sys_err(label)

    dt_type = 'd'
    tag = 's'

    #sys_err_by_mode = attr.sys_err_by_mode(label)

    for mode in modes:
        if opt == 'statonly':
            syerrmul = 0
        else:
            syerrmul = sys_err_by_mode[mode]['ST Background modeling']
            if mode == 0:
                lepton_veto = sys_err_by_mode[mode]['Lepton veto']
                syerrmul = math.sqrt(syerrmul**2 + lepton_veto**2)

        input_file = tools.set_file('txt',
                                    dt_type,
                                    mode,
                                    tag,
                                    prefix=prefix,
                                    extbase=attr.fitpath)
        tab = DHadTable(input_file)
        N1 = tab.cell_get(1, 'Value')
        N1_err = tab.cell_get(1, 'Error')
        N1_err_sys = str(float(N1) * syerrmul)

        N2 = tab.cell_get(2, 'Value')
        N2_err = tab.cell_get(2, 'Error')
        N2_err_sys = str(float(N2) * syerrmul)

        fo.write('%s\n%s\n%s\n' % (N1, N1_err, N1_err_sys))
        fo.write('%s\n%s\n%s\n' % (N2, N2_err, N2_err_sys))

        if verbose > 1:
            print '%s +/- %s +/- %s' % (N1, N1_err, N1_err_sys)
            print '%s +/- %s +/- %s' % (N2, N2_err, N2_err_sys)
    if verbose > 0:
        print 'single tag data yield finished.'
コード例 #13
0
ファイル: __init__.py プロジェクト: xshi/dhad
def init_paras_single(label, dt_type, tag, mode):

    if '281ipb' in label:
        init_para_prefix = 'dir_281ipbv12'
    elif '537ipb' in label:
        init_para_prefix = 'dir_537ipbv12'
    elif '818ipb' in label or 'v13' in label:
        init_para_prefix = 'dir_818ipbv12'
    else:
        raise ValueError(label)

    init_para_base = attr.fitpath

    if dt_type == 'generic':
        if label in ['281ipbv7', '537ipbv7', '818ipbv7']:
            dt_type = 'signal'
    
    tabfile =  tools.set_file('txt', dt_type, mode, tag,
                              prefix=init_para_prefix,
                              extbase=init_para_base)

    sys.stdout.write('Loading init paras from %s ... \n' %tabfile)

    tab     = DHadTable(tabfile)
    
    N1      = float(tab.cell_get('N1', 'Value'))
    N2      = float(tab.cell_get('N2', 'Value'))
    Nbkgd1  = float(tab.cell_get('Nbkgd1', 'Value'))
    Nbkgd2  = float(tab.cell_get('Nbkgd2', 'Value'))
    md      = float(tab.cell_get('md', 'Value'))
    p       = float(tab.cell_get('p', 'Value'))
    sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
    xi      = float(tab.cell_get('xi', 'Value'))

    return N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi
コード例 #14
0
ファイル: __init__.py プロジェクト: xshi/dhad
def get_resolution_paras(mode, label):
    if 'resolution' in label:
        Sigma = 0.005
        Fa = 0.05
        Fb = 0.05
        Sa = 2.0
        Sb = 2.0

    else:
        tab_name='para_momentum_resolution'
        short_label = label.split('/')[0] 
        if short_label in ['281ipbv0', '281ipbv12', '537ipbv12',
                           '818ipbv12', '818ipbv13', 'v13']:
            tab_name = '%s/%s' % (short_label, tab_name)
        else:
            raise NameError(label)

        tab_prefix = ''
        tab_opt_sigma  = 'value'
        tab_opt_fa     = 'value'
        tab_opt_fb     = 'value'
        tab_opt_sa     = 'value'
        tab_opt_sb     = 'value'

        tabfile = tools.set_file(
            extbase=attr.tabpath, prefix=tab_prefix, 
            comname=tab_name, ext='txt')
        sys.stdout.write('Loading lineshape parameters from %s... \n' %tabfile)
        tab = DHadTable(tabfile)
        line_no = attr.mode_line_dict[mode]
        Sigma = float(tab.cell_get(line_no, 'sigma (MeV)',tab_opt_sigma))/1000
        Fa    = float(tab.cell_get(line_no, 'fa', tab_opt_fa))
        Fb    = float(tab.cell_get(line_no, 'fb', tab_opt_fb))
        Sa    = float(tab.cell_get(line_no, 'sa', tab_opt_sa))
        Sb    = float(tab.cell_get(line_no, 'sb', tab_opt_sb))
        
    return Sigma, Fa, Fb, Sa, Sb
コード例 #15
0
ファイル: genericyields.py プロジェクト: xshi/dhad
def generic_yields_single(fo, prefix, opt='', label='', verbose=0):
    #sys_err = attr.sys_err(label)

    dt_type = 'g'
    tag     = 's'

    #sys_err_by_mode = attr.sys_err_by_mode(label)

    for mode in modes:
        if opt == 'statonly':
            syerrmul = 0
        else:
            syerrmul = sys_err_by_mode[mode]['ST Background modeling']
            if mode ==0:
                lepton_veto = sys_err_by_mode[mode]['Lepton veto']
                syerrmul = math.sqrt(syerrmul**2+ lepton_veto**2)
                
        input_file = tools.set_file('txt', dt_type, mode, tag,
                                    prefix=prefix, extbase=attr.fitpath)
        tab    = DHadTable(input_file)
        N1     = tab.cell_get(1, 'Value')
        N1_err = tab.cell_get(1, 'Error')
        N1_err_sys = str(float(N1)*syerrmul)

        N2     = tab.cell_get(2, 'Value')
        N2_err = tab.cell_get(2, 'Error')
        N2_err_sys = str(float(N2)*syerrmul)

        fo.write('%s\n%s\n%s\n' % (N1, N1_err, N1_err_sys))
        fo.write('%s\n%s\n%s\n' % (N2, N2_err, N2_err_sys))

        if verbose > 1:
            print '%s +/- %s +/- %s'  % (N1, N1_err, N1_err_sys)
            print '%s +/- %s +/- %s'  % (N2, N2_err, N2_err_sys)
    if verbose >0:
        print 'single tag generic yield finished.'
コード例 #16
0
def get_dcsd_sys(label, i, j):
    if label in ['818ipbv7']:
        sys_err = attr.sys_err(label)
        dcsd_sys = float(sys_err['Double DCSD interference(Neutral DT)'])
        dcsd_cor = None
    elif label in ['818ipbv8', '818ipbv9', '818ipbv10']:
        tabdir = '818ipbv7'
        tabfile = os.path.join(attr.cbxtabpath, tabdir, 'dcsd_correction.txt')
        tab = DHadTable(tabfile)
        modename = '%s %s' % (modes[i]['fname'], modes[j]['fnamebar'])
        dcsd_val_err = tab.cell_get(modename, 'Yield correction factor')
        dcsd_cor = float(dcsd_val_err.split('+/-')[0])
        dcsd_sys = float(dcsd_val_err.split('+/-')[1])
    else:
        raise NameError(lable)

    return dcsd_sys, dcsd_cor
コード例 #17
0
ファイル: genericyields.py プロジェクト: xshi/dhad
def get_dcsd_sys(label, i, j):
    if label in ['818ipbv7']:
        sys_err = attr.sys_err(label)
        dcsd_sys = float(sys_err['Double DCSD interference(Neutral DT)'])
        dcsd_cor = None
    elif label in ['818ipbv8', '818ipbv9', '818ipbv10']:
        tabdir = '818ipbv7'
        tabfile = os.path.join(attr.cbxtabpath, tabdir,
                               'dcsd_correction.txt')
        tab = DHadTable(tabfile)
        modename = '%s %s' %(modes[i]['fname'], modes[j]['fnamebar'])
        dcsd_val_err = tab.cell_get(modename, 'Yield correction factor')
        dcsd_cor = float(dcsd_val_err.split('+/-')[0])
        dcsd_sys = float(dcsd_val_err.split('+/-')[1])
    else:
        raise NameError(lable)

    return dcsd_sys, dcsd_cor 
コード例 #18
0
ファイル: genericyields.py プロジェクト: xshi/dhad
def generic_yields_double(fo, prefix, opt='', label='', verbose=0):
    dt_type = 'g'
    tag     = 'd'
    mode_pair_list = attr.PossibleDoubleTags
    n = 0 

    for mode_pair in mode_pair_list:
        i = mode_pair[0]
        j = mode_pair[1]
        txtfile = tools.set_file('txt', dt_type, mode_pair, tag, 
                                 prefix=prefix, extbase=attr.fitpath)
        tab    = DHadTable(txtfile)
        N      = tab.cell_get(1, 'Value')
        N_err  = tab.cell_get(1, 'Error')

        if 'DCSD_0' in opt :
            dcsd_sys = 0
            
        if opt == 'statonly':
            syerrmul = 0

        else:
            syerrmul = 0
            if i in (0, 1, 3):
                dcsd_sys, dcsd_cor = get_dcsd_sys(label, i, j)
                syerrmul += dcsd_sys**2
                if dcsd_cor != None:
                    sys.stdout.write(
                        'Correcting mode (%s %s) with %s +/- %s ...\n' %(
                        i,j,dcsd_cor, dcsd_sys))
                    N = str(float(N)*dcsd_cor)

            syerrmul = syerrmul**.5

        N_err_sys = str(float(N)*syerrmul)
        fo.write('%s\n%s\n%s\n' % (N, N_err, N_err_sys))
        n += 1
        if verbose > 1:
            print '%s +/- %s +/- %s'  % (N, N_err, N_err_sys)

    if verbose >0:
        print 'Total double tag generic yield lines ... %s' %n
コード例 #19
0
ファイル: __init__.py プロジェクト: zhixing1996/dhad
def init_paras_single(label, dt_type, tag, mode):

    if '281ipb' in label:
        init_para_prefix = 'dir_281ipbv12'
    elif '537ipb' in label:
        init_para_prefix = 'dir_537ipbv12'
    elif '818ipb' in label or 'v13' in label:
        init_para_prefix = 'dir_818ipbv12'
    else:
        raise ValueError(label)

    init_para_base = attr.fitpath

    if dt_type == 'generic':
        if label in ['281ipbv7', '537ipbv7', '818ipbv7']:
            dt_type = 'signal'

    tabfile = tools.set_file('txt',
                             dt_type,
                             mode,
                             tag,
                             prefix=init_para_prefix,
                             extbase=init_para_base)

    sys.stdout.write('Loading init paras from %s ... \n' % tabfile)

    tab = DHadTable(tabfile)

    N1 = float(tab.cell_get('N1', 'Value'))
    N2 = float(tab.cell_get('N2', 'Value'))
    Nbkgd1 = float(tab.cell_get('Nbkgd1', 'Value'))
    Nbkgd2 = float(tab.cell_get('Nbkgd2', 'Value'))
    md = float(tab.cell_get('md', 'Value'))
    p = float(tab.cell_get('p', 'Value'))
    sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
    xi = float(tab.cell_get('xi', 'Value'))

    return N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi
コード例 #20
0
import modes

sys.stdout.write('Loading syserr_818ipbv12.2 ...')
## ----------------------------------------------------------
##  Systematic  Errors
## ----------------------------------------------------------

tabdir = '818ipbv12'
tabfile = os.path.join(attr.cbxtabpath, tabdir, 'mode_dependent_syst.txt')
sys.stdout.write('from %s ...' % tabfile)
tab = DHadTable(tabfile)
tab.data_trim(factor=0.01)

sys_err_by_mode = {
    0: {
        'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kpi')),
        'Lepton veto': float(tab.cell_get('Lepton veto', 'Kpi'))
    },
    1: {
        'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kpipi0'))
    },
    3: {
        'ST Background modeling': float(tab.cell_get('Bkgd shape', 'K3pi'))
    },
    200: {
        'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kpipi'))
    },
    201: {
        'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kpipipi0'))
    },
    202: {
コード例 #21
0
ファイル: syserr_818ipbv12_4.py プロジェクト: xshi/dhad
import modes 

sys.stdout.write('Loading syserr_818ipbv12.4 ...')
## ----------------------------------------------------------
##  Systematic  Errors
## ----------------------------------------------------------

tabdir = '818ipbv12.4'
tabfile = os.path.join(attr.cbxtabpath, tabdir,
                       'mode_dependent_syst.txt')
sys.stdout.write('from %s ...' % tabfile)
tab = DHadTable(tabfile)
tab.data_trim(factor=0.01)

sys_err_by_mode = {
    0: {'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kpi')),
        'Lepton veto'           : float(tab.cell_get('Lepton veto', 'Kpi'))
        },
    1: {'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kpipi0'))
        },
    3: {'ST Background modeling':  float(tab.cell_get('Bkgd shape', 'K3pi'))
        },
    200: {'ST Background modeling':  float(tab.cell_get('Bkgd shape', 'Kpipi'))
          },
    201: {'ST Background modeling':  float(tab.cell_get('Bkgd shape', 'Kpipipi0'))
          },
    202: {'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kspi'))
          },
    203: {'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Kspipi0'))
          },
    204: {'ST Background modeling': float(tab.cell_get('Bkgd shape', 'Ks3pi'))
コード例 #22
0
ファイル: brf.py プロジェクト: xshi/dhad
def yields_and_efficiencies(opts, args):
    label = args[0]
    prefix = 'dir_'+label
    
    yldfile = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                             comname='yields_and_efficiencies')
    
    f = UserFile()

    single_modes = [(pair, sign) for pair in modes for sign in [-1, 1]]

    input_label = label
    if '.' in label:
        input_label = label.split('.')[0]
        
    prefix='dir_'+input_label+'/crossfeeds'

    dt_type = 'signal'
    for x in single_modes:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fname)
        txtfile  = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yield', 'Value')
        yld = tab.cell_trim(yld, rnd='.000001')
        
        ratio = tab.cell_get('ratio', 'Value')
        ratio = tab.cell_trim(ratio, rnd='.000001')

        f.data.append('%s: %s %s %s\n' % (fname, entries, yld, ratio))
        
    for x, y  in [(x, y) for x in single_modes for y in single_modes if x!=y]:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']
        if y[1] == 1:
            unameb = modes[y[0]]['uname']
            fnameb = modes[y[0]]['fname']
        else:
            unameb = modes[y[0]]['unamebar']
            fnameb = modes[y[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fnameb)
        txtfile  = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yld', 'Value')
        ylderr = tab.cell_get('yld', 'Error')
        
        try:
            float(yld)/float(ylderr)
        except:
            sys.stdout.write('The original ylderr is %s, set to 1.0e10.\n' % ylderr)
            ylderr = 1.0e10
            
        yldsigma = str(float(yld)/float(ylderr))
        yldsigma = tab.cell_trim(yldsigma, rnd='.000001')
        
        yld = tab.cell_trim(yld, rnd='.000001')

        ratio = str(float(yld)/float(entries))
        ratio = tab.cell_trim(ratio, rnd='.000001')

        ratioerr = str(float(ylderr)/float(entries))
        ratioerr = tab.cell_trim(ratioerr, rnd='.000001')

        f.data.append('%s fakes %s: %s %s %s %s %s\n' % (
            fname, fnameb, yldsigma, entries, yld, ratio, ratioerr))
       
    f.output(yldfile, verbose=1)
    return yldfile
コード例 #23
0
ファイル: backgrounds.py プロジェクト: zhixing1996/dhad
def fit_backgrounds_single(datatype, modes, label, test):
    epsname = '%s_background' % (datatype.replace('/', '_'))
    epspath = os.path.join(attr.figpath, label)
    epsfile = set_file(extbase=epspath, comname=epsname, ext='eps')

    if test:
        epsfile = epsfile + '.test'

    input_label = label

    ROOT.gROOT.SetBatch(1)
    ROOT.gROOT.SetStyle('Plain')

    mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV')
    mbc_aset = ROOT.RooArgSet(mbc)

    ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV')

    dflav = ROOT.RooCategory('dflav', 'D0 flavor')
    dflav.defineType('dflav', 1)
    dflav.defineType('dbarflav', -1)

    dataset_args = ROOT.RooArgList(mbc, ebeam, dflav)

    arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89,
                                 'GeV')
    arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1)
    yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000)
    bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000)

    sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV')

    mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV')
    mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV')

    gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma)
    gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma)

    argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope)
    sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf',
                               ROOT.RooArgList(gauss_d0, argus),
                               ROOT.RooArgList(yld, bkg))
    sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf',
                               ROOT.RooArgList(gauss_dp, argus),
                               ROOT.RooArgList(yld, bkg))

    Extended = ROOT.RooFit.Extended(ROOT.kTRUE)
    Save = ROOT.RooFit.Save(ROOT.kTRUE)
    Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE)
    Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE)

    if '281ipb' in label:
        prefix = 'dir_281ipbv7'
    elif '537ipb' in label:
        prefix = 'dir_537ipbv7'
    elif '818ipb' in label:
        prefix = 'dir_818ipbv7'
    else:
        raise NameError(label)

    c1 = ROOT.TCanvas('c1', 'canvas1', 800, 1000)
    #c1.SetFixedAspectRatio(0)
    c1.Divide(3, 3)
    pad = 1
    for mode in modes:
        mode_root_name = get_mode_root_name(mode)
        if datatype == 'generic/ddbar':
            frametitle = 'Generic faking %s' % mode_root_name
        elif datatype == 'generic/cont':
            frametitle = 'Continuum production faking %s' % mode_root_name
        elif datatype == 'generic/tau':
            frametitle = '#tau #tau production faking %s' % mode_root_name
        elif datatype == 'generic/radret':
            frametitle = 'Radiative return faking %s' % mode_root_name
        else:
            raise NameError(datatype)

        c1.cd(pad)
        pad += 1
        comname = '%s_%s' % (datatype.replace('/', '_'), mode)
        bkgpath = os.path.join(attr.bkgpath(), input_label)
        bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt')
        if not os.access(bkgfile, os.F_OK):
            input_prefix = 'dir_%s' % input_label
            bkgfile = set_file(extbase=attr.bkgpath(),
                               dt_type=datatype.replace('/', '_'),
                               tag='s',
                               mode=mode,
                               prefix=input_prefix,
                               comname=comname,
                               ext='evt',
                               forceCombine=1)

        dataset = ROOT.RooDataSet.read(bkgfile, dataset_args)

        if 'D0' in mode:
            pdf = sumpdf_d0
        else:
            pdf = sumpdf_dp

        if 'floatsigma' not in label:
            tab_datatype = 'data'
            tag = 'single'

        tabfile = set_file('txt',
                           tab_datatype,
                           mode,
                           tag,
                           prefix=prefix,
                           extbase=attr.fitpath())

        sys.stdout.write('Using width from %s \n' % tabfile)
        tab = DHadTable(tabfile)
        sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
        sigma.setVal(sigmap1)
        sigma.setConstant(ROOT.kTRUE)

        res = pdf.fitTo(dataset, Extended, Save, Verbose)
        res.Print('v')

        xframe = mbc.frame()
        xframe.SetMarkerSize(0.3)
        if '818ipb' in label and 'noxfeed' in label:
            frame_max = bkg_generic_ddbar_818_max_noxfeed[mode]
            xframe.SetMaximum(frame_max)

        dataset.plotOn(xframe)
        pdf.plotOn(xframe)

        pdf.paramOn(xframe, dataset)

        xframe.SetTitle(frametitle)
        xframe.Draw()

    c1.Print(epsfile)

    if not test:
        tools.eps2png(epsfile)
        tools.eps2pdf(epsfile)
コード例 #24
0
ファイル: backgrounds.py プロジェクト: zhixing1996/dhad
def fit_backgrounds_single_mode(datatype, mode, label, test):
    comname = '%s_%s' % (datatype.replace('/', '_'), mode)
    input_label = label
    if 'nogaus' in label:
        input_label = label.split('/')[0]

    bkgpath = os.path.join(attr.bkgpath(), input_label)
    bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt')
    if not os.access(bkgfile, os.F_OK):
        input_prefix = 'dir_%s' % input_label
        bkgfile = set_file(extbase=attr.bkgpath(),
                           dt_type=datatype.replace('/', '_'),
                           tag='s',
                           mode=mode,
                           prefix=input_prefix,
                           comname=comname,
                           ext='evt',
                           forceCombine=1)

    epspath = os.path.join(attr.figpath, label)
    epsfile = set_file(extbase=epspath, comname=comname, ext='eps')

    txtpath = os.path.join(attr.fitpath(), label)
    txtfile = set_file(extbase=txtpath, comname=comname, ext='txt')

    if test:
        epsfile = epsfile + '.test'
        txtfile = txtfile + '.test'

    ROOT.gROOT.SetBatch(1)
    ROOT.gROOT.SetStyle('Plain')

    mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV')
    mbc_aset = ROOT.RooArgSet(mbc)

    ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV')

    dflav = ROOT.RooCategory('dflav', 'D0 flavor')
    dflav.defineType('dflav', 1)
    dflav.defineType('dbarflav', -1)

    dataset_args = ROOT.RooArgList(mbc, ebeam, dflav)

    dataset = ROOT.RooDataSet.read(bkgfile, dataset_args)

    arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89,
                                 'GeV')
    arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1)
    yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000)
    bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000)

    sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV')

    pars = [arg_cutoff, arg_slope, bkg, sigma, yld]

    mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV')
    mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV')

    gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma)
    gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma)

    argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope)
    sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf',
                               ROOT.RooArgList(gauss_d0, argus),
                               ROOT.RooArgList(yld, bkg))
    sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf',
                               ROOT.RooArgList(gauss_dp, argus),
                               ROOT.RooArgList(yld, bkg))

    Extended = ROOT.RooFit.Extended(ROOT.kTRUE)
    Save = ROOT.RooFit.Save(ROOT.kTRUE)
    Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE)
    Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE)

    if 'D0' in mode:
        pdf = sumpdf_d0
    else:
        pdf = sumpdf_dp

    if 'nogaus' in label:
        yld.setVal(1)
        yld.setConstant(ROOT.kTRUE)
        pars.remove(yld)

    if 'floatsigma' not in label:
        datatype = 'data'
        tag = 'single'

        if '281ipb' in label:
            prefix = 'dir_281ipbv7'
            frame_max = bkg_generic_ddbar_281_max[mode]
        elif '537ipb' in label:
            prefix = 'dir_537ipbv7'
            frame_max = bkg_generic_ddbar_537_max[mode]
        elif '818ipb' in label:
            prefix = 'dir_818ipbv7'
            frame_max = bkg_generic_ddbar_818_max[mode]
            if 'noxfeed' in label:
                frame_max = bkg_generic_ddbar_818_max_noxfeed[mode]

        else:
            raise NameError(label)

        tabfile = set_file('txt',
                           datatype,
                           mode,
                           tag,
                           prefix=prefix,
                           extbase=attr.fitpath())

        sys.stdout.write('Using width from %s \n' % tabfile)
        tab = DHadTable(tabfile)
        sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
        sigma.setVal(sigmap1)
        sigma.setConstant(ROOT.kTRUE)
        pars.remove(sigma)

    res = pdf.fitTo(dataset, Extended, Save, Verbose)
    res.Print('v')
    c1 = ROOT.TCanvas('c1', 'canvas1', 600, 600)
    c1.SetFixedAspectRatio(0)

    xframe = mbc.frame()

    xframe.SetMaximum(frame_max)
    xframe.SetMarkerSize(0.3)
    dataset.plotOn(xframe)
    pdf.plotOn(xframe)
    nfitParam = len(pars)
    chisq_ndof = xframe.chiSquare(nfitParam)

    nbin = xframe.GetNbinsX()
    ndof = nbin - nfitParam
    chisq = chisq_ndof * ndof

    chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC')
    chisqbox.SetFillColor(0)
    chisqbox.SetBorderSize(1)
    chisqbox.AddText('#chi^{2}/ndof = %.3f/%d =  %.3f' %
                     (chisq, ndof, chisq_ndof))
    xframe.addObject(chisqbox)

    pdf.paramOn(xframe, dataset)

    xframe.SetTitle('Generic faking %s' % mode)
    xframe.Draw()

    c1.Print(epsfile)
    tools.save_fit_result(pars, txtfile)

    if not test:
        tools.eps2png(epsfile)
        tools.eps2pdf(epsfile)
コード例 #25
0
ファイル: sidebands.py プロジェクト: zhixing1996/dhad
def fit_sidebands_single_mode(datatype, mode, label, test):
    load_roofit_lib(datatype, label)

    dt_type = datatype.replace('/', '_')
    modekey = tools.get_modekey(mode)

    comname = '%s_%s' % (dt_type, mode)
    input_label = label

    sdbpath = os.path.join(attr.evtpath, input_label)
    sdbfile = set_file(extbase=sdbpath, comname=comname, ext='evt')

    has_charge_conjugate = False
    if '__' in mode:
        has_charge_conjugate = True

    if not os.access(sdbfile, os.F_OK):
        if has_charge_conjugate:
            sdbfile = set_file(extbase=sdbpath,
                               dt_type=dt_type,
                               tag='s',
                               mode=modekey,
                               comname=comname,
                               ext='evt',
                               forceCombine=1)
        else:
            raise ValueError(sdbfile)

    epspath = os.path.join(attr.figpath, label)
    epsfile = set_file(extbase=epspath, comname=comname, ext='eps')

    txtpath = os.path.join(attr.fitpath, label)
    txtfile = set_file(extbase=txtpath, comname=comname, ext='txt')

    if test:
        epsfile = epsfile + '.test'
        txtfile = txtfile + '.test'

    ROOT.gROOT.SetBatch(1)
    ROOT.gROOT.SetStyle('Plain')

    mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV')
    mbc_aset = ROOT.RooArgSet(mbc)

    ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV')

    dflav = ROOT.RooCategory('dflav', 'D0 flavor')

    dflav.defineType('dflav', 1)
    dflav.defineType('dbarflav', -1)

    dataset_args = ROOT.RooArgList(mbc, ebeam, dflav)

    dataset = ROOT.RooDataSet.read(sdbfile, dataset_args)

    arg_cutoff = ebeam
    arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1)
    arg_power = ROOT.RooRealVar('arg_power', 'Argus power', 0.5, 0.1, 1.5)

    yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000)
    bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000)

    sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV')

    pars = [arg_slope, arg_power, bkg, sigma, yld]

    mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV')
    mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV')

    gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma)
    gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma)

    argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope,
                            arg_power)
    sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf',
                               ROOT.RooArgList(gauss_d0, argus),
                               ROOT.RooArgList(yld, bkg))
    sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf',
                               ROOT.RooArgList(gauss_dp, argus),
                               ROOT.RooArgList(yld, bkg))

    Extended = ROOT.RooFit.Extended(ROOT.kTRUE)  # e
    Save = ROOT.RooFit.Save(ROOT.kTRUE)  # r
    Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE)  # no h
    Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE)  # no q

    if 'D0' in mode:
        pdf = sumpdf_d0
    else:
        pdf = sumpdf_dp

    if has_charge_conjugate:
        yld_bar = ROOT.RooRealVar('yield_bar', 'Dbar yield', 100, 0, 200000)
        bkg_bar = ROOT.RooRealVar('bkg_bar', 'Background Bar', 100, 0, 1000000)
        pars.extend([yld_bar, bkg_bar])

        mbc_d0bar = ROOT.RooRealVar('mbc_d0bar', 'D0Bar Mbc', 1.8647, 'GeV')
        mbc_dm = ROOT.RooRealVar('mbc_dm', 'D- Mbc', 1.8694, 'GeV')

        gauss_d0bar = ROOT.RooGaussian('gauss_d0bar', 'D0bar gaussian', mbc,
                                       mbc_d0bar, sigma)
        gauss_dm = ROOT.RooGaussian('gauss_dm', 'D- gaussian', mbc, mbc_dm,
                                    sigma)

        sumpdf_d0bar = ROOT.RooAddPdf('sumpdf_d0bar', 'D0bar sum pdf',
                                      ROOT.RooArgList(gauss_d0bar, argus),
                                      ROOT.RooArgList(yld_bar, bkg_bar))
        sumpdf_dm = ROOT.RooAddPdf('sumpdf_dm', 'Dm sum pdf',
                                   ROOT.RooArgList(gauss_dm, argus),
                                   ROOT.RooArgList(yld_bar, bkg_bar))

        pdf = ROOT.RooSimultaneous('totalPdf', 'totalPdf', dflav)

        if 'D0' in mode:
            pdf.addPdf(sumpdf_d0, 'dflav')
            pdf.addPdf(sumpdf_d0bar, 'dbarflav')
        else:
            pdf.addPdf(sumpdf_dp, 'dflav')
            pdf.addPdf(sumpdf_dm, 'dbarflav')

    if 'nogaus' in label:
        yld.setVal(1)
        yld.setConstant(ROOT.kTRUE)
        pars.remove(yld)

    if 'floatsigma' not in label:
        datatype = 'data'
        tag = 'single'

        if '818ipb' in label:
            prefix = 'dir_818ipbv12'
            frame_max = 1500  #bkg_generic_ddbar_818_max[mode]
        else:
            raise NameError(label)

        tabfile = set_file('txt',
                           datatype,
                           modekey,
                           tag,
                           prefix=prefix,
                           extbase=attr.fitpath)

        sys.stdout.write('Using width from %s \n' % tabfile)
        tab = DHadTable(tabfile)
        sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
        sigma.setVal(sigmap1)
        sigma.setConstant(ROOT.kTRUE)
        pars.remove(sigma)

    #res = pdf.fitTo(dataset, Extended, Save, Verbose)
    res = pdf.fitTo(dataset, 'emr')  #Migrad only, no MINOS
    res.Print('v')

    if not has_charge_conjugate:
        canvas = ROOT.TCanvas('canvas', 'canvas1', 600, 600)
        canvas.SetFixedAspectRatio(0)

        xframe = mbc.frame()

        xframe.SetMaximum(frame_max)
        xframe.SetMarkerSize(0.3)
        dataset.plotOn(xframe)
        pdf.plotOn(xframe)
        nfitParam = len(pars)
        chisq_ndof = xframe.chiSquare(nfitParam)

        nbin = xframe.GetNbinsX()
        ndof = nbin - nfitParam
        chisq = chisq_ndof * ndof

        chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC')
        chisqbox.SetFillColor(0)
        chisqbox.SetBorderSize(1)
        chisqbox.AddText('#chi^{2}/ndof = %.2f/%d =  %.2f' %
                         (chisq, ndof, chisq_ndof))
        xframe.addObject(chisqbox)

        pdf.paramOn(xframe, dataset)

        xframe.SetTitle('Sidebands of %s' % mode)
        xframe.GetYaxis().SetTitleSize(0.03)
        xframe.GetYaxis().SetLabelSize(0.03)
        xframe.GetYaxis().SetTitleOffset(1.8)
        xframe.GetXaxis().SetTitleSize(0.03)
        xframe.GetXaxis().SetLabelSize(0.03)
        xframe.GetXaxis().SetTitleOffset(1.2)
        xframe.Draw()
    else:
        canvas = ROOT.TCanvas('canvas', 'mbc', 1200, 400)
        canvas.Divide(3, 1)
        title1 = attr.modes[modekey]['uname']
        title2 = attr.modes[modekey]['unamebar']

        canvas_1 = canvas.GetListOfPrimitives().FindObject('canvas_1')
        canvas_2 = canvas.GetListOfPrimitives().FindObject('canvas_2')
        canvas_1.SetLogy()
        canvas_2.SetLogy()

        ebeam.setBins(900)

        canvas.cd(1)
        mbcFrame = mbc.frame()
        mbcFrame = mbc.frame(60)
        dflav.setLabel('dflav')
        ebeam_aset = ROOT.RooArgSet(ebeam, dflav)
        ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", ebeam_aset,
                                     dataset)

        Cut = ROOT.RooFit.Cut("dflav==dflav::dflav")

        LineColor = ROOT.RooFit.LineColor(ROOT.kRed)
        LineWidth = ROOT.RooFit.LineWidth(1)
        #Slice = ROOT.RooFit.Slice(dflav, 'dflav')
        Slice = ROOT.RooFit.Slice(dflav)

        ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata)

        dataset.plotOn(mbcFrame, Cut)
        mbcFrame.getAttMarker().SetMarkerSize(0.6)
        mbcFrame.Draw()

        pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData)

        nfitParam = len(pars) - 2
        chisq_ndof = mbcFrame.chiSquare(nfitParam)

        nbin = mbcFrame.GetNbinsX()
        ndof = nbin - nfitParam
        chisq = chisq_ndof * ndof

        chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC')
        chisqbox.SetFillColor(0)
        chisqbox.SetBorderSize(1)
        chisqbox.AddText('#chi^{2}/ndof = %.2f/%d =  %.2f' %
                         (chisq, ndof, chisq_ndof))

        mbcFrame.addObject(chisqbox)

        mbcFrame.SetTitle(title1)
        mbcFrame.Draw()

        canvas.cd(2)
        mbcFrame = mbc.frame()
        mbcFrame = mbc.frame(60)
        dflav.setLabel('dbarflav')

        ebeam_aset = ROOT.RooArgSet(ebeam, dflav)
        ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", ebeam_aset,
                                     dataset)

        Cut = ROOT.RooFit.Cut("dflav==dflav::dbarflav")

        LineColor = ROOT.RooFit.LineColor(ROOT.kRed)
        LineWidth = ROOT.RooFit.LineWidth(1)
        #Slice = ROOT.RooFit.Slice(dflav, 'dbarflav')
        Slice = ROOT.RooFit.Slice(dflav)

        ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata)

        dataset.plotOn(mbcFrame, Cut)
        mbcFrame.getAttMarker().SetMarkerSize(0.6)
        mbcFrame.Draw()

        pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData)

        nfitParam = len(pars) - 2
        chisq_ndof = mbcFrame.chiSquare(nfitParam)

        nbin = mbcFrame.GetNbinsX()
        ndof = nbin - nfitParam
        chisq = chisq_ndof * ndof

        chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC')
        chisqbox.SetFillColor(0)
        chisqbox.SetBorderSize(1)
        chisqbox.AddText('#chi^{2}/ndof = %.2f/%d =  %.2f' %
                         (chisq, ndof, chisq_ndof))

        mbcFrame.addObject(chisqbox)

        mbcFrame.SetTitle(title2)
        mbcFrame.Draw()

        canvas.cd(3)
        mbcFrame = mbc.frame()

        paramWin1 = pdf.paramOn(mbcFrame, dataset, "", 2, "NELU", 0.1, 0.9,
                                0.9)
        mbcFrame.GetXaxis().SetLabelSize(0)
        mbcFrame.GetXaxis().SetTickLength(0)
        mbcFrame.GetXaxis().SetLabelSize(0)
        mbcFrame.GetXaxis().SetTitle("")
        mbcFrame.GetXaxis().CenterTitle()

        mbcFrame.GetYaxis().SetLabelSize(0)
        mbcFrame.GetYaxis().SetTitleSize(0.03)
        mbcFrame.GetYaxis().SetTickLength(0)

        paramWin1.getAttText().SetTextSize(0.06)

        mbcFrame.Draw()
        mbcFrame.SetTitle("Fit Parameters")
        mbcFrame.Draw()

    canvas.Print(epsfile)
    tools.save_fit_result(pars, txtfile)

    if not test:
        tools.eps2png(epsfile)
        tools.eps2pdf(epsfile)
コード例 #26
0
ファイル: sidebands.py プロジェクト: xshi/dhad
def fit_sidebands_single_mode(datatype, mode, label, test):
    load_roofit_lib(datatype, label)

    dt_type=datatype.replace('/', '_')
    modekey = tools.get_modekey(mode)
    
    comname = '%s_%s' %(dt_type, mode)
    input_label = label

    sdbpath = os.path.join(attr.evtpath, input_label)
    sdbfile = set_file(extbase=sdbpath, comname=comname, ext='evt')

    has_charge_conjugate = False
    if '__' in mode:
        has_charge_conjugate = True
    
    if not os.access(sdbfile, os.F_OK):
        if has_charge_conjugate:
            sdbfile = set_file(extbase=sdbpath, dt_type=dt_type,
                               tag='s', mode=modekey, 
                               comname=comname, ext='evt', forceCombine=1)
        else:
            raise ValueError(sdbfile)
        
    epspath = os.path.join(attr.figpath, label)    
    epsfile = set_file(extbase=epspath, comname=comname, ext='eps')

    txtpath = os.path.join(attr.fitpath, label)    
    txtfile = set_file(extbase=txtpath, comname=comname, ext='txt')

    if test:
        epsfile = epsfile + '.test'
        txtfile = txtfile + '.test'

    ROOT.gROOT.SetBatch(1)
    ROOT.gROOT.SetStyle('Plain')

    mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV')
    mbc_aset = ROOT.RooArgSet(mbc)

    ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV')

    dflav = ROOT.RooCategory('dflav','D0 flavor')

    dflav.defineType('dflav',1)
    dflav.defineType('dbarflav',-1)

    dataset_args = ROOT.RooArgList(mbc, ebeam, dflav)

    dataset = ROOT.RooDataSet.read(sdbfile, dataset_args)

    arg_cutoff = ebeam
    arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1)
    arg_power = ROOT.RooRealVar('arg_power', 'Argus power', 0.5, 0.1, 1.5)
    
    yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000)
    bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000)

    sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV')

    pars = [arg_slope, arg_power, bkg, sigma, yld]
    
    mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV')
    mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV')
    
    gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma)
    gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma)

    argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope,
                            arg_power)
    sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf',
                          ROOT.RooArgList(gauss_d0, argus),
                          ROOT.RooArgList(yld, bkg))
    sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf',
                               ROOT.RooArgList(gauss_dp, argus),
                               ROOT.RooArgList(yld, bkg))


    Extended = ROOT.RooFit.Extended(ROOT.kTRUE)  # e
    Save = ROOT.RooFit.Save(ROOT.kTRUE)          # r
    Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE)       # no h
    Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE)   # no q 

    if 'D0' in mode:
        pdf = sumpdf_d0
    else:
        pdf = sumpdf_dp


    if has_charge_conjugate:
        yld_bar = ROOT.RooRealVar('yield_bar', 'Dbar yield', 100, 0, 200000)
        bkg_bar = ROOT.RooRealVar('bkg_bar', 'Background Bar', 100, 0, 1000000)
        pars.extend([yld_bar, bkg_bar])

        mbc_d0bar = ROOT.RooRealVar('mbc_d0bar', 'D0Bar Mbc', 1.8647, 'GeV')
        mbc_dm = ROOT.RooRealVar('mbc_dm', 'D- Mbc', 1.8694, 'GeV')
        
        gauss_d0bar = ROOT.RooGaussian('gauss_d0bar', 'D0bar gaussian',
                                       mbc, mbc_d0bar, sigma)
        gauss_dm = ROOT.RooGaussian('gauss_dm', 'D- gaussian',
                                    mbc, mbc_dm, sigma)
        
        sumpdf_d0bar = ROOT.RooAddPdf('sumpdf_d0bar', 'D0bar sum pdf',
                                      ROOT.RooArgList(gauss_d0bar, argus),
                                      ROOT.RooArgList(yld_bar, bkg_bar))
        sumpdf_dm = ROOT.RooAddPdf('sumpdf_dm', 'Dm sum pdf',
                                   ROOT.RooArgList(gauss_dm, argus),
                                   ROOT.RooArgList(yld_bar, bkg_bar))

        pdf = ROOT.RooSimultaneous('totalPdf', 'totalPdf', dflav)

        if 'D0' in mode:
            pdf.addPdf(sumpdf_d0, 'dflav')
            pdf.addPdf(sumpdf_d0bar, 'dbarflav')
        else:
            pdf.addPdf(sumpdf_dp, 'dflav')
            pdf.addPdf(sumpdf_dm, 'dbarflav')
            

    if 'nogaus' in label:
        yld.setVal(1)
        yld.setConstant(ROOT.kTRUE)
        pars.remove(yld)

    if 'floatsigma' not in label:
        datatype = 'data'
        tag = 'single'

        if '818ipb' in label:
            prefix = 'dir_818ipbv12'
            frame_max = 1500 #bkg_generic_ddbar_818_max[mode]
        else:
            raise NameError(label)


        tabfile = set_file('txt', datatype, modekey, tag,
                           prefix=prefix,
                           extbase=attr.fitpath)

        sys.stdout.write('Using width from %s \n' %tabfile)
        tab = DHadTable(tabfile)
        sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
        sigma.setVal(sigmap1)
        sigma.setConstant(ROOT.kTRUE)
        pars.remove(sigma)
        
    #res = pdf.fitTo(dataset, Extended, Save, Verbose)
    res = pdf.fitTo(dataset, 'emr') #Migrad only, no MINOS
    res.Print('v')


    if not has_charge_conjugate:
        canvas = ROOT.TCanvas('canvas', 'canvas1', 600, 600)
        canvas.SetFixedAspectRatio(0)
        
        xframe = mbc.frame()
        
        xframe.SetMaximum(frame_max)
        xframe.SetMarkerSize(0.3)
        dataset.plotOn(xframe)
        pdf.plotOn(xframe)
        nfitParam = len(pars)
        chisq_ndof = xframe.chiSquare(nfitParam)
        
        nbin = xframe.GetNbinsX()
        ndof = nbin - nfitParam
        chisq = chisq_ndof * ndof
    
        chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC')
        chisqbox.SetFillColor(0)
        chisqbox.SetBorderSize(1)
        chisqbox.AddText('#chi^{2}/ndof = %.2f/%d =  %.2f' %
                         (chisq, ndof, chisq_ndof))
        xframe.addObject(chisqbox)

        pdf.paramOn(xframe, dataset)        

        xframe.SetTitle('Sidebands of %s' % mode)
        xframe.GetYaxis().SetTitleSize(0.03) 
        xframe.GetYaxis().SetLabelSize(0.03) 
        xframe.GetYaxis().SetTitleOffset(1.8)
        xframe.GetXaxis().SetTitleSize(0.03) 
        xframe.GetXaxis().SetLabelSize(0.03) 
        xframe.GetXaxis().SetTitleOffset(1.2)
        xframe.Draw()
    else:
        canvas = ROOT.TCanvas('canvas','mbc', 1200, 400);
        canvas.Divide(3,1)
        title1 = attr.modes[modekey]['uname']
        title2 = attr.modes[modekey]['unamebar']
        
        canvas_1 = canvas.GetListOfPrimitives().FindObject('canvas_1')
        canvas_2 = canvas.GetListOfPrimitives().FindObject('canvas_2')
        canvas_1.SetLogy() 
        canvas_2.SetLogy()
        
        ebeam.setBins(900)

        canvas.cd(1)
        mbcFrame=mbc.frame()
        mbcFrame=mbc.frame(60)
        dflav.setLabel('dflav')
        ebeam_aset = ROOT.RooArgSet(ebeam, dflav)
        ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", 
                                     ebeam_aset, dataset)

        Cut = ROOT.RooFit.Cut("dflav==dflav::dflav")

        LineColor = ROOT.RooFit.LineColor(ROOT.kRed)
        LineWidth = ROOT.RooFit.LineWidth(1)
        #Slice = ROOT.RooFit.Slice(dflav, 'dflav')
        Slice = ROOT.RooFit.Slice(dflav)

        ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata)
        
        dataset.plotOn(mbcFrame, Cut)
        mbcFrame.getAttMarker().SetMarkerSize(0.6)
        mbcFrame.Draw()


        pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData)

        nfitParam = len(pars) - 2
        chisq_ndof = mbcFrame.chiSquare(nfitParam)
        
        nbin = mbcFrame.GetNbinsX()
        ndof = nbin - nfitParam
        chisq = chisq_ndof * ndof
    
        chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC')
        chisqbox.SetFillColor(0)
        chisqbox.SetBorderSize(1)
        chisqbox.AddText('#chi^{2}/ndof = %.2f/%d =  %.2f' %
                         (chisq, ndof, chisq_ndof))

        mbcFrame.addObject(chisqbox)

        mbcFrame.SetTitle(title1)
        mbcFrame.Draw()

        canvas.cd(2)
        mbcFrame = mbc.frame()
        mbcFrame=mbc.frame(60)
        dflav.setLabel('dbarflav')

        ebeam_aset = ROOT.RooArgSet(ebeam, dflav)
        ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", 
                                     ebeam_aset, dataset)

        Cut = ROOT.RooFit.Cut("dflav==dflav::dbarflav")

        LineColor = ROOT.RooFit.LineColor(ROOT.kRed)
        LineWidth = ROOT.RooFit.LineWidth(1)
        #Slice = ROOT.RooFit.Slice(dflav, 'dbarflav')
        Slice = ROOT.RooFit.Slice(dflav)

        ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata)
        
        dataset.plotOn(mbcFrame, Cut)
        mbcFrame.getAttMarker().SetMarkerSize(0.6)
        mbcFrame.Draw()


        pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData)

        nfitParam = len(pars) - 2
        chisq_ndof = mbcFrame.chiSquare(nfitParam)
        
        nbin = mbcFrame.GetNbinsX()
        ndof = nbin - nfitParam
        chisq = chisq_ndof * ndof
    
        chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC')
        chisqbox.SetFillColor(0)
        chisqbox.SetBorderSize(1)
        chisqbox.AddText('#chi^{2}/ndof = %.2f/%d =  %.2f' %
                         (chisq, ndof, chisq_ndof))

        mbcFrame.addObject(chisqbox)

        mbcFrame.SetTitle(title2)
        mbcFrame.Draw()


        canvas.cd(3)
        mbcFrame = mbc.frame()
        
        paramWin1 = pdf.paramOn(mbcFrame,dataset,
                                "",2,"NELU",0.1,0.9,0.9)
        mbcFrame.GetXaxis().SetLabelSize(0) 
        mbcFrame.GetXaxis().SetTickLength(0) 
        mbcFrame.GetXaxis().SetLabelSize(0) 
        mbcFrame.GetXaxis().SetTitle("") 
        mbcFrame.GetXaxis().CenterTitle() 
        
        mbcFrame.GetYaxis().SetLabelSize(0) 
        mbcFrame.GetYaxis().SetTitleSize(0.03) 
        mbcFrame.GetYaxis().SetTickLength(0) 
        
        paramWin1.getAttText().SetTextSize(0.06) 
        
        mbcFrame.Draw() 
        mbcFrame.SetTitle("Fit Parameters") 
        mbcFrame.Draw() 
 

    canvas.Print(epsfile)
    tools.save_fit_result(pars, txtfile)

    if not test:
        tools.eps2png(epsfile)
        tools.eps2pdf(epsfile)
コード例 #27
0
ファイル: backgrounds.py プロジェクト: xshi/dhad
def fit_backgrounds_single_mode(datatype, mode, label, test):
    comname = '%s_%s' %(datatype.replace('/', '_'), mode)
    input_label = label
    if 'nogaus' in label:
        input_label = label.split('/')[0]

    bkgpath = os.path.join(attr.bkgpath(), input_label)
    bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt')
    if not os.access(bkgfile, os.F_OK):
        input_prefix = 'dir_%s' % input_label
        bkgfile = set_file(extbase=attr.bkgpath(),
                           dt_type=datatype.replace('/', '_'),
                           tag='s', mode=mode, prefix=input_prefix,
                           comname=comname, ext='evt', forceCombine=1)

    epspath = os.path.join(attr.figpath, label)    
    epsfile = set_file(extbase=epspath, comname=comname, ext='eps')

    txtpath = os.path.join(attr.fitpath(), label)    
    txtfile = set_file(extbase=txtpath, comname=comname, ext='txt')

    if test:
        epsfile = epsfile + '.test'
        txtfile = txtfile + '.test'

    ROOT.gROOT.SetBatch(1)
    ROOT.gROOT.SetStyle('Plain')
    
    mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV')
    mbc_aset = ROOT.RooArgSet(mbc)

    ebeam = ROOT.RooRealVar('ebeam','Ebeam',1.8815,1.892,'GeV')

    dflav = ROOT.RooCategory('dflav','D0 flavor')
    dflav.defineType('dflav',1)
    dflav.defineType('dbarflav',-1)

    dataset_args = ROOT.RooArgList(mbc, ebeam, dflav)

    dataset = ROOT.RooDataSet.read(bkgfile, dataset_args)


    arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89, 'GeV')
    arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1)
    yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000)
    bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000)

    sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV')
    
    pars = [arg_cutoff, arg_slope, bkg, sigma, yld]

    mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV')
    mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV')
    
    gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma)
    gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma)

    argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope)
    sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf',
                          ROOT.RooArgList(gauss_d0, argus),
                          ROOT.RooArgList(yld, bkg))
    sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf',
                               ROOT.RooArgList(gauss_dp, argus),
                               ROOT.RooArgList(yld, bkg))

    Extended = ROOT.RooFit.Extended(ROOT.kTRUE)
    Save = ROOT.RooFit.Save(ROOT.kTRUE)
    Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE)
    Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE)

    if 'D0' in mode:
        pdf = sumpdf_d0
    else:
        pdf = sumpdf_dp


    if 'nogaus' in label:
        yld.setVal(1)
        yld.setConstant(ROOT.kTRUE)
        pars.remove(yld)

    if 'floatsigma' not in label:
        datatype = 'data'
        tag = 'single'

        if '281ipb' in label:
            prefix = 'dir_281ipbv7'
            frame_max = bkg_generic_ddbar_281_max[mode]
        elif '537ipb' in label:
            prefix = 'dir_537ipbv7'
            frame_max = bkg_generic_ddbar_537_max[mode]
        elif '818ipb' in label:
            prefix = 'dir_818ipbv7'
            frame_max = bkg_generic_ddbar_818_max[mode]
            if 'noxfeed' in label:
                frame_max = bkg_generic_ddbar_818_max_noxfeed[mode]

        else:
            raise NameError(label)
        
        tabfile = set_file('txt', datatype, mode, tag,
                           prefix=prefix,
                           extbase=attr.fitpath())

        sys.stdout.write('Using width from %s \n' %tabfile)
        tab = DHadTable(tabfile)
        sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
        sigma.setVal(sigmap1)
        sigma.setConstant(ROOT.kTRUE)
        pars.remove(sigma)
        
    res = pdf.fitTo(dataset, Extended, Save, Verbose)
    res.Print('v')
    c1 = ROOT.TCanvas('c1', 'canvas1', 600, 600)
    c1.SetFixedAspectRatio(0)

    xframe = mbc.frame()
    
    xframe.SetMaximum(frame_max)
    xframe.SetMarkerSize(0.3)
    dataset.plotOn(xframe)
    pdf.plotOn(xframe)
    nfitParam = len(pars)
    chisq_ndof = xframe.chiSquare(nfitParam)

    nbin = xframe.GetNbinsX()
    ndof = nbin - nfitParam
    chisq = chisq_ndof * ndof
    
    chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC')
    chisqbox.SetFillColor(0)
    chisqbox.SetBorderSize(1)
    chisqbox.AddText('#chi^{2}/ndof = %.3f/%d =  %.3f' %
                     (chisq, ndof, chisq_ndof))
    xframe.addObject(chisqbox)

    pdf.paramOn(xframe, dataset)        

    xframe.SetTitle('Generic faking %s' % mode)
    xframe.Draw()

    c1.Print(epsfile)
    tools.save_fit_result(pars, txtfile)

    if not test:
        tools.eps2png(epsfile)
        tools.eps2pdf(epsfile)
コード例 #28
0
ファイル: backgrounds.py プロジェクト: xshi/dhad
def fit_backgrounds_single(datatype, modes, label, test):
    epsname = '%s_background' %(datatype.replace('/', '_'))
    epspath = os.path.join(attr.figpath, label)    
    epsfile = set_file(extbase=epspath, comname=epsname, ext='eps')

    if test:
        epsfile = epsfile + '.test'

    input_label = label

    ROOT.gROOT.SetBatch(1)
    ROOT.gROOT.SetStyle('Plain')
    
    mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV')
    mbc_aset = ROOT.RooArgSet(mbc)

    ebeam = ROOT.RooRealVar('ebeam','Ebeam',1.8815,1.892,'GeV')

    dflav = ROOT.RooCategory('dflav','D0 flavor')
    dflav.defineType('dflav',1)
    dflav.defineType('dbarflav',-1)

    dataset_args = ROOT.RooArgList(mbc, ebeam, dflav)

    arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89, 'GeV')
    arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1)
    yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000)
    bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000)

    sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV')
    

    mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV')
    mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV')
    
    gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma)
    gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma)

    argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope)
    sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf',
                          ROOT.RooArgList(gauss_d0, argus),
                          ROOT.RooArgList(yld, bkg))
    sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf',
                               ROOT.RooArgList(gauss_dp, argus),
                               ROOT.RooArgList(yld, bkg))

    Extended = ROOT.RooFit.Extended(ROOT.kTRUE)
    Save = ROOT.RooFit.Save(ROOT.kTRUE)
    Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE)
    Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE)

    if '281ipb' in label:
        prefix = 'dir_281ipbv7'
    elif '537ipb' in label:
        prefix = 'dir_537ipbv7'
    elif '818ipb' in label:
        prefix = 'dir_818ipbv7'
    else:
        raise NameError(label)

    c1 = ROOT.TCanvas('c1', 'canvas1', 800, 1000)
    #c1.SetFixedAspectRatio(0)
    c1.Divide(3,3)
    pad = 1
    for mode in modes:
        mode_root_name = get_mode_root_name(mode)
        if datatype == 'generic/ddbar':
            frametitle = 'Generic faking %s' % mode_root_name
        elif datatype == 'generic/cont':
            frametitle = 'Continuum production faking %s' % mode_root_name
        elif datatype == 'generic/tau':
            frametitle = '#tau #tau production faking %s' % mode_root_name
        elif datatype == 'generic/radret':
            frametitle = 'Radiative return faking %s' % mode_root_name
        else:
            raise NameError(datatype)
    
        c1.cd(pad)
        pad += 1
        comname = '%s_%s' %(datatype.replace('/', '_'), mode)
        bkgpath = os.path.join(attr.bkgpath(), input_label)
        bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt')
        if not os.access(bkgfile, os.F_OK):
            input_prefix = 'dir_%s' % input_label
            bkgfile = set_file(extbase=attr.bkgpath(),
                               dt_type=datatype.replace('/', '_'),
                               tag='s', mode=mode, prefix=input_prefix,
                               comname=comname, ext='evt', forceCombine=1)

        dataset = ROOT.RooDataSet.read(bkgfile, dataset_args)

        if 'D0' in mode:
            pdf = sumpdf_d0
        else:
            pdf = sumpdf_dp

        if 'floatsigma' not in label:
            tab_datatype = 'data'
            tag = 'single'
        
        tabfile = set_file('txt', tab_datatype, mode, tag,
                           prefix=prefix,
                           extbase=attr.fitpath())

        sys.stdout.write('Using width from %s \n' %tabfile)
        tab = DHadTable(tabfile)
        sigmap1 = float(tab.cell_get('sigmap1', 'Value'))
        sigma.setVal(sigmap1)
        sigma.setConstant(ROOT.kTRUE)
        
        res = pdf.fitTo(dataset, Extended, Save, Verbose)
        res.Print('v')

        xframe = mbc.frame()
        xframe.SetMarkerSize(0.3)
        if '818ipb' in label and 'noxfeed' in label:
            frame_max = bkg_generic_ddbar_818_max_noxfeed[mode]
            xframe.SetMaximum(frame_max)

        dataset.plotOn(xframe)
        pdf.plotOn(xframe)

        pdf.paramOn(xframe, dataset)        

        xframe.SetTitle(frametitle)
        xframe.Draw()

    c1.Print(epsfile)

    if not test:
        tools.eps2png(epsfile)
        tools.eps2pdf(epsfile)
コード例 #29
0
def yields_and_efficiencies(opts, args):
    label = args[0]
    prefix = 'dir_' + label

    yldfile = tools.set_file(extbase=attr.brfpath,
                             prefix=prefix,
                             comname='yields_and_efficiencies')

    f = UserFile()

    single_modes = [(pair, sign) for pair in modes for sign in [-1, 1]]

    input_label = label
    if '.' in label:
        input_label = label.split('.')[0]

    prefix = 'dir_' + input_label + '/crossfeeds'

    dt_type = 'signal'
    for x in single_modes:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fname)
        txtfile = tools.set_file(extbase=attr.fitpath,
                                 prefix=prefix,
                                 comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yield', 'Value')
        yld = tab.cell_trim(yld, rnd='.000001')

        ratio = tab.cell_get('ratio', 'Value')
        ratio = tab.cell_trim(ratio, rnd='.000001')

        f.data.append('%s: %s %s %s\n' % (fname, entries, yld, ratio))

    for x, y in [(x, y) for x in single_modes for y in single_modes if x != y]:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']
        if y[1] == 1:
            unameb = modes[y[0]]['uname']
            fnameb = modes[y[0]]['fname']
        else:
            unameb = modes[y[0]]['unamebar']
            fnameb = modes[y[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fnameb)
        txtfile = tools.set_file(extbase=attr.fitpath,
                                 prefix=prefix,
                                 comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yld', 'Value')
        ylderr = tab.cell_get('yld', 'Error')

        try:
            float(yld) / float(ylderr)
        except:
            sys.stdout.write('The original ylderr is %s, set to 1.0e10.\n' %
                             ylderr)
            ylderr = 1.0e10

        yldsigma = str(float(yld) / float(ylderr))
        yldsigma = tab.cell_trim(yldsigma, rnd='.000001')

        yld = tab.cell_trim(yld, rnd='.000001')

        ratio = str(float(yld) / float(entries))
        ratio = tab.cell_trim(ratio, rnd='.000001')

        ratioerr = str(float(ylderr) / float(entries))
        ratioerr = tab.cell_trim(ratioerr, rnd='.000001')

        f.data.append('%s fakes %s: %s %s %s %s %s\n' %
                      (fname, fnameb, yldsigma, entries, yld, ratio, ratioerr))

    f.output(yldfile, verbose=1)
    return yldfile