Пример #1
0
def get_norm(wdir, kc):
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    tab = {}
    for replica in replicas:
        order = replica['order'][istep]
        #for _ in order: print(_,istep)
        #sys.exit()
        params = replica['params'][istep]
        for i in range(len(order)):
            if order[i][0] == 2:
                reaction = order[i][1]
                idx = order[i][2]
                if reaction not in tab: tab[reaction] = {}
                if idx not in tab[reaction]: tab[reaction][idx] = []
                tab[reaction][idx].append(params[i])

    for reaction in tab:
        for idx in tab[reaction]:
            norm = tab[reaction][idx][:]
            tab[reaction][idx] = {}
            tab[reaction][idx]['mean'] = np.mean(norm)
            tab[reaction][idx]['std'] = np.std(norm)

    return tab
Пример #2
0
def make_figure(wdir,
                task,
                plot_with_factor=True,
                only_best_cluster=True,
                dpi=200):
    ## attribute 'plot_with_factor' is inherited from jet and not yet used
    ## it is kept there because someday it might be useful

    if task == 1:
        print('\nplotting PJET data from %s' % (wdir))
    elif task == 2:
        print('\nplotting PJET data over theory from %s' % (wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    predictions = load('%s/data/predictions-%d.dat' % (wdir, istep))
    if 'pjet' not in predictions['reactions']:
        print('PJET is not in data file')
        return
    labels = load('%s/data/labels-%d.dat' % (wdir, istep))
    cluster = labels['cluster']
    cluster_average_chi2 = labels['cluster_average_chi2']
    best_cluster = np.argmin(cluster_average_chi2)

    data = predictions['reactions']['pjet']

    for idx in data:
        predictions = copy.copy(data[idx]['prediction-rep'])
        del data[idx]['prediction-rep']
        del data[idx]['residuals-rep']
        if only_best_cluster:
            best_predictions = [
                predictions[i] for i in range(len(predictions))
                if cluster[i] == best_cluster
            ]
            data[idx]['thy'] = np.mean(best_predictions, axis=0)
            data[idx]['dthy'] = np.std(best_predictions, axis=0)**0.5
        else:
            all_predictions = [predictions[i] for i in range(len(predictions))]
            data[idx]['thy'] = np.mean(all_predictions, axis=0)
            data[idx]['dthy'] = np.std(all_predictions, axis=0)**0.5

    if task == 1:
        plot_data(wdir, data, istep, dpi, plot_with_factor)
        # for idx in data:
        #     plot_data_separate(wdir, data[idx], istep, idx, dpi, plot_with_factor)
    elif task == 2:
        ## this is copied from jet plot and not yet ready
        plot_data_on_theory(wdir, data, istep, dpi)

    return
Пример #3
0
def plot_obs(wdir, kc):

    print('\nplotting ln data from %s' % (wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    predictions = load('%s/data/predictions-%d.dat' % (wdir, istep))
    data = predictions['reactions']['ln']
    plot_H1(wdir, istep, data[1000])
    plot_ZEUS(wdir, istep, data[2000])
Пример #4
0
def plot_obs(wdir, only_best_cluster=True, dpi=200):

    print('\nplotting dy data from %s' % (wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    predictions = load('%s/data/predictions-%d.dat' % (wdir, istep))
    if 'dy' not in predictions['reactions']:
        print('DY is not in data file')
        return
    labels = load('%s/data/labels-%d.dat' % (wdir, istep))
    cluster = labels['cluster']
    cluster_average_chi2 = labels['cluster_average_chi2']
    best_cluster = np.argmin(cluster_average_chi2)

    data = predictions['reactions']['dy']

    for idx in data:
        predictions = copy.copy(data[idx]['prediction-rep'])
        del data[idx]['prediction-rep']
        del data[idx]['residuals-rep']
        if only_best_cluster:
            best_predictions = [
                predictions[i] for i in range(len(predictions))
                if cluster[i] == best_cluster
            ]
            data[idx]['thy'] = np.mean(best_predictions, axis=0)
            data[idx]['dthy'] = np.std(best_predictions, axis=0)**0.5
        else:
            all_predictions = [predictions[i] for i in range(len(predictions))]
            data[idx]['thy'] = np.mean(all_predictions, axis=0)
            data[idx]['dthy'] = np.std(all_predictions, axis=0)**0.5

    Q2_bins = []
    # Q2_bins.append([30, 40])
    Q2_bins.append([35, 45])  ## label pp:  37 < Q2 < 42   pd: idem
    Q2_bins.append([45, 52])  ## label pp:  47 < Q2 < 49   pd: idem
    Q2_bins.append([52, 60])  ## label pp:  54 < Q2 < 58   pd:  55 < Q2 < 57
    Q2_bins.append([60, 68])  ## label pp:  63 < Q2 < 66   pd:  62 < Q2 < 65
    Q2_bins.append([68, 75])  ## label pp:  70 < Q2 < 73   pd:  70 < Q2 < 72
    Q2_bins.append([100, 140])  ## label pp: 118 < Q2 < 131  pd: 124 < Q2 < 129
    Q2_bins.append([140, 160])  ## label pp: 148 < Q2 < 156  pd: 145 < Q2 < 154
    Q2_bins.append([160, 280])  ## label pp: 173 < Q2 < 222  pd:  73 < Q2 < 280

    plot_ratio(wdir, data, istep, Q2_bins, dpi)

    return
Пример #5
0
def plot_obs(wdir, kc):

    print('\nplotting dy-pion data from %s' % (wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    predictions = load('%s/data/predictions-%d.dat' % (wdir, istep))
    if 'dy-pion' not in predictions['reactions']: return

    data = predictions['reactions']['dy-pion']
    plot_E615(wdir, istep, data[10001])
    plot_NA10(wdir, istep, data[10002], data[10003])

    return
Пример #6
0
def plot_obs(wdir, kc):

    print('\nplotting DY-pion (qT) from %s' % (wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    predictions = load('%s/data/predictions-%d.dat' % (wdir, istep))
    #print(predictions['reactions'].keys())
    if 'pion_qT' not in predictions['reactions']: return

    data = predictions['reactions']['pion_qT']
    plot_E615_Q(wdir, istep, data[1001])
    plot_E615_xF(wdir, istep, data[1002])

    return
Пример #7
0
def gen_dist_from_fitpack(wdir,dist):

    print('\ngenerating  %s tables for benchmark using %s'%(dist,wdir))

    load_config('%s/input.py'%wdir)
    istep=core.get_istep()
    core.mod_conf(istep) #--set conf as specified in istep   

    resman=RESMAN(nworkers=1,parallel=False,datasets=False)
    parman=resman.parman

    jar=load('%s/data/jar-%d.dat'%(wdir,istep))
    replicas=jar['replicas']

    X,Q2=gen_grid(dist)
    qpd=conf[dist]


    nx=len(X)
    nQ2=len(Q2)

    flavs=[-5,-4,-3,-2,-1,1,2,3,4,5,21]
    fmap={-5:'bb',-4:'cb',-3:'sb',-2:'ub',-1:'db'}
    fmap.update({5:'b',4:'c',3:'s',2:'u',1:'d'})
    fmap.update({21:'g'})


    #--gen qpd data per replica
    checkdir('%s/benchmark'%wdir)
    cnt=0
    for par in replicas:
        lprint('progress: %d/%d'%(cnt+1,len(replicas)))
        parman.set_new_params(par)

        data={}
        for _ in Q2:
            data[_]={}
            for flav in flavs:
                data[_][flav]=np.array([qpd.get_xF(x,_,fmap[flav]) for  x in X])
        save(data,'%s/benchmark/%s-%d.dat'%(wdir,dist,cnt))
        cnt+=1
    print
Пример #8
0
def plot_params(wdir,dist,kc):
    load_config('%s/input.py'%wdir)
    istep=core.get_istep()
    replicas = core.get_replicas(wdir) 
    core.mod_conf(istep,replicas[0])

    clusters,colors,nc,cluster_order = classifier.get_clusters(wdir,istep,kc)

    _order = replicas[0]['order'][istep]

    #--get correct order from dist
    order  = []
    idx    = []
    for i in range(len(_order)):
        if _order[i][1] != dist: continue
        order.append(_order[i][2])
        idx.append(i)

    #--get correct params from dist
    params = np.zeros((len(order),len(replicas)))
    for i in range(len(order)):
        for j in range(len(replicas)):
            params[i][j] = replicas[j]['params'][istep][idx[i]]

    #--create plot with enough space for # of parameters
    nrows, ncols = np.ceil(len(order)/5.0), 5
    fig = py.figure(figsize=(ncols*7,nrows*4))
    X = np.linspace(1,len(replicas),len(replicas))

    #--create plot
    for i in range(len(order)):
        ax = py.subplot(nrows,ncols, i+1)
        ax.set_title('%s'%(order[i]), size=20)
        #params = [replicas[j]['params'][istep][i] for j in range(len(replicas))]
        color  = [colors[clusters[j]] for j in range(len(replicas))]
        ax.scatter(X,params[i],color=color) 
        ax.plot(X,np.ones(len(X))*np.average(params[i]),'k--',alpha=0.5)

    filename='%s/gallery/%s-params.png'%(wdir,dist)
    checkdir('%s/gallery'%wdir)
    py.savefig(filename)
    print 'Saving figure to %s'%filename
Пример #9
0
def gen_tables(wdir, dist, file_name, info, info_only=False):

    print('\ngenerating LHAPDF tables for %s using %s' % (dist, wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    core.mod_conf(istep)  #--set conf as specified in istep

    resman = RESMAN(nworkers=1, parallel=False, datasets=False)
    parman = resman.parman

    jar = load('%s/data/jar-%d.dat' % (wdir, istep))
    replicas = jar['replicas']

    #--check order consistency
    order = jar['order']
    parman.order = order

    #--create output dir
    checkdir(wdir + '/data/')
    checkdir(wdir + '/data/%s/' % file_name)

    #--gen lhapdf_data_files
    if info_only == False:
        cnt = 0
        for par in replicas:
            lprint('progress: %d/%d' % (cnt + 1, len(replicas)))
            parman.set_new_params(par)
            X, Q2, table = _gen_table(dist)
            gen_lhapdf_dat_file(X, Q2, table, wdir, file_name, cnt)
            cnt += 1
        print

    #--gen_lhapdf_info_file
    X, Q2 = gen_grid(dist)
    nrep = len(replicas)
    gen_lhapdf_info_file(X, Q2, nrep, wdir, file_name, info)
Пример #10
0
def make_figure(wdir, task, only_best_cluster=True, dpi=200):

    if task == 1:
        print('\nplotting PIDIS data from %s' % (wdir))
    elif task == 2:
        print('\nplotting PIDIS data over theory from %s' % (wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()
    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  #--set conf as specified in istep

    predictions = load('%s/data/predictions-%d.dat' % (wdir, istep))
    if 'pidis' not in predictions['reactions']:
        print('PIDIS is not in data file')
        return
    labels = load('%s/data/labels-%d.dat' % (wdir, istep))
    cluster = labels['cluster']
    cluster_average_chi2 = labels['cluster_average_chi2']
    best_cluster = np.argmin(cluster_average_chi2)

    data = predictions['reactions']['pidis']

    for idx in data:
        predictions = copy.copy(data[idx]['prediction-rep'])
        del data[idx]['prediction-rep']
        del data[idx]['residuals-rep']
        if only_best_cluster:
            best_predictions = [
                predictions[i] for i in range(len(predictions))
                if cluster[i] == best_cluster
            ]
            data[idx]['thy'] = np.mean(best_predictions, axis=0)
            data[idx]['dthy'] = np.std(best_predictions, axis=0)
        else:
            all_predictions = [predictions[i] for i in range(len(predictions))]
            data[idx]['thy'] = np.mean(all_predictions, axis=0)
            data[idx]['dthy'] = np.std(all_predictions, axis=0)

    maps = generate_maps()
    subset_bins = pick_subsets(data)
    # log_list = []

    if task == 1:
        indices = {}
        for idx in data:
            observable = data[idx]['obs'][0]
            target = data[idx]['target'][0]
            collaboration = data[idx]['col'][0]
            if (observable == 'A1') or (observable == 'Apa'):
                if target == 'p':
                    if collaboration.startswith('JLab') != True:
                        if 'Apa_proton' not in indices:
                            indices['Apa_proton'] = []
                        indices['Apa_proton'].append(idx)
                    elif collaboration.startswith('JLabHB(EG1DVCS)') == True:
                        if 'Apa_proton_DVCS' not in indices:
                            indices['Apa_proton_DVCS'] = []
                        indices['Apa_proton_DVCS'].append(idx)
                    elif collaboration.startswith('JLabHB(EG1b)') == True:
                        if 'Apa_proton_EG1b' not in indices:
                            indices['Apa_proton_EG1b'] = []
                        indices['Apa_proton_EG1b'].append(idx)
                elif target == 'd':
                    if collaboration.startswith('JLab') != True:
                        if 'Apa_deuteron' not in indices:
                            indices['Apa_deuteron'] = []
                        indices['Apa_deuteron'].append(idx)
                    elif collaboration.startswith('JLabHB(EG1DVCS)') == True:
                        if 'Apa_deuteron_DVCS' not in indices:
                            indices['Apa_deuteron_DVCS'] = []
                        indices['Apa_deuteron_DVCS'].append(idx)
                    elif collaboration.startswith('JLabHB(EG1b)') == True:
                        if 'Apa_deuteron_EG1b' not in indices:
                            indices['Apa_deuteron_EG1b'] = []
                        indices['Apa_deuteron_EG1b'].append(idx)
            elif (observable == 'A2') or (observable == 'Ape') or (observable
                                                                   == 'Atpe'):
                if target == 'p':
                    if collaboration.startswith('JLab') != True:
                        if 'Ape_proton' not in indices:
                            indices['Ape_proton'] = []
                        indices['Ape_proton'].append(idx)
                elif target == 'd':
                    if collaboration.startswith('JLab') != True:
                        if 'Ape_deuteron' not in indices:
                            indices['Ape_deuteron'] = []
                        indices['Ape_deuteron'].append(idx)

            if target == 'h':
                if 'helium' not in indices:
                    indices['helium'] = []
                indices['helium'].append(idx)

        for key in indices:
            print(key)
            if key == 'Apa_proton':
                data_Apa_proton(wdir, data, indices[key], subset_bins, maps,
                                istep, dpi)
            elif key == 'Apa_proton_DVCS':
                data_Apa_proton_DVCS(wdir, data, indices[key], subset_bins,
                                     maps, istep, dpi)
            elif key == 'Apa_proton_EG1b':
                data_Apa_proton_EG1b(wdir, data, indices[key], subset_bins,
                                     maps, istep, dpi)
            elif key == 'Apa_deuteron':
                data_Apa_deuteron(wdir, data, indices[key], subset_bins, maps,
                                  istep, dpi)
            elif key == 'Apa_deuteron_DVCS':
                data_Apa_deuteron_DVCS(wdir, data, indices[key], subset_bins,
                                       maps, istep, dpi)
            elif key == 'Apa_deuteron_EG1b':
                data_Apa_deuteron_EG1b(wdir, data, indices[key], subset_bins,
                                       maps, istep, dpi)
            elif key == 'Ape_proton':
                data_Ape_proton(wdir, data, indices[key], subset_bins, maps,
                                istep, dpi)
            elif key == 'Ape_deuteron':
                data_Ape_deuteron(wdir, data, indices[key], subset_bins, maps,
                                  istep, dpi)
            elif key == 'helium':
                data_helium(wdir, data, indices[key], subset_bins, maps, istep,
                            dpi)

    elif task == 2:
        plot_data_on_theory(wdir, data, istep, dpi)

    return
Пример #11
0
def get_parameters(wdir, Q2=None):
    load_config('%s/input.py' % wdir)
    istep = core.get_istep()

    replicas = core.get_replicas(wdir)
    ## 'conf' will be modified for each replica individually later in the loop over 'replicas'
    ## the reason for doing this is that 'fix parameters' has to be set correctly for each replica

    if 'ppdf' not in conf['steps'][istep]['active distributions']:
        print('ppdf-proton not in active distribution')
        return

    resman = RESMAN(nworkers=1, parallel=False, datasets=False)
    parman = resman.parman
    parman.order = replicas[0]['order'][
        istep]  ## make sure 'parman' uses the same order as all the replicas do
    # print parman.order

    ppdf = conf['ppdf']

    ## setup kinematics
    if Q2 == None: Q2 = conf['Q20']
    ## get parameters for all flavors of PDF
    print('\ngetting ppdf-parameters from %s at Q2 = %.2f' % (wdir, Q2))

    ## check if any of the shapes are fixed
    shape_1 = []
    shape_2 = []
    shape_3 = []
    for parameter in conf['params']['ppdf']:
        if '1' in parameter:
            shape_1.append(conf['params']['ppdf'][parameter]['fixed'])
        elif '2' in parameter:
            shape_2.append(conf['params']['ppdf'][parameter]['fixed'])
        elif '3' in parameter:
            shape_3.append(conf['params']['ppdf'][parameter]['fixed'])
        else:
            print('there seems to be more than three shapes')
            print(parameter)
            sys.exit('please update script %s' % __file__)

    fixed_shape_1 = False
    fixed_shape_2 = False
    fixed_shape_3 = False
    if (len(shape_1) != 0) and all([_ == True for _ in shape_1]):
        fixed_shape_1 = True
    elif len(shape_1) == 0:
        fixed_shape_1 = True
    if (len(shape_2) != 0) and all([_ == True for _ in shape_2]):
        fixed_shape_2 = True
    elif len(shape_2) == 0:
        fixed_shape_2 = True
    if (len(shape_3) != 0) and all([_ == True for _ in shape_3]):
        fixed_shape_3 = True
    elif len(shape_3) == 0:
        fixed_shape_3 = True

    parameters = {}
    if not fixed_shape_1: parameters[1] = {}
    if not fixed_shape_2: parameters[2] = {}
    if not fixed_shape_3: parameters[3] = {}

    n_replicas = len(replicas)
    for i in range(n_replicas):
        lprint('%d/%d' % (i + 1, n_replicas))

        parman.order = copy.copy(replicas[i]['order'][istep])
        core.mod_conf(istep, replicas[i])
        parman.set_new_params(replicas[i]['params'][istep], initial=True)

        for flavor, value in ppdf.params.iteritems():
            for j in parameters:
                if str(j) in flavor:
                    flavor_key = flavor.replace(str(j), '')
                    if flavor_key not in parameters[j]:
                        parameters[j][flavor_key] = {
                            'n': [],
                            'a': [],
                            'b': [],
                            'c': [],
                            'd': []
                        }

                    parameters[j][flavor_key]['n'].append(value[0])
                    parameters[j][flavor_key]['a'].append(value[1])
                    parameters[j][flavor_key]['b'].append(value[2])
                    parameters[j][flavor_key]['c'].append(value[3])
                    parameters[j][flavor_key]['d'].append(value[4])
                else:
                    pass

    ## remove c or d parameters if fixed in all flavors and shapes
    ## this is to avoid producing empty figures
    shapes_fixed_c = []
    shapes_fixed_d = []
    for shape in parameters:
        flavors_fixed_c = []
        flavors_fixed_d = []
        for flavor in parameters[shape]:
            cs = parameters[shape][flavor]['c']
            ds = parameters[shape][flavor]['d']
            if all([_ == cs[0] for _ in cs]):
                flavors_fixed_c.append(True)
            else:
                flavors_fixed_c.append(False)
            if all([_ == ds[0] for _ in ds]):
                flavors_fixed_d.append(True)
            else:
                flavors_fixed_d.append(False)

        if all(flavors_fixed_c):
            shapes_fixed_c.append(True)
        else:
            shapes_fixed_c.append(False)
        if all(flavors_fixed_d):
            shapes_fixed_d.append(True)
        else:
            shapes_fixed_d.append(False)

    if all(shapes_fixed_c):
        for shape in parameters:
            for flavor in parameters[shape]:
                del parameters[shape][flavor]['c']
        print('parameter c is fixed for shape %s' % shape)
    if all(shapes_fixed_d):
        for shape in parameters:
            for flavor in parameters[shape]:
                del parameters[shape][flavor]['d']
        print('parameter d is fixed for shape %s' % shape)

    print
    checkdir('%s/data' % wdir)
    if Q2 == conf['Q20']:
        save(parameters, '%s/data/ppdf-parameters-%d.dat' % (wdir, istep))
    else:
        save(parameters,
             '%s/data/ppdf-parameters-%d-%f.dat' % (wdir, istep, Q2))
Пример #12
0
def get_moments(wdir, flavors, x_1, x_2, Q2=None):
    load_config('%s/input.py' % wdir)
    istep = core.get_istep()

    replicas = core.get_replicas(wdir)
    ## 'conf' will be modified for each replica individually later in the loop over 'replicas'
    ## the reason for doing this is that 'fix parameters' has to be set correctly for each replica

    if 'ppdf' not in conf['steps'][istep]['active distributions']:
        print('ppdf-proton not in active distribution')
        return

    resman = RESMAN(nworkers=1, parallel=False, datasets=False)
    parman = resman.parman
    parman.order = replicas[0]['order'][istep]
    ## make sure 'parman' uses the same order for active distributions as all the replicas do
    # print parman.order

    ppdf = conf['ppdf']

    ## setup kinematics
    # X = 10.0 ** np.linspace(-3, -1, 100)
    # X = np.append(X, np.linspace(0.1, 0.99, 100))
    if Q2 == None: Q2 = conf['Q20']
    print('\ngenerating momentus for polarized pdf-proton from %s at Q2 = %f' %
          (wdir, Q2))

    ## compute moments for all replicas
    moments = {}
    statistics = {}
    n_replicas = len(replicas)
    for i in range(n_replicas):
        lprint('%d/%d' % (i + 1, n_replicas))

        parman.order = copy.copy(replicas[i]['order'][istep])
        core.mod_conf(istep, replicas[i])
        parman.set_new_params(replicas[i]['params'][istep], initial=True)

        for flavor in flavors:
            if flavor not in moments: moments[flavor] = []
            if flavor not in statistics: statistics[flavor] = {}
            if flavor == 'up':
                func = lambda x: (ppdf.get_xF(x, Q2, 'u') + ppdf.get_xF(
                    x, Q2, 'ub')) / x
            elif flavor == 'dp':
                func = lambda x: (ppdf.get_xF(x, Q2, 'd') + ppdf.get_xF(
                    x, Q2, 'sb')) / x
            elif flavor == 'sp':
                func = lambda x: (ppdf.get_xF(x, Q2, 's') + ppdf.get_xF(
                    x, Q2, 'sb')) / x
            else:
                func = lambda x: ppdf.get_xF(x, Q2, flavor) / x

            moments[flavor].append(quad(func, x_1, x_2)[0])

    for flavor in flavors:
        statistics[flavor]['mean'] = np.mean(moments[flavor])
        statistics[flavor]['standard_deviation'] = np.std(moments[flavor])

    print
    for flavor in flavors:
        print flavor, ': ', statistics[flavor]

    checkdir('%s/data' % wdir)
    if Q2 == conf['Q20']:
        save({
            'Q2': Q2,
            'moments': moments,
            'statistics': statistics
        }, '%s/data/ppdf-moments-%s-to-%s-%d.dat' % (wdir, x_1, x_2, istep))
    else:
        save({
            'Q2': Q2,
            'moments': moments,
            'statistics': statistics
        }, '%s/data/ppdf-moments-%s-to-%s-%d-%f.dat' %
             (wdir, x_1, x_2, istep, Q2))
Пример #13
0
def gen_xf(wdir, flavors, Q2=None):
    load_config('%s/input.py' % wdir)
    istep = core.get_istep()

    replicas = core.get_replicas(wdir)
    ## 'conf' will be modified for each replica individually later in the loop over 'replicas'
    ## the reason for doing this is that 'fix parameters' has to be set correctly for each replica

    if 'ppdf' not in conf['steps'][istep]['active distributions']:
        print('ppdf-proton not in active distribution')
        return

    resman = RESMAN(nworkers=1, parallel=False, datasets=False)
    parman = resman.parman
    parman.order = replicas[0]['order'][istep]
    ## make sure 'parman' uses the same order for active distributions as all the replicas do
    # print parman.order

    ppdf = conf['ppdf']

    ## setup kinematics
    xs = 10.0**np.linspace(-3, -1, 100)
    xs = np.append(xs, np.linspace(0.1, 0.99, 100))
    if Q2 == None: Q2 = conf['Q20']
    print('\ngenerating polarized pdf-proton from %s at Q2 = %f' % (wdir, Q2))

    ## compute xf for all replicas
    xfs = {}
    n_replicas = len(replicas)
    for i in range(n_replicas):
        lprint('%d/%d' % (i + 1, n_replicas))

        ## filter
        #flag=False
        #params=replica['params'][istep]
        #order=replica['order'][istep]
        #for i in range(len(order)):
        #    if order[i][0]!=1:continue
        #    if order[i][1]!='ppdf':continue
        #    #if order[i][2]=='s1 a':
        #    #   if params[i]<-0.9: flag=True
        #if flag: continue

        parman.order = copy.copy(replicas[i]['order'][istep])
        core.mod_conf(istep, replicas[i])
        parman.set_new_params(replicas[i]['params'][istep], initial=True)

        for flavor in flavors:
            if flavor not in xfs: xfs[flavor] = []
            if flavor == 'up':
                func = lambda x: ppdf.get_xF(x, Q2, 'u') + ppdf.get_xF(
                    x, Q2, 'ub')
            elif flavor == 'dp':
                func = lambda x: ppdf.get_xF(x, Q2, 'd') + ppdf.get_xF(
                    x, Q2, 'sb')
            elif flavor == 'sp':
                func = lambda x: ppdf.get_xF(x, Q2, 's') + ppdf.get_xF(
                    x, Q2, 'sb')
            else:
                func = lambda x: ppdf.get_xF(x, Q2, flavor)

            xfs[flavor].append([func(x) for x in xs])
    print
    checkdir('%s/data' % wdir)
    if Q2 == conf['Q20']:
        save({
            'X': xs,
            'Q2': Q2,
            'XF': xfs
        }, '%s/data/ppdf-%d.dat' % (wdir, istep))
    else:
        save({
            'X': xs,
            'Q2': Q2,
            'XF': xfs
        }, '%s/data/ppdf-%d-%f.dat' % (wdir, istep, Q2))
Пример #14
0
def gen_xf(wdir, had, flavors=['g', 'u', 'ub', 'd', 'db', 's', 'sb'], Q2=None):

    fflabel = 'ff%s' % had
    print('\ngenerating ff-%s from %s' % (had, wdir))

    load_config('%s/input.py' % wdir)
    istep = core.get_istep()

    replicas = core.get_replicas(wdir)
    core.mod_conf(istep, replicas[0])  ## set conf as specified in istep

    if fflabel not in conf['steps'][istep]['active distributions']:
        print('ff-%s not in active distribution' % had)
        return

    resman = RESMAN(nworkers=1, parallel=False, datasets=False)
    parman = resman.parman

    jar = load('%s/data/jar-%d.dat' % (wdir, istep))
    ## 'jar' contains parameters and their orders
    replicas = jar['replicas']
    ## 'jar['replicas']' is a list, in which each element is a list of parameters obeying 'jar['order']'

    ff = conf[fflabel]

    ## setup kinematics
    X = np.linspace(0.01, 0.99, 100)
    if Q2 == None: Q2 = conf['Q20']

    ## compute XF for all replicas
    XF = {}
    cnt = 0
    for par in replicas:
        cnt += 1
        lprint('%d/%d' % (cnt, len(replicas)))

        ## filter
        #flag=False
        #params=replica['params'][istep]
        #order=replica['order'][istep]
        #for i in range(len(order)):
        #    if order[i][0]!=1:continue
        #    if order[i][1]!='pdf':continue
        #    #if order[i][2]=='s1 a':
        #    #   if params[i]<-0.9: flag=True
        #if flag: continue

        parman.set_new_params(par, initial=True)

        #print
        #print conf['ffpion'].get_xF(0.5,10.0,'u')
        #print conf['ffkaon'].get_xF(0.5,10.0,'u')
        #print ff.get_xF(0.5,10.0,'u')

        for flavor in flavors:
            if flavor not in XF: XF[flavor] = []
            if flavor == 'c' or flavor == 'cb' or flavor == 'c+cb':
                _Q2 = conf['aux'].mc2 + 1
            elif flavor == 'b' or flavor == 'bb' or flavor == 'b+bb':
                _Q2 = conf['aux'].mb2 + 1
            else:
                _Q2 = Q2
            if flavor == 'u+ub':
                func = lambda x: ff.get_xF(x, _Q2, 'u') + ff.get_xF(
                    x, _Q2, 'ub')
            elif flavor == 'd+db':
                func = lambda x: ff.get_xF(x, _Q2, 'd') + ff.get_xF(
                    x, _Q2, 'db')
            elif flavor == 's+sb':
                func = lambda x: ff.get_xF(x, _Q2, 's') + ff.get_xF(
                    x, _Q2, 'cb')
            elif flavor == 'c+cb':
                func = lambda x: ff.get_xF(x, _Q2, 'c') + ff.get_xF(
                    x, _Q2, 'cb')
            elif flavor == 'b+bb':
                func = lambda x: ff.get_xF(x, _Q2, 'b') + ff.get_xF(
                    x, _Q2, 'bb')
            else:
                func = lambda x: ff.get_xF(x, _Q2, flavor)

            XF[flavor].append([func(x) for x in X])
    #print func(0.5)
    print
    checkdir('%s/data' % wdir)
    if Q2 == conf['Q20']:
        save({
            'X': X,
            'Q2': Q2,
            'XF': XF
        }, '%s/data/ff%s-%d.dat' % (wdir, had, istep))
    else:
        save({
            'X': X,
            'Q2': Q2,
            'XF': XF
        }, '%s/data/ff%s-%d-%d.dat' % (wdir, had, istep, int(Q2)))
Пример #15
0
def print_grouped_parameters(working_directory,
                             distribution_name,
                             i_replica=1):
    ## print parameters from replicas and PDF class to compare
    load_config('%s/input.py' % working_directory)
    istep = core.get_istep()

    replicas = core.get_replicas(working_directory)
    core.mod_conf(istep, replicas[0])  ## set conf as specified in istep

    if distribution_name not in conf['steps'][istep]['active distributions']:
        print('%s-proton is not an active distribution' % distribution_name)
        return

    resman = RESMAN(nworkers=1, parallel=False, datasets=False)
    parman = resman.parman
    parman.order = replicas[0]['order'][
        istep]  ## make sure 'parman' uses the same order as all the replicas do
    # print parman.order

    distribution = conf[distribution_name]

    print('%s parameters in class' % distribution_name)
    core.mod_conf(istep, replicas[i_replica - 1])
    parman.set_new_params(replicas[i_replica - 1]['params'][istep],
                          initial=True)
    for name, value in distribution.params.iteritems():
        if value[0] != 0.0:
            print '%7s: %.5e, %.5e, %.5e, %.5e, %.5e' % (
                name, value[0], value[1], value[2], value[3], value[4])

    print('%s parameters in replicas' % distribution_name)
    orders = []
    unique_orders = []
    values = []
    for i in range(len(replicas[i_replica - 1]['order'][istep])):
        order = replicas[i_replica - 1]['order'][istep][i]
        value = replicas[i_replica - 1]['params'][istep][i]
        if (order[0] == 1) and (order[1] == distribution_name):
            orders.append(order[2])
            unique_orders.append(order[2].split(' ')[0])
            values.append(value)

    unique_orders = list(set(unique_orders))
    for unique_order in unique_orders:
        parameters = []
        all_parameters = {'N': None, 'a': 0.0, 'b': 0.0, 'c': 0.0, 'd': 0.0}
        for i in range(len(orders)):
            if orders[i].split(' ')[0] == unique_order:
                all_parameters[orders[i].split(' ')[1]] = values[i]
        if all_parameters == {
                'N': None,
                'a': 0.0,
                'b': 0.0,
                'c': 0.0,
                'd': 0.0
        }:
            continue
        if all_parameters['N'] == None:
            print '%7s: None, %.5e, %.5e, %.5e, %.5e' % (
                unique_order, all_parameters['a'], all_parameters['b'],
                all_parameters['c'], all_parameters['d'])
        else:
            print '%7s: %.5e, %.5e, %.5e, %.5e, %.5e' % (
                unique_order, all_parameters['N'], all_parameters['a'],
                all_parameters['b'], all_parameters['c'], all_parameters['d'])