Exemple #1
0
def get_random_hist():
    h = Hist(10, -5, 5)
    h.FillRandom('gaus')
    return h
Exemple #2
0
def test_histfactory():

    # create some Samples
    data = Data('data')
    data.hist = get_random_hist()
    a = Sample('QCD')
    b = Sample('QCD')

    for sample in (a, b):
        sample.hist = get_random_hist()
        # include some histosysts
        for sysname in ('x', 'y', 'z'):
            histosys = HistoSys(sysname)
            histosys.high = get_random_hist()
            histosys.low = get_random_hist()
            sample.AddHistoSys(histosys)
        # include some normfactors
        for normname in ('x', 'y', 'z'):
            norm = NormFactor(normname)
            norm.value = 1
            norm.high = 2
            norm.low = 0
            norm.const = False
            sample.AddNormFactor(norm)

    # samples must be compatible here
    c = a + b
    c = sum([a, b])

    # create Channels
    channel_a = Channel('VBF')
    channel_a.data = data
    channel_a.AddSample(a)

    channel_b = Channel('VBF')
    channel_b.data = data
    channel_b.AddSample(b)

    combined_channel = channel_a + channel_b
    combined_channel = sum([channel_a, channel_b])

    # create a Measurement
    meas = Measurement('MyAnalysis')
    meas.AddChannel(channel_a)

    # create the workspace containing the model
    workspace = make_workspace(meas, silence=True)
    with TemporaryFile():
        workspace.Write()

    assert_true(channel_a.GetSample(a.name) is not None)
    channel_a.RemoveSample(a.name)
    assert_true(channel_a.GetSample(a.name) is None)

    assert_true(meas.GetChannel(channel_a.name) is not None)
    meas.RemoveChannel(channel_a.name)
    assert_true(meas.GetChannel(channel_a.name) is None)

    # test split_norm_shape
    nominal = Hist(1, 0, 1)
    nominal.FillRandom('gaus')
    hsys = HistoSys('shape', high=nominal * 1.5, low=nominal * 0.9)
    norm, shape = split_norm_shape(hsys, nominal)
    assert_equal(norm.low, 0.9)
    assert_equal(norm.high, 1.5)
    assert_equal(shape.high[1].value, nominal[1].value)
    assert_equal(shape.low[1].value, nominal[1].value)
Exemple #3
0
# set the random seed
ROOT.gRandom.SetSeed(42)
np.random.seed(42)

# signal distribution
signal = 126 + 10 * np.random.randn(100)
signal_obs = 126 + 10 * np.random.randn(100)

# create histograms
h1 = Hist(30, 40, 200, title='Background', markersize=0)
h2 = h1.Clone(title='Signal')
h3 = h1.Clone(title='Data')
h3.markersize = 1.2

# fill the histograms with our distributions
h1.FillRandom('landau', 1000)
map(h2.Fill, signal)
h3.FillRandom('landau', 1000)
map(h3.Fill, signal_obs)

# set visual attributes
h1.fillstyle = 'solid'
h1.fillcolor = 'green'
h1.linecolor = 'green'
h1.linewidth = 0

h2.fillstyle = 'solid'
h2.fillcolor = 'red'
h2.linecolor = 'red'
h2.linewidth = 0
Exemple #4
0
from style import set_hsg4_style
from rootpy.plotting import Hist
#from rootpy.interactive import wait
from templates import SimplePlot, RatioPlot

import ROOT
ROOT.gROOT.SetBatch()

set_hsg4_style()

hist = Hist(10, 0, 1)
hist.FillRandom('gaus')

plot = SimplePlot(xtitle='X [GeV]', ytitle='Events')
plot.draw('main', hist)
plot.SaveAs('simple.png')

plot = RatioPlot(xtitle='X [GeV]',
                 ytitle='Events',
                 ratio_title='Data / Model',
                 offset=-122,
                 ratio_margin=22,
                 prune_ratio_ticks=True)
plot.draw('main', hist)
plot.SaveAs('ratio.png')
#wait()
Exemple #5
0
def test_init_from_hist():

    h = Hist(100, -10, 10)
    h.FillRandom('gaus')
    g = Graph(h)
Exemple #6
0
def test_poisson_errors():
    h = Hist(20, -3, 3)
    h.FillRandom('gaus')
    g = h.poisson_errors()
Exemple #7
0
def test_init_from_graph():
    hist = Hist(10, 0, 1)
    hist.FillRandom('gaus')
    graph = Graph(hist)
    hist2 = Hist(graph)
Exemple #8
0
def make_plot():
    canvas = Canvas(700, 500)
    hist = Hist(10, -3, 3)
    hist.FillRandom('gaus')
    hist.Draw()
    return canvas
Exemple #9
0
    h_t2Shape.SetBinContent(7, 20)
    h_t2Shape.SetBinContent(8, 20)
    h_t2Shape.SetBinContent(9, 10)
    h_t2Shape.SetBinContent(10, 10)

    h_t3Shape.SetBinContent(1, 20)
    h_t3Shape.SetBinContent(2, 20)
    h_t3Shape.SetBinContent(3, 20)
    h_t3Shape.SetBinContent(4, 50)
    h_t3Shape.SetBinContent(5, 50)
    h_t3Shape.SetBinContent(6, 100)
    h_t3Shape.SetBinContent(7, 100)
    h_t3Shape.SetBinContent(8, 50)
    h_t3Shape.SetBinContent(9, 50)
    h_t3Shape.SetBinContent(10, 40)
    if useT1: h_t1.FillRandom(h_t1Shape, nTemplate)
    if useT2: h_t2.FillRandom(h_t2Shape, nTemplate)
    if useT3: h_t3.FillRandom(h_t3Shape, nTemplate)
    if useT4: h_t4.FillRandom(h_t4Shape, nTemplate)
    pass

# h_data.Scale(nData)
# h_data.FillRandom(  t1Scale * h_t1Shape + t2Scale * h_t2Shape + t3Scale * h_t3Shape, nData )
fillingHistogram = 0
if useT1: fillingHistogram += t1Scale * h_t1Shape
if useT2: fillingHistogram += t2Scale * h_t2Shape
if useT3: fillingHistogram += t3Scale * h_t3Shape
if useT4: fillingHistogram += t4Scale * h_t4Shape

if useDataFromFile:
    h_data = getDataFromFile()