Exemple #1
0
def generateToy():
    plt.close('all')

    def poly1(x):
        return 2*x/100

    nentries = 100
    p0=0.01
    x = np.arange(0.0, 10, 0.1)
    np.random.seed(12345)
    ROOT.gRandom.SetSeed(8675309)
    poly1_gen = TF1("poly1","2*x",0,10)
    my_rands = []
    for i in range(nentries):
        my_rands.append(poly1_gen.GetRandom())

    fig = plt.figure()
    hist(my_rands,bins=10,histtype='stepfilled',alpha=0.2,label='10 bins',normed=True)
    bb_edges = bayesian_blocks(my_rands,p0=p0)
    hist(my_rands,bins=bb_edges,histtype='stepfilled',alpha=0.2,label='10 bins',normed=True)
    plt.plot(x,poly1(x),'k')
    plt.show()
def generateToy():
    plt.close('all')

    def poly1(x):
        return 2*x/100

    nentries = 100
    p0=0.01
    x = np.arange(0.0, 10, 0.1)
    np.random.seed(12345)
    ROOT.gRandom.SetSeed(8675309)
    poly1_gen = TF1("poly1","2*x",0,10)
    my_rands = []
    for i in xrange(nentries):
        my_rands.append(poly1_gen.GetRandom())

    fig = plt.figure()
    hist(my_rands,bins=10,histtype='stepfilled',alpha=0.2,label='10 bins',normed=True)
    bb_edges = bayesian_blocks(my_rands,p0=p0)
    hist(my_rands,bins=bb_edges,histtype='stepfilled',alpha=0.2,label='10 bins',normed=True)
    plt.plot(x,poly1(x),'k')
    plt.show()
#! /usr/bin/env python

from __future__ import division
import numpy as np
from scipy import stats
from bb.tools.bayesian_blocks_modified import bayesian_blocks
from matplotlib import pyplot as plt
import cPickle as pkl
import scipy.stats as st
import cPickle as pkl
from bb.tools.bb_plotter import make_hist_ratio_blackhole
from bb.tools.hist_tools_modified import hist
import os

plt.close('all')
p0=0.05

current_dir = os.path.dirname(__file__)
bb_dir=os.path.join(current_dir,'../..')
df_data = pkl.load(open(bb_dir+'/files/BH/BH_paper_data.p','rb'))

data_ST_mul8 = df_data[df_data.ST_mul8_BB>=2800].ST_mul8_BB.values

bc,be,_ = hist(data_ST_mul8, p0=p0, bins='blocks', scale='binwidth', log=True)
print be

plt.show()
Exemple #4
0
def bh_ratio_plots(data,
                   mc,
                   be,
                   title='Black Hole Visual Example',
                   save_name='bh_vis_ex',
                   do_ratio=False,
                   signal_mc=None,
                   n_sig=10):
    xlims = (be[0], be[-1])
    ratlims = (0, 6)

    bin_centers = (be[1:] + be[:-1]) / 2

    if do_ratio:
        fig = plt.figure()
        gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
        ax1 = fig.add_subplot(gs[0])
        ax1.set_yscale("log", nonposy='clip')
        ax2 = fig.add_subplot(gs[1], sharex=ax1)
        ax1.grid(True)
        ax2.grid(True)
        # ax2.set_yscale("log", nonposy='clip')
        plt.setp(ax1.get_xticklabels(), visible=False)
        fig.subplots_adjust(hspace=0.001)
        ax1.set_xlim(xlims)
    else:
        fig, ax1 = plt.subplots()
        ax1.set_yscale("log", nonposy='clip')
        ax1.grid(True)
        ax1.set_xlim(xlims)

    # print 'lims'
    bc_d, _ = np.histogram(data, bins=be)
    bc_mc, _ = np.histogram(mc,
                            bins=be,
                            weights=[len(data) / (len(mc))] * (len(mc)))
    hist(data,
         ax=ax1,
         bins=be,
         scale='binwidth',
         histtype='marker',
         markersize=10,
         color='k',
         errorbars=True,
         suppress_zero=True,
         label='Sim Data')

    hist(mc,
         ax=ax1,
         bins=be,
         scale='binwidth',
         weights=[len(data) / (len(mc))] * (len(mc)),
         histtype='stepfilled',
         alpha=0.2,
         label='Sim Background')
    if do_ratio:
        ratio = bc_d / bc_mc
        ratio_err = np.sqrt(bc_d) / bc_mc
        fill_between_steps(ax2,
                           be,
                           ratio + ratio_err,
                           ratio - ratio_err,
                           alpha=0.2,
                           step_where='pre',
                           linewidth=0,
                           color='red')
        ax2.errorbar(bin_centers,
                     ratio,
                     yerr=None,
                     xerr=[
                         np.abs(be[0:-1] - bin_centers),
                         np.abs(be[1:] - bin_centers)
                     ],
                     fmt='ok')
        ax2.set_xlabel(r'$S_T$ (GeV)', fontsize=17)
        ax2.set_ylabel('Data/BG', fontsize=17)
        ax2.get_yaxis().get_major_formatter().set_useOffset(False)
        ax2.axhline(1, linewidth=2, color='r')
        ax2.yaxis.set_major_locator(MaxNLocator(nbins=7, prune='upper'))
        ax2.set_ylim(ratlims)

    ax1.set_ylabel(r'N/$\Delta$x', fontsize=17)
    ax1.set_title(title)
    if not isinstance(signal_mc, type(None)):
        hist(signal_mc,
             ax=ax1,
             bins=be,
             scale='binwidth',
             weights=[n_sig / (len(signal_mc))] * (len(signal_mc)),
             histtype='step',
             linestyle='--',
             linewidth=2,
             label='Sim Signal')

    ax1.legend()
    plt.savefig('figures/{}.pdf'.format(save_name))
    plt.savefig('figures/{}.png'.format(save_name))

    plt.show()
#! /usr/bin/env python

from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
import numpy as np
from scipy import stats
from bb.tools.bayesian_blocks_modified import bayesian_blocks
from matplotlib import pyplot as plt
import six.moves.cPickle as pkl
import scipy.stats as st
import six.moves.cPickle as pkl
from bb.tools.bb_plotter import make_hist_ratio_blackhole
from bb.tools.hist_tools_modified import hist
import os

plt.close('all')
p0=0.05

current_dir = os.path.dirname(__file__)
bb_dir=os.path.join(current_dir,'../..')
df_data = pkl.load(open(bb_dir+'/files/BH/BH_paper_data.p','rb'))

data_ST_mul8 = df_data[df_data.ST_mul8_BB>=2800].ST_mul8_BB.values

bc,be,_ = hist(data_ST_mul8, p0=p0, bins='blocks', scale='binwidth', log=True)
print(be)

plt.show()