def make_single_space_overlay( histos, filenames, ext="png" ) :

    linestyles=['dotted','solid','dotted']

    filling=['lightgreen','darkgreen','r']

    fs = [ r2m.RootFile(name) for name in filenames  ]
    for hname, options in histos.iteritems() :

        hists = [f.get(hname) for f in fs ]
        cs_sels=[] 

        for hist, lst  in zip(hists, linestyles  ): 
            cs= plt.contour( hist.x, hist.y, hist.content, levels = options["contours"], colors = options["colors"], linewidths = 3, linestyles=lst )
            cs_sels.append(select_segments(cs.allsegs,hist,options))

        fig, axes = initialise_axes_new(hists,options)

        for hist, cs_sel,lst, fill,name in zip(hists, cs_sels,linestyles,filling ,filenames ): 
            plot_segments(axes,cs_sel,options = options,linestyle=lst,filename=name)
            plot_minimum(hist,fill,'darkgreen')
        plot_legend(axes, options)

        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.2)

        print "Save to: ", (fig_name( options, filenames[1] ) + "_overlay.%s" % ext)
        plt.savefig( fig_name( options, filenames[1] ) + "_overlay.%s" % ext )
def make_raw_smooth_overlays( r_s_histos, filename, ext="png" ) : #FIXME: ugly, but it does the job poorly
    f = r2m.RootFile(filename)
    linestyles=['dotted','solid','-.']
    for r_histo, s_histo in r_s_histos :
        r_hname,r_options=r_histo
        s_hname,s_options=s_histo
        fig = plt.figure( figsize=[10,7.5] )
        plt.rcParams.update({'font.size':25,'axes.labelsize':30 })
        try:
            r_hist,s_hist = f.get(r_hname) ,f.get(s_hname) 
        except:
            print "Failed to get {} or {} from {}".format(r_hname, s_hname, filename)
            continue
        xmin  = r_hist.xedges[0]   
        xmax  = r_hist.xedges[-1] 
        ymin, ymax = r_options["zrange1d"]

        
        r_splines=[ get_raw_spline_from_hist(r_hist,r_options), get_raw_spline_from_hist(s_hist,s_options)  ]

        fig = plt.figure( figsize=[10,7.5] )
        plt.axis( [xmin, xmax, ymin, ymax] )
        axes = plt.axes()
        axes.set_xlabel( r_hist.xlabel )
        axes.set_ylabel( r_options["ytitle"] )
        pylab.xticks(pylab.arange( xmin, xmax*1.001, r_options["xticks"] ) )
        for rsp,lst in zip(r_splines,linestyles):
            (rxs,rys)  = rsp 
            plt.plot(rxs,rys,'b',linestyle=lst,linewidth=1)
        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.12)

        print "Saved to: ",(fig_name( r_options, filename ) + "_raw_smooth.%s" % ext)
        plt.savefig( fig_name( r_options, filename ) + "_raw_smooth.%s" % ext )
def make_colour_contour_overlay(colour,contour,filename, ext="png"):
    f = r2m.RootFile(filename)
    for col,cont in zip(colour,contour) :
        hname1,  hname2=col[0],  cont[0]
        options1, options2=col[1] , cont[1]
        hist1 = f.get(hname1)
        hist2 = f.get(hname2)
        # get contours before initialising figure
        cs=plt.contour( hist2.x, hist2.y, hist2.content, levels = options2["contours"], colors = options2["colors"], linewidths = 2 )
        cs_sel=select_segments(cs.allsegs,hist2,options2)
        fig, axes = initialise_axes_new([hist1,hist2],options1)
        # plot colors
        plot_colors(hist1,options1)
#        hist1.colz()
#        plt.clim( *options1["zrange"] )
        # coloured plots should get a title
        if options1.get('title') :    
            axes.set_title( options1["title"] )
        # plot contours
        plot_segments(axes,cs_sel,options= options2)
        # adjust figure so that it looks nice
        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.2)
        plt.gcf().subplots_adjust(right=0.74)
        #save
        print "Save to: ", fig_name( options1, filename ) + "_col_"+options2["mode"] + "_con.%s" % ext
        plt.savefig( fig_name( options1, filename ) + "_col_"+options2["mode"] + "_con.%s" % ext )
Example #4
0
def makeSingle1DPlot(histos, filename, ext="png"):
    i = 0
    f = r2m.RootFile(filename)
    for hname, options in histos.iteritems():
        hist = f.get(hname)
        xmin, xmax = hist.xedges[0], hist.xedges[-1]
        ymin, ymax = options["zrange1d"]
        y, x, patch = hist.hist()

        segs = get_valid_segments(y, options["zrange"][0], options["zrange"][1])
        for seg in segs:
            i += 1
            y[seg[0]] = options["zrange1d"][1]
            y[seg[1]] = options["zrange1d"][1]

            tck = interpolate.splrep(x[seg[0] : seg[1]], y[seg[0] : seg[1]], s=0)
            xnew = np.arange(x[seg[0]], x[seg[1]], (x[seg[1]] - x[seg[0]]) / 200)
            ynew = interpolate.splev(xnew, tck, der=0)
            ynew[-1] = options["zrange1d"][1]
            plt.figure()
            plt.plot(xnew, ynew, "b")
            plt.axis([xmin, xmax, ymin, ymax])
            axes = plt.axes()
            axes.set_xlabel(hist.xlabel)
            axes.set_ylabel(options["title"])
            pylab.xticks(pylab.arange(xmin, xmax + 0.1, options["xticks"]))
            axes.set_title("%s(%s)" % (options["title"], hist.xlabel))
        plt.savefig(fig_name(options, filename) + ".%s" % ext)
def make_single_1d_plot( histos, filename, ext="png" ) :
    f = r2m.RootFile(filename)
    for hname, options in histos.iteritems() :
        hist = f.get(hname)
#        xmin,xmax = hist.xedges[0], hist.xedges[-1]
#        ymin,ymax = options["zrange1d"]
        rxs,rys= get_raw_spline_from_hist(hist,options)
        initialise_axes(hist,options,filename=filename)
        plt.plot(rxs,rys,'b',linestyle='solid',linewidth=3,zorder=2)
        if 'green_band' in options.keys():
            x_min, x_max  = options['green_band']
#            plt.axvspan(xmin= x_min,xmax=x_max,facecolor="#30c048", alpha = 0.4)
            plt.axvspan(xmin= x_min,xmax=x_max,color="#30c048",zorder=1)
        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.15)

        print "Save to: " , fig_name( options, filename ) + ".%s" % ext
        plt.savefig( fig_name( options, filename ) + ".%s" % ext )
def make_single_space_plot( histos, filename, ext="png" ) :
    f = r2m.RootFile(filename)
    for hname, options in histos.iteritems() :
        try:
            hist = f.get(hname)
        except TypeError:
            print "WARNING: skipping {} as not in ROOT file".format(hname)
            continue

        cs=plt.contour( hist.x, hist.y, hist.content, levels = options["contours"], colors = options["colors"], linewidths = 2 )
        cs_sel=select_segments(cs.allsegs,hist,options)

#        fig = plt.figure( figsize=[5,3.75] )
        fig = plt.figure( figsize=[10,7.5] )

        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.20)

#        plt.rcParams.update({ 'legend.fontsize':12})
        plt.rcParams.update({'axes.titlesize':30,'legend.fontsize':16,'axes.labelsize':30,'xtick.labelsize':25, 'ytick.labelsize':25 })
        axes = plt.axes()
        initialise_axes(axes,[hist],options,filename)

        if 'green_band' in options.keys():
            x_min, x_max, axis  = options['green_band']
            hv_axis={'x':'v','y':'h'}[axis]
            eval("plt.ax%sspan(%smin= x_min,%smax=x_max,color='#30c048')" % (hv_axis,axis,axis))

        if options.get('colz'): plot_colors(hist,options)
        plot_segments(axes,cs_sel,options= options)
        x,y =plot_minimum(hist,'gold','gold')
        plot_legend(axes, options)
        if options.get('pickle'):
            import pickle
            output = open('contours.pkl','wb')
            pickle.dump(cs_sel,output)
            out = open('bf.pkl','wb')
            pickle.dump([x,y],out)


#        add_logo(fig)
        print "Save to : ",(fig_name( options, filename ) + ".%s" % ext)
        plt.savefig( fig_name( options, filename ) + ".%s" % ext )
def make_red_band_plot_raw( histos, filename, ext="png", data_file=None):
    f = r2m.RootFile(filename)
    xmin=85
    xmax=140
    for hname, options in histos.iteritems() :
        hist = f.get(hname)

        xs,ys=get_raw_spline_from_hist(hist,options)
        ax = initialise_axes(hist,options, xmin=xmin, xmax=xmax, xmin_offset=5)

        #draw the LEP exclusion
        if  hist.xedges[0] < 114.4:
            plt.axvspan(xmin= xmin,xmax=114.4,color="#FFFF00",zorder=0)
            plt.axvspan(xmin= 124,xmax=126,color="#00FF00",zorder=1)
            x_pos_lhc_label=0.67
#            print x_pos_lhc_label
            plt.figtext(x=0.15,y=0.2, s="LEP \nexcluded",zorder=2 )
            plt.figtext(x=x_pos_lhc_label,y=0.2, s="LHC ",zorder=2 )
        if hist.xedges[-1] > 130 or xmax > 130:
            plt.axvspan(xmin= 130,xmax=xmax,color="#DBBB88",zorder=1)
            plt.figtext(x=0.77,y=0.2, s="Theoretically\nInaccessible",zorder=2 )

        ymax = options["zrange1d"][1]
        collection = get_band_collection(xs,ys,ymax=ymax)
        ax.add_collection(collection) 

        plt.plot(xs,ys,'b',linestyle='solid',linewidth=3,zorder=5)
        model = filename.split('/')[-1].split('_')[0]
        data_file = { 'cmssm': 'cmssm_pre_lhc.csv', 'nuhm1': 'nuhm1_pre_lhc.csv' }[model]
        smoothing = { 'cmssm': 100, 'nuhm1': None }[model]

        if data_file:
            xf,yf = get_xy_from_file(filename=data_file,smoothing=smoothing)
            plt.plot(xf,yf,'b',linestyle='dashed',linewidth=3,zorder=4)

        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.12)

        print "Save to: ", fig_name( options, filename ) + "_raw.%s" % ext 
        plt.savefig( fig_name( options, filename ) + "_raw.%s" % ext )
def make_single_1d_overlay( histos, filenames, ext="png" ) : #FIXME: ugly, but it does the job poorly
    linestyles=['dotted','solid','-.']
    fs = [ r2m.RootFile(name) for name in filenames  ]
    for hname, options in histos.iteritems() :
        fig = plt.figure( figsize=[10,7.5] )
        plt.rcParams.update({'font.size':12,'axes.labelsize':30,'xtick.labelsize':25, 'ytick.labelsize':25 })
        try:
            hists = [f.get(hname) for f in fs ]
        except ReferenceError: 
            print "ERROR: {} is not in one of the files".format(hname)
            continue
        xmins  =[ hist.xedges[0]  for hist in hists ] 
        xmaxs  =[ hist.xedges[-1] for hist in hists ]
        xmin, xmax = min(xmins), max(xmaxs)
        ymin, ymax = options["zrange1d"]

        
        r_splines=[]
        for  hist in  hists  :
            r_splines.append( get_raw_spline_from_hist(hist,options))

        fig = plt.figure( figsize=[10,7.5] )
        plt.axis( [xmin, xmax, ymin, ymax] )
        axes = plt.axes()
        axes.set_xlabel( hist.xlabel )
        axes.set_ylabel( options.get("ytitle",None) )
        pylab.xticks(pylab.arange( xmin, xmax*1.001, options["xticks"] ) )
        from config.file_dict import file_dict
        for rsp,lst,name in zip(r_splines,linestyles,filenames):
            (rxs,rys)  = rsp 
            plt.plot(rxs,rys,'b',linestyle=lst,linewidth=3,label=file_dict.get(name))

#        plt.legend()
        plt.gcf().subplots_adjust(bottom=0.15)
        plt.gcf().subplots_adjust(left=0.15)

        print "Save to: ", fig_name( options, filenames[1] ) + "_overlay.%s" % ext 
        plt.savefig( fig_name( options, filenames[1] ) + "_overlay.%s" % ext )
def makeSingleSpacePlot( histos, filename, ext="png" ) :
    i=0
    f = r2m.RootFile(filename)
    for hname, options in histos.iteritems() :
        hist = f.get(hname)
        i += 1
        fig = plt.figure( figsize=[8,6] )
        xmin,xmax = hist.xedges[0], hist.xedges[-1]
        ymin,ymax = hist.yedges[0], hist.yedges[-1]
        plt.axis( [xmin, xmax, ymin, ymax] )
        axes = plt.axes()
        axes.set_xlabel( hist.xlabel )
        axes.set_ylabel( hist.ylabel )
        hist.contour( levels = options["contours"], colors = options["colors"], linewidths = 2 )
        hist.colz()
        plt.axis( [xmin, xmax, ymin, ymax] )
        plt.clim( *options["zrange"] )
        pylab.yticks(pylab.arange( ymin, ymax+0.1, options["yticks"] ) )
        pylab.xticks(pylab.arange( xmin, xmax+0.1, options["xticks"] ) )
        axes.set_title( options["title"] )
        plt.savefig( fig_name( options, filename ) + ".%s" % ext )