コード例 #1
0
def addtogroupsplot2(csfunc):
    combinemap = {}
    combinemap[0] = []
    combinemap[1] = []
    combinemap[2] = []
    combinemap[3] = []
    combinemap[4] = []
    combinemap[5] = []
    combinemap[6] = []
    combinemap[7] = []
    combinemap[8] = []
    combinemap[9] = []
    for r in testsample:
        combinemap[0].append(csfunc(r))
        combinemap[groupify(r)].append(csfunc(r))
    groups = range(1, 10)
    hadgroup = [0] * 9
    hadgroup_err = [0] * 9
    for g in groups:
        hadgroup[g - 1], hadgroup_err[g - 1] = jt.wmean(combinemap[g])
    center_of_groups = jt.wmean(combinemap[0])[0]

    centers, errors = Numeric.array(
        hadgroup) / center_of_groups, Numeric.array(
            hadgroup_err) / center_of_groups
    chi2 = 0.
    for c, e in zip(centers, errors):
        print(c - 1), e
        chi2 += ((c - 1) / e)**2
    print chi2
コード例 #2
0
def addtogroupsplot(p, csfunc, offset, color, kind):
    combinemap = {}
    combinemap[0] = []
    combinemap[1] = []
    combinemap[2] = []
    combinemap[3] = []
    combinemap[4] = []
    combinemap[5] = []
    combinemap[6] = []
    combinemap[7] = []
    combinemap[8] = []
    combinemap[9] = []
    for r in testsample:
        combinemap[0].append(csfunc(r))
        combinemap[groupify(r)].append(csfunc(r))
    groups = range(1, 10)
    hadgroup = [0] * 9
    hadgroup_err = [0] * 9
    for g in groups:
        hadgroup[g - 1], hadgroup_err[g - 1] = jt.wmean(combinemap[g])
    center_of_groups = jt.wmean(combinemap[0])[0]
    tmp = biggles.Points(Numeric.array(groups) + offset,
                         Numeric.array(hadgroup) / center_of_groups,
                         type=kind,
                         color=color)
    p.add(tmp)
    p.add(
        biggles.SymmetricErrorBarsY(Numeric.array(groups) + offset,
                                    Numeric.array(hadgroup) / center_of_groups,
                                    Numeric.array(hadgroup_err) /
                                    center_of_groups,
                                    color=color))
    p.add(biggles.LineY(1., type="longdashed"))
    return tmp
コード例 #3
0
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]

    p = biggles.FramedPlot()
    p.add(
        biggles.Points(range(len(testsample)),
                       Numeric.array(hads) / hads_center,
                       type="filled circle"))
    p.add(
        biggles.SymmetricErrorBarsY(range(len(testsample)),
                                    Numeric.array(hads) / hads_center,
                                    Numeric.array(hads_err) / hads_center))
    p.x1.draw_ticklabels = 0
    p.x1.label = "Runs by index"
    p.y1.label = "Normalized hadronic cross-section"
    p.add(biggles.LineY(1.))
    p.add(biggles.LineX(41.5, type="dashed"))
    l, r = 0.8, 1.2
    p.yrange = l, r + 0.001
    p.add(biggles.DataLabel(41.5 - 10, l + 0.15 * (r - l), "db16"))
    p.add(biggles.DataLabel(41.5 + 10, l + 0.15 * (r - l), "db17"))
    p.aspect_ratio = 8.5 / 11.
    p.show()
    p.write_eps(filename)
コード例 #4
0
def group_correction_factor(gees):
    combine_correction_factor = []
    combine_correction_factor_err = []
    for r, c, e in zip(testsample, correction_factor, correction_factor_err):
        if groupify(r) in gees:
            combine_correction_factor.append(c)
            combine_correction_factor_err.append(e)
    return jt.wmean(
        zip(combine_correction_factor, combine_correction_factor_err))[0]
コード例 #5
0
p1 = biggles.FramedPlot()
p1.add(biggles.Points(rnum, eff, symboltype="filled circle", symbolsize=0.7))
p1.add(biggles.SymmetricErrorBarsY(rnum, eff, efferr))
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")

コード例 #6
0
p.x1.ticklabels = [r"$e^+e^-$", r"$\mu^+\mu^-$", r"$\gamma\gamma$"]
p.x1.range = 0.5, 3.5
p.y1.label = r"all off-$\Upsilon$ luminosity (nb)"
p.show()
p.write_eps("/home/mccann/tmp.ps")

print zip([
    L1ee[0] + L2ee[0] + L3ee[0], L1mm[0] + L2mm[0] + L3mm[0],
    L1gg[0] + L2gg[0] + L3gg[0]
], [
    trueerror2(L1ee, L2ee, L3ee),
    trueerror2(L1mm, L2mm, L3mm),
    trueerror2(L1gg, L2gg, L3gg)
])

(745015.96999999997, 3800.4106992897518),
(761084.32999999996, 4027.7956696546462),
(754823.03553299501, 3890.5976385867111)

print jt.wmean(
    zip([
        L1ee[0] + L2ee[0] + L3ee[0], L1mm[0] + L2mm[0] + L3mm[0],
        L1gg[0] + L2gg[0] + L3gg[0]
    ], [
        trueerror2(L1ee, L2ee, L3ee),
        trueerror2(L1mm, L2mm, L3mm),
        trueerror2(L1gg, L2gg, L3gg)
    ]))

(753334.9594020159, 2253.3621610084865)
コード例 #7
0
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)
コード例 #8
0
for s in scanu3s:
  m = 10358.131397318795
  if s == "dec05": m = 10359.4784845
  if s == "dec19": m = 10357.5457012
  scanfit[s] = Minuit(lambda area, mass, wide, back: chi2(y3sfunc, s, area, mass, wide, back), start=[3.4897, m, 4.317, 0.3497])
  scanfit[s].migrad()
  a, m, w, b = scanfit[s].values
  plotoverlay(y3sfunc, s, a, m, w, b).show()
  print "reduced chi2", scanfit[s].fval/(len(scanen[s])-4), "precision", scanfit[s].errors[0]/scanfit[s].values[0]*100, "%"



areas = []
for s in scanu1s:
  areas.append((scanfit[s].values[0], scanfit[s].errors[0]))
print jt.wmean(areas)[1]/jt.wmean(areas)[0]*100.

areas = []
for s in scanu2s:
  areas.append((scanfit[s].values[0], scanfit[s].errors[0]))
print jt.wmean(areas)[1]/jt.wmean(areas)[0]*100.

areas = []
for s in scanu3s:
  areas.append((scanfit[s].values[0], scanfit[s].errors[0]))
print jt.wmean(areas)[1]/jt.wmean(areas)[0]*100.



p = biggles.Table(5,5)
i = 0