Esempio n. 1
0
def main():
    squid = loadCSVToList('../calc/bfields_leiterschleife_fit.txt')
    theo = loadCSVToList('../calc/bfields_leiterschleife_theo.txt')
    resistors = loadCSVToList('../data/resistors.txt')
    x = [u / r for r, u in resistors]
    sx = [0.01 / r for r, u in resistors]
    ysquid, sysquid = zip(*squid)
    ytheo, sytheo = zip(*theo)

    c = TCanvas('c', '', 1280, 720)

    theoData = DataErrors.fromLists(x, ytheo, sx, sytheo)
    gTheo = theoData.makeGraph('gTheo', 'Strom I / A', 'Magnetfeld B_{z} / T')
    gTheo.SetMarkerColor(2)
    gTheo.SetLineColor(2)
    gTheo.Draw('AP')

    squidData = DataErrors.fromLists(x, ysquid, sx, sysquid)
    gSquid = squidData.makeGraph('gSquid', 'Strom I / A', 'Magnetfeld B_{z} / T')
    gSquid.Draw('P')

    l = TLegend(0.15, 0.7, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(gSquid, 'gemessene Magnetfeldst#ddot{a}rke B_{z}', 'p')
    l.AddEntry(gTheo, 'theoreitsche Magnetfeldst#ddot{a}rke B_{z}', 'p')
    l.Draw()

    c.Update()
    c.Print('../img/compare.pdf', 'pdf')

    c.SetLogy()
    c.SetLogx()
    c.Update()
    c.Print('../img/compare_loglog.pdf', 'pdf')
Esempio n. 2
0
def evalSigmaChannelDatas(datas):
    x = list(zip(*datas))[0]
    sx = list(zip(*datas))[1]
    y = list(zip(*datas))[2]
    sy = list(zip(*datas))[3]
    data = DataErrors.fromLists(x, y, sx, sy)

    c = TCanvas('c_sc', '', 1280, 720)
    g = data.makeGraph('g_sc', 'channel c', '#sigma(channels)')
    g.Draw('AP')
    c.Update()
    c.Print('../img/energieaufloesung_channels.pdf', 'pdf')

    ecallist = loadCSVToList('../calc/ecal_sigmas.txt')
    x, sx, y, sy = list(zip(*ecallist))
    ecaldata = DataErrors.fromLists(x, y, sx, sy)
    
    g.SetMaximum(50)
    g.Draw('AP')
    gecal = ecaldata.makeGraph('g_ecal', 'channel c', '#sigma(channels)')
    gecal.SetMarkerColor(2)
    gecal.SetLineColor(2)
    gecal.Draw('P')

    l = TLegend(0.15, 0.7, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'fitted #sigma of LED-Peaks', 'p')
    l.AddEntry(gecal, 'fitted #sigma of energy calibration peaks', 'p')
    l.Draw()

    c.Update()
    c.Print('../img/energieaufloesung_channels+ecal.pdf', 'pdf')
Esempio n. 3
0
def main():
    z, sz = 840, 40
    d = [210, 106, 75]
    sd = [10, 4, 4]
    calc = list(map(lambda x:-20 * log10(x/z), d))
    scalc = list(map(lambda x:20 * sqrt((x[1]/x[0]) ** 2 + (sz/z)**2) / log(10), zip(*[d, sd])))
    
    data = DataErrors.fromLists(calc, [12, 18, 21], scalc, [0]*3)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured attenuation m / dB', 'nominal value n / dB')
    g.Draw('AP')
    
    fit = Fitter('fit', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 11, 22)
    fit.saveData('../fit/attenuator.txt')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'measured att. vs. nominal value', 'p')
    l.AddEntry(fit.function, 'fit with n = a + b m', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.4f', units=['dB', ''], lang='en')
    l.Draw()
    
    c.Update()
    c.Print('../img/attenuator.pdf', 'pdf')
Esempio n. 4
0
def loadCrossSection(ctype):
    datalist = loadCSVToList('../calc/crosssections_%s.txt' % ctype)
    xlist = list(zip(*datalist))[0]
    sxlist = [0] * len(xlist)
    ylist = list(zip(*datalist))[1]
    sylist = list(zip(*datalist))[2]
    return DataErrors.fromLists(xlist, ylist, sxlist, sylist)
Esempio n. 5
0
def main():
    x, y, sy = zip(*loadCSVToList('../calc/part3/Co-Si_mergedbins.txt'))
    data = DataErrors.fromLists(x, y, [0]*len(x), sy)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanal k', 'Counts N')
    g.SetMarkerStyle(8)
    g.SetMarkerSize(0.5)
    g.SetLineColor(15)
    g.SetLineWidth(0)
    g.Draw('AP')
    
    fit = Fitter('f', '1/(sqrt(2*pi*[2]^2))*gaus(0)')
    fit.setParam(0, 'A', 50)
    fit.setParam(1, 'x_{c}', 690)
    fit.setParam(2, 's', 20)
    fit.fit(g, 672, 712)
    fit.saveData('../calc/part3/fit_Co-Si_01_mergedbins.txt', 'w')
    with TxtFile('../calc/part3/fit_Co-Si_01_mergedbins_raw.txt', 'w') as f:
        for key, param in fit.params.iteritems():
            f.writeline('\t', *map(str, [param['value'], param['error']]))
    
    l = TLegend(0.7, 0.5, 0.95, 0.85)
    l.SetTextSize(0.0225)
    l.AddEntry(g, 'Gemittelte Messwerte', 'p')
    l.AddEntry(fit.function, 'Fit mit', 'l')
    l.AddEntry(0, 'N(k) = #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{x-x_{c}}{#sigma})^{2})', '')
    l.AddEntry(0, '', '')
    fit.addParamsToLegend(l, chisquareformat='%.2f')
    l.Draw()
    
    c.Update()
    c.Print('../img/part3/Co-Si_01_mergedbins.pdf', 'pdf')
Esempio n. 6
0
def loadCrossSection(ctype):
    datalist = loadCSVToList('../calc/crosssections_%s.txt' % ctype)
    xlist = list(zip(*datalist))[0]
    sxlist = [0] * len(xlist)
    ylist = list(zip(*datalist))[1]
    sylist = list(zip(*datalist))[2]
    return DataErrors.fromLists(xlist, ylist, sxlist, sylist)
Esempio n. 7
0
def compareSpectrum(prefix, spectrum, litvals):
    xlist = list(zip(*spectrum))[0]
    sxlist = list(zip(*spectrum))[1]

    compData = DataErrors.fromLists(xlist, litvals, sxlist, [0] * len(litvals))

    c = TCanvas('c_%s_compspectrum' % prefix, '', 1280, 720)
    g = compData.makeGraph('g_%s_compspectrum' % prefix,
                           'experimentell bestimmte HFS-Aufspaltung #Delta#nu^{exp}_{%s} / GHz' % prefix,
                           'theoretische HFS-Aufspaltung #Delta#nu^{theo} / GHz')
    g.Draw('AP')

    fit = Fitter('fit_%s_compspectum' % prefix, 'pol1(0)')
    fit.setParam(0, 'a_{%s}' % prefix, 0)
    fit.setParam(1, 'b_{%s}' % prefix, 1)
    fit.fit(g, compData.getMinX() - 0.5, compData.getMaxX() + 0.5)

    if prefix == "up":
        l = TLegend(0.15, 0.6, 0.45, 0.85)
    else:
        l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Spektrum', 'p')
    l.AddEntry(fit.function, 'Fit mit #Delta#nu^{theo} = a_{%s} + b_{%s} #Delta#nu^{exp}_{%s}' % (prefix, prefix, prefix), 'l')
    fit.addParamsToLegend(l, [('%.2f', '%.2f'), ('%.3f', '%.3f')], chisquareformat='%.2f', units=['GHz', ''])
    l.Draw()

    c.Update()
    if not DEBUG:
        c.Print('../img/part2/%s-spectrum.pdf' % prefix, 'pdf')
Esempio n. 8
0
def main():
    z, sz = 840, 40
    d = [210, 106, 75]
    sd = [10, 4, 4]
    calc = list(map(lambda x: -20 * log10(x / z), d))
    scalc = list(
        map(lambda x: 20 * sqrt((x[1] / x[0])**2 + (sz / z)**2) / log(10),
            zip(*[d, sd])))

    data = DataErrors.fromLists(calc, [12, 18, 21], scalc, [0] * 3)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured attenuation m / dB',
                       'nominal value n / dB')
    g.Draw('AP')

    fit = Fitter('fit', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 11, 22)
    fit.saveData('../fit/attenuator.txt')

    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'measured att. vs. nominal value', 'p')
    l.AddEntry(fit.function, 'fit with n = a + b m', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')),
                          chisquareformat='%.4f',
                          units=['dB', ''],
                          lang='en')
    l.Draw()

    c.Update()
    c.Print('../img/attenuator.pdf', 'pdf')
Esempio n. 9
0
def fitSigma(sigs, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*sigs)
    listy = map(abs, listy)   # fits can yield negative sigma, because it only occurse to
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cSigma', '', 1280, 720)
    g = data.makeGraph('Sigma', 'Zeit t / s', 'Standardabweichung #sigma / cm')
    g.Draw('AP')

    fit = Fitter('fitS', 'sqrt(2*[0]*(x + [1]))')
    fit.setParam(0, 'D_{n}', 100)
    fit.setParam(1, 't_{0}', 0)
    fit.fit(g, 1e-6, 21e-6)
    fit.saveData('../calc/part2/dist_fit_sigma.txt')

    l = TLegend(0.15, 0.625, 0.45, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('Sigma', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit #sigma(t) = #sqrt{2*D_{n}*(t + t_{0})}', 'l')
    fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2e', '%.2e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/dist_fitSigma.pdf', 'pdf')
Esempio n. 10
0
def makeBFit(darkTimes, Bs):
    dt, sdt = list(zip(*darkTimes))
    b, sb = list(zip(*Bs))
    data = DataErrors.fromLists(dt, b, sdt, sb)

    c = TCanvas('c_B', '', 1280, 720)
    g = data.makeGraph('g_B', 'Dunkelzeit t_{D} / ms', 'Fitparameter B / V')
    g.Draw('APX')

    fit = Fitter('fit_B', '[0] + [1] * (1 - exp(-x/[2]))')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0.1)
    fit.setParam(1, 'b', 0.1)
    fit.setParam(2, 'T_{R_{F}}', 6)
    fit.fit(g, 0, 25)
    fit.saveData('../fit/B.txt')

    l = TLegend(0.55, 0.15, 0.85, 0.6)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Fitparameter B', 'p')
    l.AddEntry(fit.function, 'Fit mit B(t_{D}) = a + b (1 - e^{-x/T_{R_{F}}})', 'l')
    fit.addParamsToLegend(l, (('%.3f', '%.3f'), ('%.3f', '%.3f'), ('%.1f', '%.1f')), chisquareformat='%.2f', units=['V', 'V', 'ms'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part6/BFit.pdf', 'pdf')
Esempio n. 11
0
def makeSigmaFit(darkTimes, sigmas):
    dt, sdt = list(zip(*darkTimes))
    s, ss = list(zip(*sigmas))
    data = DataErrors.fromLists(dt, s, sdt, ss)

    c = TCanvas('c_sigma', '', 1280, 720)
    g = data.makeGraph('g_sigma', 'Dunkelzeit t_{D} / ms', 'Verschmierung #sigma / #mus')
    g.Draw('APX')

    fit = Fitter('fit_sigma', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 0, 25)
    fit.saveData('../fit/sigma.txt')

    l = TLegend(0.6, 0.15, 0.85, 0.5)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Verschmierung #sigma', 'p')
    l.AddEntry(None, 'der Fermi-Verteilung', '')
    l.AddEntry(fit.function, 'Fit mit #sigma(t_{D}) = a + b t_{D}', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=['#mus', '10^{-3}'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part6/sigmaFit.pdf', 'pdf')
Esempio n. 12
0
def fitA(amps, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*amps)
    slaser_rel = 0.05
    listsy = list(listsy)
    for i, y in enumerate(listy):
        listsy[i] = y * np.sqrt(listsy[i] ** 2 + slaser_rel ** 2)
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cA', '', 1280, 720)
    g = data.makeGraph('A', 'Zeit t / s', 'Amplitude A / V')
    g.GetYaxis().SetTitleOffset(1.2)
    g.Draw('AP')

    fit = Fitter('A', '[0]*exp(-(x)/[1])+[2]')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'C', 5e-8)
    fit.setParam(1, '#tau_{n}', 45e-6)
    fit.setParam(2, 'a', 0)
    fit.fit(g, 7.5e-6, 18e-6)
    fit.saveData('../calc/part2/volt_fit_A.txt')

    l = TLegend(0.625, 0.625, 0.85, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('A', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit A(t) = C*e^{- #frac{t}{#tau_{n}}} + a', 'l')
    fit.addParamsToLegend(l, [('%.2e', '%.1e'), ('%.2e', '%.1e'), ('%.2e', '%.1e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/volt_fitA.pdf', 'pdf')
        c.SetLogy()
        c.Update()
        c.Print('../img/part2/volt_fitA_log.pdf', 'pdf')
Esempio n. 13
0
File: eval.py Progetto: Bigben37/FP1
def main():
    snu = ERRORS["nu"]  # TODO get error
    sB = ERRORS["B"]
    sgyrorel = 0
    files = ["H", "Glycol", "Teflon"]
    for file in files:
        datalist = loadCSVToList("../data/03-%s.txt" % file)
        if len(datalist) == 1:
            B, nu = datalist[0]
            gyro, sgyro = calcGyro(nu, snu, B, sB)
            if not sgyrorel == 0:
                sgyro = gyro * sgyrorel
            with TxtFile("../calc/%s.txt" % file, "w") as f:
                f.writeline("\t", "gyro", *map(str, (gyro, sgyro)))
                f.writeline("\t", "mu", *map(str, calcMu(gyro, sgyro)))
                f.writeline("\t", "gI", *map(str, calcNucGFactor(gyro, sgyro)))
        else:
            x, y = zip(*datalist)
            sx = [0] * len(x)
            sy = [snu] * len(y)
            data = DataErrors.fromLists(x, y, sx, sy)
            data.setXErrorAbs(sB)
            c = TCanvas("c%s" % file, "", 1280, 720)
            g = data.makeGraph("g%s" % file, "Magnetfeld B / mT", "Resonanzfrequenz #nu / MHz")
            g.Draw("AP")

            fit = Fitter("fit%s" % file, "[0]*x")
            fit.setParam(0, "m", 0.002)
            fit.fit(g, datalist[0][0] * 0.95, datalist[-1][0] * 1.05)
            fit.saveData("../calc/fit-%s.txt" % file, "w")

            l = TLegend(0.15, 0.60, 0.475, 0.85)
            l.SetTextSize(0.03)
            l.AddEntry(g, "Messdaten", "p")
            l.AddEntry(fit.function, "Fit mit #nu(B) = m*B", "l")
            l.AddEntry(0, "", "")
            fit.addParamsToLegend(
                l,
                [("%.5f", "%.5f"), ("%.2f", "%.2f")],
                chisquareformat="%.2f",
                advancedchi=True,
                units=["MHz / mT", "MHz"],
            )
            l.Draw()

            gyro = 2 * np.pi * fit.params[0]["value"] * 1e9  # in Hz / T
            sgyro = 2 * np.pi * fit.params[0]["error"] * 1e9  # in Hz / T
            sgyrorel = sgyro / gyro
            with TxtFile("../calc/%s.txt" % file, "w") as f:
                f.writeline("\t", "gyro", *map(str, (gyro, sgyro)))
                f.writeline("\t", "sgyrorel", str(sgyrorel))
                f.writeline("\t", "mu", *map(str, calcMu(gyro, sgyro)))
                f.writeline("\t", "gI", *map(str, calcNucGFactor(gyro, sgyro)))

            c.Update()
            c.Print("../img/03-%s.pdf" % file, "pdf")
Esempio n. 14
0
def evalEnergyCalibration(peaks, percents):
    maxenergy = 1.95 * 0.87 * 84
    smaxenergy = maxenergy * sqrt((0.05 / 1.95)**2 + (0.01 / 0.87)**2 +
                                  (5 / 84)**2)
    channels = list(list(zip(*peaks))[0])
    schannels = list(list(zip(*peaks))[1])
    energies = list(map(lambda x: x / 100 * maxenergy, percents))
    senergies = list(map(lambda x: x / 100 * smaxenergy, percents))
    print(energies)
    print(senergies)

    with TxtFile('../src/tab_energycalibration.tex', 'w') as f:
        f.write2DArrayToLatexTable(
            list(zip(*[percents, channels, schannels, energies, senergies])),
            ['\% energy', '$c$', '$s_c$', '$E$ / MeV', '$s_E$ / MeV'],
            ['%d', '%.3f', '%.3f', '%.1f', '%.1f'],
            "Channels of fitted peaks and their theoretical energy for the energy calibration.",
            "tab:ecal")

    data = DataErrors.fromLists(channels, energies, schannels, senergies)
    c = TCanvas('c_energycalibration', '', 1280, 720)
    g = data.makeGraph('g_energycalibration', 'channel c', 'energy E / MeV')
    g.Draw('AP')

    fit = Fitter('fit_energycalibration', 'pol1(0)')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1 / 3)
    fit.fit(g, 0, max(channels) + 5)
    fit.saveData('../fit/energyCalibration.txt')

    l = TLegend(0.15, 0.6, 0.575, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Peaks of flight through spectra / pedestal', 'p')
    l.AddEntry(fit.function, 'fit with E(c) = a + b * c', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.3f', '%.3f')),
                          chisquareformat='%.2f',
                          units=('MeV', 'MeV / channel'),
                          lang='en')
    l.Draw()

    c.Update()
    c.Print('../img/energyCalibration.pdf', 'pdf')

    with TxtFile('../calc/energyCalibration.txt', 'w') as f:
        f.writeline('\t', str(fit.params[0]['value']),
                    str(fit.params[0]['error']))
        f.writeline('\t', str(fit.params[1]['value']),
                    str(fit.params[1]['error']))
        f.writeline('\t', str(fit.getCovMatrixElem(0, 1)))
Esempio n. 15
0
def printGraph(datas, phi, name='', fit=False):
    """make graph with measured taus for one specific angle phi

    Arguments:
    datas -- datalists (sorted by series in dictonary)
    phi   -- angle
    name  -- additional name for file name
    fit   -- if true fit data with linear model (default=False)
    """
    # setup canvas and legend
    c = TCanvas('c_%d' % phi, '', 1280, 720)
    if fit:
        l = TLegend(0.6, 0.15, 0.85, 0.5)
    else:
        l = TLegend(0.65, 0.15, 0.85, 0.35)
    l.SetTextSize(0.03)
    # make and draw graphs, graphs are organized by TMultiGraph
    graphs = TMultiGraph()
    for s, datalist in datas.iteritems():
        data = DataErrors.fromLists(*zip(*datalist))
        g = data.makeGraph('g_%d_%d' % (phi, s))
        g.SetMarkerColor(seriescolors[s])
        g.SetLineColor(seriescolors[s])
        l.AddEntry(g, serieslabels[s], 'p')
        graphs.Add(g)
    graphs.Draw('AP')
    gPad.Update()
    setMultiGraphTitle(graphs, 'Druck p / mPa', '#tau / ns')

    # fit data with linear fit
    if fit:
        fit = Fitter('fit_%d' % phi, 'pol1(0)')
        fit.function.SetNpx(1000)
        fit.setParam(0, '#tau_{0}', 119)
        fit.setParam(1, 'm', 0.5)
        fit.fit(graphs, 0, 225, 'M')
        fit.saveData('../calc/fit_tau_%02d%s.txt' % (phi, name), 'w')
        l.AddEntry(fit.function, 'Fit mit #tau(p) = #tau_{0} + m * p', 'l')
        fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2f', '%.2f')], chisquareformat='%.2f',
                              advancedchi=True, units=['ns', 'ns / mPa'])

    # draw legend and print canvas to file
    l.Draw()
    c.Update()
    c.Print('../img/taus_%02d%s.pdf' % (phi, name), 'pdf')

    # return required fit parameter
    if fit:
        return fit.params[0]['value'], fit.params[0]['error']
Esempio n. 16
0
def makePeakFreqGraph(peaks, name):
    xlist = list(list(zip(*peaks))[0])
    sxlist = list(list(zip(*peaks))[1])
    ylist = list(map(lambda i: i * 9.924, range(len(peaks))))
    sylist = list(map(lambda i: i * 0.03, range(len(peaks))))

    direction = name.split('-')[0]
    tabledata = list(zip(*[list(range(1, len(xlist) + 1)), list(map(lambda x:x * 1000, xlist)), list(map(lambda x:x * 1000, sxlist)),
                           ylist, sylist]))
    with TxtFile('../src/tab_part2_etalonfreqs_%s.tex' % direction, 'w') as f:
        f.write2DArrayToLatexTable(tabledata,
                                   ["i", r"$x_i$ / ms", r"$0.2 \cdot s_i$ / ms", r"$\nu_i$ / GHz", r"$s_{\nu_i}$ / GHz"],
                                   ["%d", "%.3f", "%.3f", "%.2f", "%.2f"],
                                   "Zentren $x_i$ der gefitteten Cauchy-Funktionen mit Fehler aus den " +
                                   "Breiteparametern $s_i$ und Frequenzdifferenzen zum ersten Peak. ",
                                   "tab:etalon:calib:%s" % direction)

    etalonData = DataErrors.fromLists(xlist, ylist, sxlist, sylist)
    etalonData.multiplyX(1000)
    c = TCanvas('c_pf_' + name, '', 1280, 720)
    g = etalonData.makeGraph('g_pf_' + name, 'Zeit t / ms', 'Frequenzabstand #Delta#nu / GHz')
    g.SetMinimum(etalonData.getMinY() - 5)
    g.SetMaximum(etalonData.getMaxY() + 5)
    g.Draw('AP')

    fit = Fitter('fit_pf_' + name, 'pol1(0)')
    fit.setParam(0, 'a')
    fit.setParam(1, 'r')
    xmin, xmax = etalonData.getMinX(), etalonData.getMaxX()
    deltax = (xmax - xmin) / 10
    fit.fit(g, xmin - deltax, xmax + deltax)
    fit.saveData('../fit/part2/%s-etalon_calibration.txt' % name)

    if fit.params[1]['value'] < 0:
        l = TLegend(0.575, 0.6, 0.85, 0.85)
    else:
        l = TLegend(0.15, 0.6, 0.425, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Etalonpeaks', 'p')
    l.AddEntry(fit.function, 'Fit mit #Delta#nu = a + r * t', 'l')
    fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2f', '%.2f')], chisquareformat='%.2f', units=('GHz', 'GHz/ms'))
    l.Draw()

    c.Update()
    if not DEBUG:
        c.Print('../img/part2/%s-etalon_calibration.pdf' % name, 'pdf')

    return (fit.params[1]['value'], fit.params[1]['error'])
Esempio n. 17
0
def fitXc(volts, times, d, sd):
    listx, listsx = zip(*times)
    listy = []
    listsy = []
    for u, su in volts:  # convert u to 1/u
        y = 1. / u
        sy = su / (u ** 2)
        listy.append(y)
        listsy.append(sy)
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cXc', '', 1280, 720)
    g = data.makeGraph('xc', 'Zeit t / s', 'reziproke Treibspannung 1/U_{T} / (1/V)')
    g.GetYaxis().SetTitleOffset(1.25)
    g.Draw('AP')

    fit = Fitter('fitXc', '1/[0] + [1]*x')
    fit.setParam(0, 'U_{0}', -150)
    fit.setParam(1, 'm', 3e-3)
    fit.fit(g, 8e-6, 18e-6)
    fit.saveData('../calc/part2/volt_fit_xc.txt')

    l = TLegend(0.15, 0.55, 0.4, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('xc', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit #frac{1}{U_{T}} = m*t + #frac{1}{U_{0}}', 'l')
    l.AddEntry(0, '', '')
    fit.addParamsToLegend(l, [('%.0f', '%.0f'), ('%.0f', '%.0f')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/volt_fitXc.pdf', 'pdf')

    # calculate mu
    m, sm = fit.params[1]['value'], fit.params[1]['error']
    l = 30
    mu = m * l * d / 100  # /100 -> from mm in cm
    smu = mu * np.sqrt((sm / m) ** 2 + (sd / d) ** 2)
    with TxtFile('../calc/part2/volt_mu.txt', 'w') as f:
        f.writeline('\t', str(mu), str(smu))
        
    return mu, smu
Esempio n. 18
0
def evalEnergyCalibration(peaks, percents):
    maxenergy = 1.95 * 0.87 * 84
    smaxenergy = maxenergy * sqrt((0.05/1.95) ** 2 + (0.01/0.87) ** 2 + (5/84) ** 2 )
    channels = list(list(zip(*peaks))[0])
    schannels = list(list(zip(*peaks))[1])
    energies = list(map(lambda x:x/100*maxenergy, percents))
    senergies = list(map(lambda x:x/100*smaxenergy, percents))
    print(energies)
    print(senergies)
    
    with TxtFile('../src/tab_energycalibration.tex', 'w') as f:
        f.write2DArrayToLatexTable(list(zip(*[percents, channels, schannels, energies, senergies])),
                                   ['\% energy', '$c$', '$s_c$', '$E$ / MeV', '$s_E$ / MeV'], 
                                   ['%d', '%.3f', '%.3f', '%.1f', '%.1f'], 
                                   "Channels of fitted peaks and their theoretical energy for the energy calibration.", "tab:ecal")
    
    data = DataErrors.fromLists(channels, energies, schannels, senergies)
    c = TCanvas('c_energycalibration', '', 1280, 720)
    g = data.makeGraph('g_energycalibration', 'channel c', 'energy E / MeV')
    g.Draw('AP')
    
    fit = Fitter('fit_energycalibration', 'pol1(0)')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1/3)
    fit.fit(g, 0, max(channels) + 5)
    fit.saveData('../fit/energyCalibration.txt')
    
    l = TLegend(0.15, 0.6, 0.575, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Peaks of flight through spectra / pedestal', 'p')
    l.AddEntry(fit.function, 'fit with E(c) = a + b * c', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.3f', '%.3f')), chisquareformat='%.2f', units=('MeV', 'MeV / channel'), lang='en')
    l.Draw()
    
    c.Update()
    c.Print('../img/energyCalibration.pdf', 'pdf')
    
    with TxtFile('../calc/energyCalibration.txt', 'w') as f:
        f.writeline('\t', str(fit.params[0]['value']), str(fit.params[0]['error']))
        f.writeline('\t', str(fit.params[1]['value']), str(fit.params[1]['error']))
        f.writeline('\t', str(fit.getCovMatrixElem(0, 1)))
Esempio n. 19
0
def makeEnergyGauge(detector, peaks, litvals):
    x, sx = zip(*peaks)
    data = DataErrors.fromLists(x, litvals, sx, [0] * len(x))
    c = TCanvas('c_eg_%s' % detector, '', 1280, 720)
    g = data.makeGraph('g_eg_%s' % detector, 'Kanal k', 'Energie E / eV')
    g.Draw('AP')

    fit = Fitter('f_eg_%s' % detector, 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b')
    fit.fit(g, x[0] - 20, x[-1] + 20)
    fit.saveData('../calc/part3/energygauge_%s.txt' % detector, 'w')

    l = TLegend(0.15, 0.6, 0.4, 0.85)
    l.AddEntry(g, 'Messwerte', 'p')
    l.AddEntry(fit.function, 'Fit mit E(k) = a + b*k', 'l')
    fit.addParamsToLegend(l, [('%.2f', '%.2f'), ('%.4f', '%.4f')], chisquareformat='%.2f')
    l.Draw()

    c.Update()
    if PRINTGRAPHS:
        c.Print('../img/part3/energygauge_%s.pdf' % detector, 'pdf')
Esempio n. 20
0
def main():
    times = [2.4, 4.5, 6.25, 8.6]
    times_error = [0.02] * len(times)
    channels = [113, 223, 315.5, 441]
    channels_error = [0.5] * len(times)
    
    with TxtFile('../src/tab_timecalibration.tex', 'w') as f:
        f.write2DArrayToLatexTable(list(zip(*[times, times_error, channels, channels_error])),
                                   ["$t$ / \\textmu s", "$s_t$ / \\textmu s", "$c$", "$s_c$"], 
                                   ["%.2f", "%.2f", "%.1f", "%.1f"], 
                                   "Measured times and channels with errors for the time calibration.", "tab:tcal")

    data = DataErrors.fromLists(channels, times, channels_error, times_error)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'channel c', 'time t / #mus')
    g.Draw('APX')

    fit = Fitter('fit', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 50)
    fit.fit(g, 100, 450)
    fit.saveData('../fit/timeCalibration.txt')

    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'measurement', 'p')
    l.AddEntry(fit.function, 'fit with t(c) = a + b * c', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.5f', '%.5f')), chisquareformat='%.2f', units=('#mus', '#mus/channel'), lang='en')
    l.Draw()

    g.Draw('P')
    c.Update()
    c.Print('../img/timeCalibration.pdf', 'pdf')

    with TxtFile('../calc/timeCalibration.txt', 'w') as f:
        f.writeline('\t', str(fit.params[0]['value']), str(fit.params[0]['error']))
        f.writeline('\t', str(fit.params[1]['value']), str(fit.params[1]['error']))
        f.writeline('\t', str(fit.getCovMatrixElem(0, 1)))
Esempio n. 21
0
def fitXc(dists, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*dists)
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cXc', '', 1280, 720)
    g = data.makeGraph('xc', 'Zeit t / s', 'x_{c} / mm')
    g.SetLineWidth(0)
    g.Draw('AP')

    fit = Fitter('fitXc', 'pol1(0)')
    fit.setParam(0, 'x_{0}', 1)
    fit.setParam(1, 'm', 0.5e-6)
    fit.fit(g, 1e-6, 23e-6)
    fit.saveData('../calc/part2/dist_fit_xc.txt')

    l = TLegend(0.15, 0.625, 0.4, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('xc', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit x_{c}(t) = x_{0}+m*t', 'l')
    l.AddEntry(0, '', '')
    fit.addParamsToLegend(l, [('%.3f', '%.3f'), ('%.2e', '%.2e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/dist_fitXc.pdf', 'pdf')

    # calculate mu
    m, sm = fit.params[1]['value'], fit.params[1]['error']
    U, sU = 48.8, P2SemiCon.UERROR
    l = 30
    mu = m * l / U / 100  # /100 -> from mm in cm
    smu = mu * np.sqrt((sm / m) ** 2 + (sU / U) ** 2)
    with TxtFile('../calc/part2/dist_mu.txt', 'w') as f:
        f.writeline('\t', str(mu), str(smu))

    return mu, smu
Esempio n. 22
0
def eval():
    
    data1 = PockData.fromPath('../data/%s.tab' % 'pock_licht_01', 1)
    data2 = PockData.fromPath('../data/%s.tab' % 'pock_licht_02', 1)
    data3 = PockData.fromPath('../data/%s.tab' % 'pock_licht_03', 1)
    data4 = PockData.fromPath('../data/%s.tab' % 'pock_licht_04', 1)
    
    L0 = [0]*data1.getLength()
    Ly1 = [0]*data1.getLength()
    Ly2 = [0.03]*data1.getLength()
    Ly3 = [0.08]*data1.getLength()
    Ly4 = [0.17]*data1.getLength()
    
    Offset1 = DataErrors.fromLists(L0, Ly1, L0, L0)
    Offset2 = DataErrors.fromLists(L0, Ly2, L0, L0)
    Offset3 = DataErrors.fromLists(L0, Ly3, L0, L0)
    Offset4 = DataErrors.fromLists(L0, Ly4, L0, L0)
    
    data1 += Offset1
    data2 += Offset2
    data3 += Offset3
    data4 += Offset4
  
  
    
    c = TCanvas('c', '', 1280, 720)
    
    g1 = data1.makeGraph('g1', 'Zeit t / s', 'Spannung U / V')
    g1.SetMarkerStyle(8)
    g1.SetMarkerSize(0.5)
    g1.SetMarkerColor(1)
    g1.GetXaxis().SetRangeUser(0, 0.1)
    g1.SetMinimum(-0.02)
    g1.SetMaximum(0.25)
    g1.Draw('AP')
    
    g2 = data2.makeGraph('g2', 'Zeit t / s', 'Spannung U / V')
    g2.SetMarkerStyle(8)
    g2.SetMarkerSize(0.5)
    g2.SetMarkerColor(100)
    g2.Draw('P')
    
    g3 = data3.makeGraph('g3', 'Zeit t / s', 'Spannung U / V')
    g3.SetMarkerStyle(8)
    g3.SetMarkerSize(0.5)
    g3.SetMarkerColor(95)
    g3.Draw('P')
    
    g4 = data4.makeGraph('g4', 'Zeit t / s', 'Spannung U / V')
    g4.SetMarkerStyle(8)
    g4.SetMarkerSize(0.5)
    g4.SetMarkerColor(89)
    g4.Draw('P')
    
    
    
    l = TLegend(0.63, 0.51, 0.87, 0.87)
    l.SetTextSize(0.027)
   
   

    l.AddEntry('g4', 'Licht an,', 'p')
    l.AddEntry('', 'ohne Abschirmung', '')
    l.AddEntry('g3', 'Licht an,', 'p')
    l.AddEntry('', 'mit Papier als Abschirmung', '')
    l.AddEntry('g2', 'Licht an,', 'p')
    l.AddEntry('', 'mit Tuch als Abschirmung', '')
    l.AddEntry('g1', 'Licht aus,', 'p')
    l.AddEntry('', 'mit Tuch als Abschirmung', '')
    l.SetFillColor(0)
    l.Draw()
  
    
    c.Update()
    c.Print('../img/%s.pdf' % 'licht', 'pdf')
Esempio n. 23
0
def eval():
    
  
    data1 = PockData.fromPath('../data/%s.tab' % 'pock_gleich_01', 2)
    data2 = PockData.fromPath('../data/%s.tab' % 'pock_gleich_02', 2)
    data3 = PockData.fromPath('../data/%s.tab' % 'pock_gleich_03', 2)
    data4 = PockData.fromPath('../data/%s.tab' % 'pock_gleich_01', 1)
    
    L0 = [0]*data1.getLength()
    Ly1 = [0.41]*data1.getLength()
    Ly2 = [0.31]*data1.getLength()
    Ly3 = [0.14]*data1.getLength()
    Ly4 = [0]*data1.getLength()
    
    Offset1 = DataErrors.fromLists(L0, Ly1, L0, L0)
    Offset2 = DataErrors.fromLists(L0, Ly2, L0, L0)
    Offset3 = DataErrors.fromLists(L0, Ly3, L0, L0)
    Offset4 = DataErrors.fromLists(L0, Ly4, L0, L0)
    
    data1 += Offset1
    data2 += Offset2
    data3 += Offset3
    data4 += Offset4
  
  
    
    c = TCanvas('c', '', 1280, 720)
    
    g1 = data1.makeGraph('g1', 'Zeit t / s', 'Spannung U / V')
    g1.SetMarkerStyle(8)
    g1.SetMarkerSize(0.5)
    g1.SetMarkerColor(65)
    g1.GetXaxis().SetRangeUser(0, 0.005)
    g1.SetMinimum(-0.08)
    g1.SetMaximum(0.45)
    g1.Draw('AP')
    
    g2 = data2.makeGraph('g2', 'Zeit t / s', 'Spannung U / V')
    g2.SetMarkerStyle(8)
    g2.SetMarkerSize(0.5)
    g2.SetMarkerColor(60)
    g2.Draw('P')
    
    g3 = data3.makeGraph('g3', 'Zeit t / s', 'Spannung U / V')
    g3.SetMarkerStyle(8)
    g3.SetMarkerSize(0.5)
    g3.SetMarkerColor(53)
    g3.Draw('P')
    
    g4 = data4.makeGraph('g4', 'Zeit t / s', 'Spannung U / V')
    g4.SetMarkerStyle(8)
    g4.SetMarkerSize(0.5)
    g4.SetMarkerColor(2)
    g4.Draw('P')
    
    
    
    l = TLegend(0.63, 0.51, 0.87, 0.87)
    l.SetTextSize(0.027)
   
   

    l.AddEntry('g1', 'Photodiodensignal,', 'p')
    l.AddEntry('', 'U_{G} = 120 V', '')
    l.AddEntry('g2', 'Photodiodensignal,', 'p')
    l.AddEntry('', 'U_{G} = 122 V', '')
    l.AddEntry('g3', 'Photodiodensignal,', 'p')
    l.AddEntry('', 'U_{G} = 128 V', '')
    l.AddEntry('g4', 'Wechselsignal vom', 'p')
    l.AddEntry('', 'Sinusgenerator mit', '')
    l.AddEntry('', 'Frequenz #omega', '')
    l.SetFillColor(0)
    l.Draw()
  
    
    c.Update()
    c.Print('../img/%s.pdf' % 'pockdurchf', 'pdf')
Esempio n. 24
0
def makeGraph(xlist, ylist, slist, xerror, yerror, xlabel, ylabel, name, fit=False, fitlabel=""):
    """ make graph with optional linear fit

    Arguments:
    xlist    -- list with x-values
    ylist    -- list with y-values
    slist    -- list with measurement series
    xerror   -- absolute error on x-values
    yerror   -- absolute error on y-values
    xlabel   -- title of x-axis
    ylabel   -- title of y-axis
    name     -- appendix to file name
    fit      -- if True fits data with linear model (default=False)
    fitlabel -- fit function as string for legend
    """
    xmin = min(xlist)
    xmax = max(xlist)

    datas = dict()
    for x, y, s in zip(xlist, ylist, slist):
        if s in datas:
            datas[s].append((x, y, xerror, yerror))
        else:
            datas[s] = [(x, y, xerror, yerror)]

    c = TCanvas("c_%s" % name, "", 1280, 720)
    graphs = TMultiGraph()
    for s, datalist in datas.iteritems():
        data = DataErrors.fromLists(*zip(*datalist))
        g = data.makeGraph("g_%s_%d" % (name, s))
        g.SetMarkerColor(seriescolors[s])
        g.SetLineColor(seriescolors[s])
        graphs.Add(g)
    graphs.Draw("AP")
    gPad.Update()
    setMultiGraphTitle(graphs, xlabel, ylabel)

    if fit:
        fit = Fitter("fit_%s" % name, "pol1(0)")
        fit.setParam(0, "a")
        fit.setParam(1, "b")
        fit.fit(graphs, xmin - 1, xmax + 1)
        fit.saveData("../calc/fit_%s.txt" % name, "w")

    if fit:
        yheight = 0.3
    else:
        yheight = 0.15
    if ylist[0] < ylist[-1]:  # /
        l = TLegend(0.15, 0.85 - yheight, 0.4, 0.85)
    else:  # \
        l = TLegend(0.6, 0.85 - yheight, 0.85, 0.85)
    l.SetTextSize(0.03)
    for i, graph in enumerate(graphs.GetListOfGraphs()):
        l.AddEntry(graph, serieslabels[i], "p")
    if fit:
        l.AddEntry(fit.function, "Fit mit %s" % fitlabel, "l")
        fit.addParamsToLegend(
            l, [("%.2f", "%.2f"), ("%.3f", "%.3f")], chisquareformat="%.2f", advancedchi=True, units=["U", "#Omega"]
        )
    l.Draw()

    c.Update()
    c.Print("../img/graph_%s.pdf" % name, "pdf")
Esempio n. 25
0
def evalEnergyGauge():
    # get data
    datalist  = funcs.loadCSVToList('../calc/energy_na.txt')
    datalist += funcs.loadCSVToList('../calc/energy_co.txt')
    datalist += funcs.loadCSVToList('../calc/energy_eu.txt')
    
    #make latex table
    elems = ['Na', 'Na', 'Co', 'Co', 'Eu', 'Eu']
    with TxtFile('../src/energygauge.tex', 'w') as f:
        f.write2DArrayToLatexTable(zip(*([elems] + zip(*datalist))), ['Element', 'Literaturwert / keV', 'Kanal', 'Fehler auf Kanal'], 
                                   ['%s', '%.0f', '%.2f', '%.2f'], 'Referenzpeaks mit Literaturwerten', 'tab:energygauge')
    
    #convert do DataErrors
    datalist = zip(*datalist)
    data = DataErrors.fromLists(datalist[1], datalist[0], datalist[2], [0] * len(datalist[0]))
    
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanalnummer', 'Energie / keV')
    g.GetXaxis().SetRangeUser(0, 3500)
    g.Draw('AP')
    
    fit = Fitter('f', 'pol1(0)')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 0.4)
    fit.fit(g, 0, 3500)
    fit.saveData('../calc/energy_gauge_lin.txt', 'w')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.AddEntry('g', 'Referenzpeaks', 'p')
    l.AddEntry(fit.function, 'Fit mit y = a + b*x', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %.0f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Parameter:', '')
    l.AddEntry(0, 'a = %.2f #pm %.2f' % (fit.params[0]['value'], fit.params[0]['error']), '')
    l.AddEntry(0, 'b = %.5f #pm %.5f' % (fit.params[1]['value'], fit.params[1]['error']), '')
    l.Draw()

    c.Update()
    c.Print('../img/energy_gauge_lin.pdf', 'pdf')
    
    fit2 = Fitter('f', 'pol2(0)')
    fit2.function.SetNpx(1000)
    fit2.setParam(0, 'a', 0)
    fit2.setParam(1, 'b', fit.params[1]['value'])
    fit2.setParam(2, 'c', 0)
    fit2.fit(g, 0, 3500)
    fit2.saveData('../calc/energy_gauge_lin.txt')
    
    l = TLegend(0.15, 0.575, 0.5, 0.85)
    l.AddEntry('g', 'Referenzpeaks', 'p')
    l.AddEntry(fit2.function, 'Fit mit y = a + b*x + c*x^2', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %.0f' % fit2.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Parameter:', '')
    l.AddEntry(0, 'a = %.2f #pm %.2f' % (fit2.params[0]['value'], fit2.params[0]['error']), '')
    l.AddEntry(0, 'b = %.5f #pm %.5f' % (fit2.params[1]['value'], fit2.params[1]['error']), '')
    l.AddEntry(0, 'c = %.8f #pm %.8f' % (fit2.params[2]['value'], fit2.params[2]['error']), '')
    l.Draw()
    
    c.Update()
    c.Print('../img/energy_gauge_quad.pdf', 'pdf')
    
    #write raw data for reuse
    with TxtFile('../calc/energy_gauge_raw.txt', 'w') as f:
        f.writeline('\t', str(fit2.params[0]['value']), str(fit2.params[0]['error']))
        f.writeline('\t', str(fit2.params[1]['value']), str(fit2.params[1]['error']))
        f.writeline('\t', str(fit2.params[2]['value']), str(fit2.params[2]['error']))
        f.writeline(str(fit2.getCorrMatrixElem(0, 1))) #a, b
        f.writeline(str(fit2.getCorrMatrixElem(0, 2))) #a, c
        f.writeline(str(fit2.getCorrMatrixElem(1, 2))) #b, c