plot background methods and S/B vs energy

def gp_background():
    """ plot background methods and S/B vs energy """
    inDir, outDir = getWorkDirs()
    data, REBIN = OrderedDict(), None
    titles = [ 'SE_{+-}', 'SE@^{corr}_{/Symbol \\261\\261}', 'ME@^{N}_{+-}' ]
    Apm = OrderedDict([
        ('19', 0.026668), ('27', 0.026554), ('39', 0.026816), ('62', 0.026726)
    ])
    fake = np.array([[-1, 1, 0, 0, 0]])
    lines = {'y=0.9': 'lc {} lt 2 lw 3'.format(default_colors[-4])}
    for energy in ['19', '27', '39', '62']:
        ekey = ' '.join([getEnergy4Key(energy), 'GeV'])
        data[ekey] = [[], [], []]
        for didx,dtype in enumerate(['epsPt', 'ngmPt_corr', 'epmPt']):
            for idx,infile in enumerate(glob.glob(os.path.realpath(os.path.join(
                inDir, 'rawdata', energy, 'pt-differential', '%s_*.dat' % dtype
            )))):
                file_url = os.path.realpath(os.path.join(inDir, infile))
                data_import = np.loadtxt(open(file_url, 'rb'))
                if REBIN is None: REBIN = int(data_import[-1][2]*2*1000) # MeV
                data_import[:,4] = data_import[:,3]
                data_import[:,(2,3)] = 0
                if dtype == 'ngmPt_corr':
                    data_import = data_import[data_import[:,0] <= 0.9]
                if dtype == 'epmPt':
                    data_import = data_import[data_import[:,0] > 0.9]
                    data_import[:,(1,4)] *= Apm[energy]
                col = colorscale(default_colors[didx], 1.+idx*0.2)
                momrange =  os.path.basename(infile).split('_')[-1][:-4]
                if idx < 1:
                    data[ekey][0].append(fake)
                    data[ekey][1].append('with lines lt 1 lw 5 lc %s' % col)
                    data[ekey][2].append(titles[didx])
                data[ekey][0].append(data_import)
                data[ekey][1].append('lt 1 lw 3 lc %s pt 0' % col)
                data[ekey][2].append('')
    # unsubtracted background
    make_panel(
        name = '%s/methods' % outDir, dpt_dict = data,
        xr = [0,3.35], yr = [0.9,2e5], ylog = True, lines = lines,
        xlabel = 'dielectron invariant mass, M_{ee} (GeV/c^{2})',
        ylabel = 'counts / %d MeV/c^{2}' % REBIN, layout = '2x2',
        key = ['spacing 1.6', 'nobox'], gpcalls = ['boxwidth 0.002'],
        labels = {
            '{/=20 the lighter the color, the higher the p_{T}}': (1.5, 1e5)
        }, key_subplot_id = 1,
    )
    return 'done'
    # background ratio and acc.corr.
    make_plot(
        name = '%s/ratios%s' % (outDir, energy),
        xr = [0,1.6], yr = [0.95,1.2],
        data = graph_data[3:],
        properties = [
            'with filledcurves lt 1 lw 3 lc %s pt 0' % default_colors[i]
            for i in xrange(2)
        ],
        titles = [
            'SE_{/Symbol \\261\\261} / ME_{/Symbol \\261\\261}',
            'f_{acc} = ME_{+-} / ME_{/Symbol \\261\\261}'
        ],
        xlabel = 'dielectron invariant mass, M_{ee} (GeV/c^{2})',
        ylabel = '', key = [ 'width -2' ],
        labels = { '%s GeV' % energy: (0.4, 0.97) }
    )
    # signal-to-background ratio in rho/omega region vs. energy
    graph_data_sn = []
    for infile in os.listdir(os.path.join(inDir, 'sn')):
        energy = re.compile('\d+').search(infile).group()
        file_url = os.path.join(inDir, 'sn', infile)
        data_import = np.loadtxt(open(file_url, 'rb'))
        mask = (data_import[:,0] > 0.3) & (data_import[:,0] < 0.75)
        data_import = data_import[mask]
        weights = 1./data_import[:,3]
        sn = np.average(data_import[:,1], weights = weights)
        sn_err = np.average((data_import[:,1]-sn)**2, weights = weights)
        graph_data_sn.append([float(getEnergy4Key(energy)), sn, 0, sn_err, 0])
    graph_data_sn = np.array(graph_data_sn)
    make_plot(
        name = '%s/SNvsEnergy' % (outDir), xr = [15,210],
        yr = [1e-3, .11], xlog = True, ylog = True,
        data = [ np.array([[15,0.1,0,0,0],[210,0.1,0,0,0]]), graph_data_sn ],
        properties = [
            'with lines lt 2 lw 4 lc 0',
            'lt 1 lw 3 lc %s pt 18 ps 2' % default_colors[0]
        ],
        titles = ['']*2,
        xlabel = '{/Symbol \326}s_{NN} (GeV)',
        ylabel = 'S/B for 0.3 < M_{ee} < 0.75 GeV/c^{2}',
        lmargin = 0.1, gpcalls = [
            'nokey', 'format x "%g"',
            'xtics (20,"" 30, 40,"" 50, 60,"" 70,"" 80,"" 90, 100, 200)',
        ],
        labels = { 'p+p': (100, 0.09) }
    )
    return 'done'