Beispiel #1
0
def test(x, y, z, dx, dy, dz1, dz2, zgap):
    global bx, by, bz, bdx, bdy, bdz1, bdz2, bzgap
    (bx, by, bz) = (x, y, z)
    (bdx, bdy, bdz1, bdz2, bzgap) = (dx, dy, dz1, dz2, zgap)
    g = hist.h1(138, 0., 1.38, vals=histogram)
    g /= g.int()
    h = hist.h1(138, 0., 1.38).fill(map(cotT, a))
    h /= h.int()
    p = g.plot(False)
    #  p.add(g.stepsfill(asbiggles=True, color="yellow"))
    p.add(g.steps(asbiggles=True, linetype="dotted"))
    p.add(h.steps(asbiggles=True))
    p.xlabel = r"average cot($\theta$) (solid is MC, dotted is data)"
    #  p.xlabel = r"average cot($\theta$) (no beamspot corrections)"
    p.show()
    p.write_eps("tunes.eps")
p1.add(biggles.LineY(1., linetype="dotted"))
p1.yrange = (0.987, 1.005)
p1.xrange = (min(rnum) - 100, max(rnum) + 100)
p1.x1.label = "Run number"
p1.y1.label = "BarrelBhabha trigger efficiency"
p1.add(
    biggles.PlotLabel(0.5, 0.15,
                      "five outliers, all with suspicious notes in Elog"))
p1.aspect_ratio = 8.5 / 11. / 1.5
# p1.show()
p1.write_eps("/home/mccann/synthesis/lumieff/ptatalk/afterexclude.eps")

effmean, effmeanerr = jt.wmean(zip(eff, efferr))
effsigmas = map(lambda (e, err): (e - effmean) / (err + 1e-10),
                zip(eff, efferr))
p1ahist = hist.h1(100, -5., 5.).fill(effsigmas)
p1a = p1ahist.plot()
p1a.xlabel = "Sigmas away from mean efficiency of " + ("%3.1f%s" %
                                                       (effmean * 100., "%"))
effmeanmean = jt.mean(filter(lambda x: math.fabs(x) < 5, effsigmas))
effstdev = jt.stdev(filter(lambda x: math.fabs(x) < 5, effsigmas))
efffailures = sorted(
    zip(*filter(lambda (r, e): e < -5., zip(rnum, effsigmas)))[0])
addinfobox(p1a, [["stdev", effstdev], ["underflow", p1ahist.underflow]] +
           efffailures,
           numformat="%g")


def effgauss(x):
    return math.exp(-(x - effmeanmean)**2 / 2. / effstdev) / math.sqrt(
        2. * math.pi) / effstdev
    p.add(data.errorbars())
    return mc, p


def chi2(prompt, ratio):
    mc, p = plotit(prompt, ratio)
    p.show()
    c = 0.
    for mv, me, dv, de in zip(mc.vals, mc.errs, data.vals, data.errs):
        c += (mv - dv)**2 / sqrt(me**2 + de**2)
    return c


p = biggles.Table(1, 2)

data = hist.h1(100, 0.7, 1.2, vals=peak2, errs=peak2_err) - (
    hist.h1(100, 0.7, 1.2, vals=cont2, errs=cont2_err) * 0.064825)
mcprompt = hist.h1(100, 0.7, 1.2, vals=mc2mm, errs=mc2mm_err)
mccascade = hist.h1(100, 0.7, 1.2, vals=mc2cas, errs=mc2cas_err)

m = Minuit(chi2, start=[5., 0.5])
m.migrad()
m.minos()
rat2 = mccascade.sum() / mcprompt.sum() * m.values[1]
rat2_err = rat2 * sqrt(
    mccascade.sumerr()**2 / mccascade.sum()**2 +
    mcprompt.sumerr()**2 / mcprompt.sum()**2 +
    ((m.minos_errors[1][0] - m.minos_errors[1][1]) / 2.)**2 / m.values[1])
print rat2, rat2_err
p[0, 0] = plotit(m.values[0], m.values[1])[1]
p[0, 0].x1.label = r"$m_{\mu\mu}/M_\Upsilon$ for $\Upsilon(2S)$"
Beispiel #4
0
fracerrs[0, 0].add(
    biggles.Points(x, y, symboltype="filled circle", symbolsize=0.5))
fracerrs[0, 0].add(biggles.SymmetricErrorBarsY(x, y, yerr))
fracerrs[0, 0].yrange = (0.99, 1.0)
fracerrs[1, 0].add(
    biggles.Points(x, y, symboltype="filled circle", symbolsize=0.5))
fracerrs[1, 0].add(biggles.SymmetricErrorBarsY(x, y, yerr))
fracerrs[1, 0].yrange = (0.8, 1.02)
fracerrs.xlabel = "Run numbers"
fracerrs.ylabel = "BhabhaBarrel trigger efficiency"
fracerrs.show()
fracerrs.write_eps("plottrig_1.eps")

ylow, nlow = zip(*filter(lambda (yi, ni): yi < 0.99, zip(y, n)))
context = biggles.FramedArray(2, 1)
context[0, 0].add(hist.h1(100, 0, 20000).fill(n).steps(True))
context[1, 0].add(biggles.Points(n, y, symboltype="dot"))
context[1, 0].add(
    biggles.Points(list(nlow), list(ylow), symboltype="circle", symbolsize=3))
context.xlabel = "Number of bhabha events"
context.ylabel = "Efficiency and histogram projection"
context.show()
context.write_eps("plottrig_2.eps")

sigmas = []
ymedian = hist.prehist(y).median
for yi, yerri in zip(y, yerr):
    if yerri == 0.:
        sigmas.append(1000.)
    else:
        sigmas.append(float(yi - ymedian) / float(yerri))
# tr2phi = tr1phi + math.pi
# thefunc = lambda x: (64./2./math.pi*(math.atan2(math.cos(x+(x+math.pi)),math.sin(x+(x+math.pi)))+math.pi))
# p = h1(100,0.*math.pi,1.5*math.pi,func=thefunc).plot(False, lines=True)
# p.add(biggles.LineX(0.25*math.pi))
# p.add(biggles.LineX(1.25*math.pi))
# p.show()

phidist = Numeric.zeros(64, 'd')
for r in run.values():
  phidist += r.phi1
  phidist += r.phi2
  phidist += r.phi3
  phidist += r.phi4
  phidist += r.phi5

p = hist.h1(64, 0.25*math.pi, 1.25*math.pi, vals=phidist[::-1]).rootn().plot(False, points=True, errorbars=True)
p.x1.label = r"$\phi$ of SHOWERS (180$\degree$ range) in 0.45 < |cos$\theta$| < 0.7"
p.yrange = (15000,20000)
p.show()
p.write_eps("plottrig2_2.eps")

# block A,B,C versus run
runnumbers = run.keys()
runnumbers.sort()
a = []
aerr = []
b = []
berr = []
c = []
cerr = []
for r in runnumbers:
Beispiel #6
0
    (bdx, bdy, bdz1, bdz2, bzgap) = (dx, dy, dz1, dz2, zgap)
    g = hist.h1(138, 0., 1.38, vals=histogram)
    g /= g.int()
    h = hist.h1(138, 0., 1.38).fill(map(cotT, a))
    h /= h.int()
    p = g.plot(False)
    #  p.add(g.stepsfill(asbiggles=True, color="yellow"))
    p.add(g.steps(asbiggles=True, linetype="dotted"))
    p.add(h.steps(asbiggles=True))
    p.xlabel = r"average cot($\theta$) (solid is MC, dotted is data)"
    #  p.xlabel = r"average cot($\theta$) (no beamspot corrections)"
    p.show()
    p.write_eps("tunes.eps")

test(0., 0., 0., \
     0.000325, 0.000006, \
     0.671*math.sqrt(2)*0.01273, 0.469*math.sqrt(2)*0.01273, \
     0.237)

test(0., 0., 0., 0., 0., 0., 0., 0.237)

(bx, by, bz) = (0., 0., 0.)
(bdx, bdy, bdz1, bdz2, bzgap) = (0., 0., 0., 0., 0.)
h1 = hist.h1(138, 0., 1.38).fill(map(cotT, a))
(bx, by, bz) = (0., 0., 0.)
(bdx, bdy, bdz1, bdz2, bzgap) = (10., 10., 0., 0., 0.)
h2 = hist.h1(138, 0., 1.38).fill(map(cotT, a))
h1 /= h1.int()
h2 /= h2.int()
(h1 - h2).plot().show()
Beispiel #7
0
#   if r in [121899, 121904, 121906, 122080, 122081, 122083, 122091, 122418, 122429, 122586, 122587, 122594, 122430, 122800, 122802]:
#     try:
#       addto_package(cont, r)
#       print "off-res", r
#     except IOError: pass
#   if r in [121969, 121972, 122132, 122136, 122143, 122147, 122133, 122576, 122647, 122816, 122829, 122831, 123043, 122832, 123044]:
#     try:
#       addto_package(peak, r)
#       print "on-res", r
#     except IOError: pass

monte_carlo = hist.h1(60, 0., 1.2, vals=[0, 0, 0, 1.71828, 0, \
2.19225, 3.71552, 3.30049, 7.5774, 7.05072, 12.3834, 13.7737, 18.0992, \
29.5093, 40.0744, 41.3412, 73.1172, 87.5791, 120.026, 131.712, \
190.291, 267.39, 352.673, 431.37, 571.363, 724.011, 839.47, 1140.85, \
1329.17, 1636.02, 2012.1, 2406.28, 2757.2, 3138.12, 3509.24, 4034.42, \
4364.67, 4666.25, 5204.9, 5563.57, 5742.44, 5641.72, 5814.84, 5625.07, \
5534.19, 5022.68, 4576.48, 3929.41, 3390.26, 2701.96, 1812.06, \
1067.65, 641.305, 385.562, 261.084, 148.978, 101.362, 61.5583, \
38.9909, 51.0872])

# for r in initialrunlist:
#   if runsummary[r].kind == 'p' and runsummary[r].res == 3:
#     try:
#       open(basedir+"pickle/db_"+str(r)+".p")
#       print r
#       peak = new_package()
#       addto_package(peak, r)
#       ptoc = float(peak.c_gam)/float(cont.c_gam)
#       histogramize(peak)
#       p = (peak.mh_had_visen - cont.mh_had_visen * ptoc).plot(False, points=True, errorbars=True)
def use_cross_section(csfunc, filename):
    hads = []
    hads_err = []
    for r in testsample:
        c, e = csfunc(r)
        hads.append(c)
        hads_err.append(e)
    hads_center = jt.wmean(zip(hads, hads_err))[0]
    hads_sigs = []
    for r, c, e in zip(testsample, hads, hads_err):
        hads_sigs.append((c - hads_center) / e)
    hads_hist = hist.h1(50, -5, 5).fill(hads_sigs).rootn()

    def gauss(x, a, m, s):
        return a * math.exp(-(x - m)**2 / 2. / s**2) / math.sqrt(
            2. * math.pi) / s

    chipoints = hads_hist.frame + (hads_hist.frame[1] -
                                   hads_hist.frame[0]) / 2.

    def chi2(a, m, s):
        c = 0.
        for i, x in zip(range(len(hads_hist.frame)), chipoints):
            if hads_hist.errs[i] > 0:
                c += (hads_hist.vals[i] -
                      gauss(x, a, m, s))**2 / hads_hist.errs[i]**2
        return c

    # def hist_look(a, m, s):
    #   p = hads_hist.plot()
    #   values = []
    #   for x in chipoints:
    #     values.append(gauss(x, a, m, s))
    #   p.add(biggles.Curve(chipoints, values))
    #   p.show()
    # hist_look(len(testsample)/5., 0, 1)

    m = Minuit(chi2, start=[len(testsample) / 5., 0, 1])
    m.migrad()
    hist_chi2, hist_params, hist_errors = m.fval, m.values, m.errors
    ndf = len(filter(lambda x: x > 0, hads_hist.errs))
    values = []
    for x in chipoints:
        values.append(gauss(x, *hist_params))
    hist_info = [["$\chi^2/ndf$", hist_chi2, "/", ndf], \
                 ["RMS", hist_params[2], "$\pm$", hist_errors[2]]]

    p = biggles.Table(2, 1)
    p[0, 0] = biggles.FramedPlot()
    p[0, 0].add(
        biggles.Points(Numeric.array(hads) / hads_center,
                       range(len(testsample)),
                       type="filled circle"))
    p[0, 0].add(
        biggles.SymmetricErrorBarsX(
            Numeric.array(hads) / hads_center, range(len(testsample)),
            Numeric.array(hads_err) / hads_center))
    p[0, 0].y1.draw_ticklabels = 0
    p[0, 0].x1.label = "$\propto$ hadronic cross-section"
    p[0, 0].add(biggles.LineX(1.))
    p[0, 0].add(biggles.LineY(41.5, type="dashed"))
    l, r = 0.8, 1.2
    p[0, 0].xrange = l, r
    p[0, 0].add(biggles.DataLabel(l + 0.15 * (r - l), 41.5 - 7, "db16"))
    p[0, 0].add(biggles.DataLabel(l + 0.15 * (r - l), 41.5 + 7, "db17"))
    p[0, 1] = hads_hist.plot()
    p[0, 1].add(biggles.Curve(chipoints, values))
    hist.addinfobox(p[0, 1],
                    hist_info,
                    width=0.8,
                    colwidth=[0.2, 0.09, 0.23],
                    corner=1,
                    numformat="%.2g")
    p[0, 1].x1.label = "sigmas away from weighted mean"
    p[0, 1].yrange = 0, 17
    p.aspect_ratio = 8.5 / 11. * 4
    p.show()
    p.write_eps(filename)