Example #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')
Example #2
0
def energyGauge():
    dataList = readFileToList('../calc/hg_lines.txt')
    elemNames = ['Hg'] * len(dataList)
    dataList += readFileToList('../calc/na_lines.txt')
    elemNames += ['Na'] * (len(dataList) - len(elemNames))
    litVals = readFileToList('../data/hg_litvals.txt')
    litVals += readFileToList('../data/na_litvals.txt')

    data = DataErrors()
    for val, litval in zip(dataList, litVals):
        data.addPoint(val, litval, I2Data.ERRORBIN, 0)
        
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured wavelength #lambda_{exp} / nm', 'literature value #lambda_{lit} / nm')
    g.Draw('AP')
    
    fit = Fitter('f', '[0]+[1]*x')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 420, 600)
    fit.saveData('../calc/fit_energy_gauge.txt', 'w')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.AddEntry(fit.function, 'y = a + b*x', 'l')
    fit.addParamsToLegend(l)
    l.SetTextSize(0.03)
    l.Draw()
    
    c.Update()
    c.Print('../img/energy_gauge.pdf', 'pdf')
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')
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')
Example #5
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)
Example #6
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')
Example #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')
Example #8
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)
Example #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')
Example #10
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')
Example #11
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')
Example #12
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')
Example #13
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')
Example #14
0
def evalAngles():
    # load data and set errors
    datalist = loadCSVToList('../data/angles.txt')
    l = len(datalist)
    data = DataErrors().fromLists(list(zip(*datalist)[0]), list(zip(*datalist)[1]), ex=[0.5] * l, ey=[0] * l)
    data.setYErrorFunc(lambda x: np.sqrt(x))
    
    #draw graph
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Winkel #alpha / #circ', 'Counts N')
    g.SetMarkerStyle(1)
    g.Draw('AP')
    
    #fit function
    fit = Fitter('f', '[0]+gaus(1)')
    fit.function.SetNpx(1000)  # for smoother curve
    fit.setParam(0, 'offset', 35)
    fit.setParam(1, 'ampl', 350)
    fit.setParam(2, 'theta', 180)
    fit.setParam(3, 'sigma', 20)
    fit.fit(g, 80, 280)
    fit.saveData('../calc/angles.txt', 'w')

    fit2 = Fitter('f', '[0]+1/2*[4]*(TMath::Erf(([1]+2*x-2*[2])/(2*sqrt(2)*[3]))+TMath::Erf(([1]-2*x+2*[2])/(2*sqrt(2)*[3])))')
    fit2.function.SetNpx(1000)  # for smoother curve
    fit2.function.SetLineColor(4)
    fit2.setParam(0, 'offset', 20)
    fit2.setParam(1, 'breite', 20)
    fit2.setParam(2, 'theta', 180)
    fit2.setParam(3, 'sigma', 5)
    fit2.setParam(4, 'amplitude', 350)
    fit2.fit(g, 80, 280, '+')
    fit2.saveData('../calc/angles_convolution.txt', 'w')
    
    l = TLegend(0.65, 0.55, 0.85, 0.85)
    l.AddEntry('g', 'Messwerte', 'p')
    l.AddEntry(fit.function, 'Fit mit Gaussverteilung', 'l')
    l.AddEntry(0, '#chi^2 / DoF = %.1f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, '#alpha_{0,g} = (%.1f #pm %.1f) #circ' % (fit.params[2]['value'], fit.params[2]['error']), '')
    l.AddEntry(fit2.function, 'Fit mit Faltungsprodukt', 'l')
    l.AddEntry(0, '#chi^2 / DoF = %.1f' % fit2.getChisquareOverDoF(), '')
    l.AddEntry(0, '#alpha_{0,f} = (%.1f #pm %.1f) #circ' % (fit2.params[2]['value'], fit2.params[2]['error']), '')
    l.Draw()
    
    #print to file
    c.Update()
    c.Print('../img/angles.pdf')
Example #15
0
def evalTaus(taus, filters):
    data = DataErrors()
    table = []
    for key, (tau, stau) in taus.items():
        invtau = 1 / tau
        sinvtau = stau / (tau**2)
        int, sint = filters[key]
        data.addPoint(int, invtau, sint, sinvtau)
        table.append([int * 100, sint * 100, tau * 1000, stau * 1000])

    table.sort(key=lambda x: x[0], reverse=True)
    # make table
    with TxtFile('../src/tab_part5_taus.tex', 'w') as f:
        f.write2DArrayToLatexTable(
            table, [
                r'$I_\text{mess}$ / \%', r'$s_{I_\text{mess}}$ / \%',
                r'$\tau$ / ms', r'$s_\tau$ / ms'
            ], ['%.2f', '%.2f', '%.3f', '%.3f'],
            r'Orientierungszeiten $\tau$ des Rubidiumensembles bei verschiedenen Pumpintensitäten $I_{\text{mess}}$.',
            'tab:deh:fitres')

    # make fit
    c = TCanvas('c_taus', '', 1280, 720)
    g = data.makeGraph('g_taus', r'relative Intensitaet I_{mess}',
                       'inverse Orientierungszeit #tau^{ -1} / s^{-1}')
    g.Draw('APX')

    fit = Fitter('fit_taus', '[0]*x + 1/[1]')
    fit.setParam(0, '#alpha', 1)
    fit.setParam(1, 'T_{R}', 1)
    fit.fit(g, 0, 1.1)
    fit.saveData('../fit/part5/taufit.txt')

    l = TLegend(0.55, 0.15, 0.85, 0.5)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Inverse Orientierungszeit #tau^{ -1}', 'p')
    l.AddEntry(fit.function,
               'Fit mit #tau^{ -1} (I) = #alpha I + #frac{1}{T_{R}}', 'l')
    fit.addParamsToLegend(l, [('%.0f', '%.0f'), ('%.5f', '%.5f')],
                          chisquareformat='%.2f',
                          units=['s^{-1}', 's'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part5/taufit.pdf', 'pdf')
Example #16
0
File: eval.py Project: 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")
Example #17
0
def evalDiode():
    datalist = loadCSVToList('../data/part1/Kennlinie.txt')
    data = DataErrors()
    U0 = datalist[0][1]
    sU0 = 0.05 + 0.01 * U0
    for I, u in datalist:
        U = u - U0
        su = 5 + 0.01 * u
        sU = sqrt(su**2 + sU0**2)
        data.addPoint(I, U, 0.1, sU)
    xmin, xmax = 53, 71.5

    c = TCanvas('c_diode', '', 1280, 720)
    g = data.makeGraph('g_diode', "Laserstrom I_{L} / mA",
                       "Photodiodenspannung U_{ph} / mV")
    g.GetXaxis().SetRangeUser(-5, 90)
    g.SetMinimum(-50)
    g.SetMaximum(1400)
    g.Draw('APX')

    # y=0 line
    line = TLine(-5, 0, 90, 0)
    line.SetLineColor(OPData.CH2ECOLOR)
    line.Draw()

    data.filterX(xmin, xmax)
    g2 = data.makeGraph('g_diode_2', "Laserstrom I_{L} / mA",
                        "Photodiodenspannung U_{ph} / mV")
    g2.SetMarkerColor(OPData.CH1COLOR)
    g2.SetLineColor(OPData.CH1COLOR)

    fit = Fitter('fit_diode', '[0] * (x-[1])')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 1)
    fit.setParam(1, 'I_{th}', 50)
    fit.fit(g2, 40, 77)
    fit.saveData('../fit/part1/kennlinie.txt')

    l = TLegend(0.15, 0.55, 0.4, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Laserdiodenkennlinie', 'p')
    l.AddEntry(g2, 'Ausschnitt zum Fitten', 'p')
    l.AddEntry(fit.function, 'Fit mit U_{ph} = a (I_{ L} - I_{ th} )', 'l')
    fit.addParamsToLegend(l, (('%.1f', '%.1f'), ('%.2f', '%.2f')),
                          chisquareformat='%.2f',
                          units=['mV/mA', 'mA'])
    l.Draw()

    g.Draw('P')
    g2.Draw('P')

    c.Update()
    c.Print('../img/part1/diodenkennlinie.pdf', 'pdf')
Example #18
0
def evalTaus(taus, filters):
    data = DataErrors()
    table = []
    for key, (tau, stau) in taus.items():
        invtau = 1 / tau
        sinvtau = stau / (tau ** 2)
        int, sint = filters[key]
        data.addPoint(int, invtau, sint, sinvtau)
        table.append([int * 100, sint * 100, tau * 1000, stau * 1000])

    table.sort(key=lambda x: x[0], reverse=True)
    # make table
    with TxtFile('../src/tab_part5_taus.tex', 'w') as f:
        f.write2DArrayToLatexTable(table, [r'$I_\text{mess}$ / \%', r'$s_{I_\text{mess}}$ / \%', r'$\tau$ / ms', r'$s_\tau$ / ms'],
                                   ['%.2f', '%.2f', '%.3f', '%.3f'],
                                   r'Orientierungszeiten $\tau$ des Rubidiumensembles bei verschiedenen Pumpintensitäten $I_{\text{mess}}$.',
                                   'tab:deh:fitres')

    # make fit
    c = TCanvas('c_taus', '', 1280, 720)
    g = data.makeGraph('g_taus', r'relative Intensitaet I_{mess}', 'inverse Orientierungszeit #tau^{ -1} / s^{-1}')
    g.Draw('APX')

    fit = Fitter('fit_taus', '[0]*x + 1/[1]')
    fit.setParam(0, '#alpha', 1)
    fit.setParam(1, 'T_{R}', 1)
    fit.fit(g, 0, 1.1)
    fit.saveData('../fit/part5/taufit.txt')

    l = TLegend(0.55, 0.15, 0.85, 0.5)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Inverse Orientierungszeit #tau^{ -1}', 'p')
    l.AddEntry(fit.function, 'Fit mit #tau^{ -1} (I) = #alpha I + #frac{1}{T_{R}}', 'l')
    fit.addParamsToLegend(l, [('%.0f', '%.0f'), ('%.5f', '%.5f')], chisquareformat='%.2f', units=['s^{-1}', 's'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part5/taufit.pdf', 'pdf')
Example #19
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)))
Example #20
0
def evalAngleDependency():
    datalist = loadCSVToList(DIR + 'Winkelabh.txt')
    data = DataErrors()
    strel = 0.01
    sI = 1
    for t2, t1, n, phi in datalist:
        f, sf = calcPrecissionFreq(t2, t1, n)
        data.addPoint(phi, f, 0.5, sf)

    c = TCanvas('c_phi', '', 1280, 720)
    g = data.makeGraph('g_phi', 'Rotation des Strahlengangs #varphi / #circ',
                       'Praezessionsfrequenz f / kHz')
    g.GetXaxis().SetRangeUser(-15, 15)
    g.SetMinimum(0)
    g.Draw('APX')

    fit = Fitter('fit_phi', '[0] * abs(sin((x-[1])*pi/180))')
    fit.function.SetNpx(1000)
    fit.setParam(0, '#beta', 1)
    fit.setParam(1, '#phi_{0}', 0)
    fit.fit(g, -15, 15)
    fit.saveData('../fit/part4/winkel.txt')

    g.Draw('P')

    l = TLegend(0.7, 0.15, 0.95, 0.5)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Praezessionsfrequenz', 'p')
    l.AddEntry(fit.function, 'Fit mit f = #beta |sin(#varphi + #varphi_{0})|',
               'l')
    fit.addParamsToLegend(l, (('%.1f', '%.1f'), ('%.2f', '%.2f')),
                          chisquareformat='%.2f',
                          units=['kHz/#muT', '#circ'])
    l.Draw()

    c.Update()
    c.Print('../img/part4/winkel.pdf', 'pdf')
Example #21
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']
Example #22
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'])
Example #23
0
def evalDiode():
    datalist = loadCSVToList('../data/part1/Kennlinie.txt')
    data = DataErrors()
    U0 = datalist[0][1]
    sU0 = 0.05 + 0.01 * U0
    for I, u in datalist:
        U = u - U0
        su = 5 + 0.01 * u
        sU = sqrt(su ** 2 + sU0 ** 2)
        data.addPoint(I, U, 0.1, sU)
    xmin, xmax = 53, 71.5

    c = TCanvas('c_diode', '', 1280, 720)
    g = data.makeGraph('g_diode', "Laserstrom I_{L} / mA", "Photodiodenspannung U_{ph} / mV")
    g.GetXaxis().SetRangeUser(-5, 90)
    g.SetMinimum(-50)
    g.SetMaximum(1400)
    g.Draw('APX')

    # y=0 line
    line = TLine(-5, 0, 90, 0)
    line.SetLineColor(OPData.CH2ECOLOR)
    line.Draw()

    data.filterX(xmin, xmax)
    g2 = data.makeGraph('g_diode_2', "Laserstrom I_{L} / mA", "Photodiodenspannung U_{ph} / mV")
    g2.SetMarkerColor(OPData.CH1COLOR)
    g2.SetLineColor(OPData.CH1COLOR)

    fit = Fitter('fit_diode', '[0] * (x-[1])')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 1)
    fit.setParam(1, 'I_{th}', 50)
    fit.fit(g2, 40, 77)
    fit.saveData('../fit/part1/kennlinie.txt')

    l = TLegend(0.15, 0.55, 0.4, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Laserdiodenkennlinie', 'p')
    l.AddEntry(g2, 'Ausschnitt zum Fitten', 'p')
    l.AddEntry(fit.function, 'Fit mit U_{ph} = a (I_{ L} - I_{ th} )', 'l')
    fit.addParamsToLegend(l, (('%.1f', '%.1f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=['mV/mA', 'mA'])
    l.Draw()

    g.Draw('P')
    g2.Draw('P')

    c.Update()
    c.Print('../img/part1/diodenkennlinie.pdf', 'pdf')
Example #24
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
Example #25
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)))
Example #26
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')
Example #27
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)))
Example #28
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
Example #29
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")
Example #30
0
def makeAreaFit():
    # calculate ares
    d_s = [1.000, 0.990, 0.990, 1.005, 1.000, 1.005]
    d_m = [1.700, 1.690, 1.695, 1.700, 1.705, 1.705]
    d_l = [2.880, 2.880, 2.875, 2.880, 2.880, 2.880]
    d = map(avgstd, [d_s, d_m, d_l])
    a = map(area, d)
    
    diaarea = DataErrors()
    for i in range(3):
        diaarea.addPoint(d[i][0], a[i][0], d[i][1], a[i][1])
    diaarea.saveDataToLaTeX(['Durchmesser $d$ / cm', '$s_d$ / cm', 'Fl\"ache $F / \\text{cm}^2$', '$s_F / \\text{cm}^2$'], 
                            ['%.4f', '%.4f', '%.4f', '%.4f'], 'Verschiedene Fl\"achen f\"ur die Samariummessung', 
                            'tab:data:samarium:area', '../src/data_samarium_areas.tex', 'w')
    
    with TxtFile('../fit/samarium.txt', 'w') as f:
        f.writeline('areas')
        f.writeline('=====')
        for b in a:
            f.writeline('\t', '%e' % b[0], TxtFile.PM, '%e' % b[1])
        f.writeline()
    
    
    #read data from files
    #file=[area, area error, path, time]
    files = []
    files.append([a[0][0], a[0][1], '../data/31_Sm_kl_1600_t3000.txt', 3000])
    files.append([a[1][0], a[1][1], '../data/34_Sm_m_1600_t2400.txt', 2400])
    files.append([a[2][0], a[2][1], '../data/08_Sm_ggrFl_1600-1600-0.txt', 1200])
    u = readSingleEntryFile('../data/09_Untergrund_1600-1600-0.txt') 
    tu = 3600
    d = DataErrors()
    for file in files:
        n = readSingleEntryFile(file[2])
        d.addPoint(file[0], n - u, file[1], np.sqrt(n / file[3] + u / tu))
        
    d.saveDataToLaTeX(['Fl\"ache $F / \\text{cm}^2$', '$s_F / \\text{cm}^2$', 'Z\"ahlrate $n / (1/\\text{s})$', '$s_n / (1/\\text{s})$'], 
                      ['%.4f', '%.4f', '%.3f', '%.3f'], 'Z\"ahlraten von \\samarium~f\"ur verschiedene Fl\"achen mit Fehlern', 
                      'tab:data:samarium', '../src/data_samarium.tex', 'w')
        
    c = TCanvas('c2', '', 800, 600)
    g = d.makeGraph('g', 'Fl#ddot{a}che F / cm^{2}', 'Z#ddot{a}hlrate n / (1/s)')
    g.Draw('AP')
    
    fit = Fitter('f', '[0]+[1]*x')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 0.05)
    fit.fit(g, 0, 30)
    fit.saveData('../fit/samarium.txt', 'a')
    
    a = fit.params[0]['value']
    sa = fit.params[0]['error']
    b = fit.params[1]['value']
    sb = fit.params[1]['error']

    l = TLegend(0.55, 0.15, 0.98, 0.5)
    l.AddEntry('g', '{}^{147} Samarium ohne Untergrund', 'p')  # TODO with error bar? (options +'e')
    l.AddEntry(fit.function, 'Fit mit n(F)=a+b*F', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Paramter:', '') 
    l.AddEntry(0, 'a: %e #pm %e' % (a, sa), '')
    l.AddEntry(0, 'b: %e #pm %e' % (b, sb), '')   
    l.SetTextSize(0.03)
    l.Draw()
    
    c.Update()
    c.Print('../img/Samarium147-Flaechenabhaengigkeit.pdf', 'pdf')
    
    #calculation with fit parameters
    c  = 0.004025
    NA = 6.02214129e23
    m  = 2*150.36 + 3*15.999
    h = 0.1487
    t = (np.log(2) * c * NA * h) / (2 * m * b) / (3600 * 24 * 365.242)
    st = t * (sb / b)
    with TxtFile('../fit/samarium.txt', 'a') as f:
        f.writeline('calculation from fit')
        f.writeline('====================')
        f.writeline('\t', '%e' % t, TxtFile.PM, '%e' % st)
        f.writeline()
    
    # calculation from single data points
    sc = map(lambda p: calculateHalfLife(*p), d.points)
    with TxtFile('../fit/samarium.txt', 'a') as f:
        f.writeline('calculation from single data points')
        f.writeline('===================================')
        for s in sc:
            f.writeline('\t', '%e' % s[0], TxtFile.PM, '%e' % s[1])
        f.writeline()
Example #31
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
Example #32
0
 def subtractUnderground(self, a, b, sa, sb, rho):
     u = DataErrors()
     for x, sx in zip(self.getX(), self.getEX()):
         u.addPoint(x, a + b * x, sx, sa ** 2 + (x * sb) ** 2 + (b * sx) ** 2 + sa * sb * rho * x)
     self.points = (self - u).points
Example #33
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')
Example #34
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')
Example #35
0
def evalSpinPrecission(name):
    datalist = loadCSVToList(DIR + name + '.txt')
    data = DataErrors()
    sI = 1
    for t2, t1, n, I in datalist:
        f, sf = calcPrecissionFreq(t2, t1, n)
        B, sB = inductorIToB(4, I * 1e-3, sI * 1e-3)
        data.addPoint(B * 1e6, f, sB * 1e6, sf)

    if len(name) == 4:
        xmin, xmax = 0, 50
    else:
        xmin, xmax = 0, 80

    c = TCanvas('c_%s' % name, '', 1280, 720)
    g = data.makeGraph('g_%s' % name,
                       'Zusaetzliches Vertikalfeld B_{S, v} / #muT',
                       'Praezessionsfrequenz f / kHz')
    g.GetXaxis().SetRangeUser(xmin, xmax)
    g.Draw('APX')

    fit1 = Fitter('fit1_%s' % name, '[0] * abs([1]-x)')
    fit1.function.SetNpx(1000)
    fit1.setParam(0, '#alpha', 1)
    fit1.setParam(1, 'B_{E, v}', 40)
    fit1.fit(g, xmin, xmax)
    fit1.saveData('../fit/part4/fit1_%s' % name)

    fit2 = Fitter('fit1_%s' % name, '[0] * (abs([1]-x) + [2])')
    fit2.function.SetNpx(1000)
    fit2.function.SetLineColor(3)
    fit2.setParam(0, '#alpha', 1)
    fit2.setParam(1, 'B_{E, v}', 40)
    fit2.setParam(2, 'B_{E,h,s}', 20)
    fit2.setParamLimits(2, 0, 100)
    fit2.fit(g, xmin, xmax, '+')
    fit2.saveData('../fit/part4/fit2_%s' % name)

    g.Draw('P')

    if len(name) == 4:
        l = TLegend(0.6, 0.4, 0.975, 0.95)
    else:
        l = TLegend(0.325, 0.475, 0.725, 0.99)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Praezessionsfrequenzen', 'p')
    l.AddEntry(fit1.function,
               'Fit mit f_{1}(B_{S, v}) = #alpha |B_{E, v} - B_{S, v}|', 'l')
    fit1.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')),
                           chisquareformat='%.2f',
                           units=['kHz/#muT', '#muT'])
    l.AddEntry(
        fit2.function,
        'Fit mit f_{2}(B_{S, v}) = #alpha (|B_{E, v} - B_{S, v}| + B_{E,h,s})',
        'l')
    fit2.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f'),
                               ('%.2f', '%.2f')),
                           chisquareformat='%.2f',
                           units=['kHz/#muT', '#muT', '#muT'])
    l.Draw()

    c.Update()
    c.Print('../img/part4/%s.pdf' % name, 'pdf')
Example #36
0
def makeMassFit():
    # config files
    # file = [mass, path]
    files = []
    files.append([2.0123, "../data/11_K_m9_3200_t420.txt", 420])
    files.append([2.0123, "../data/11b_K_m9_3200_t420.txt", 420])
    files.append([1.9047, "../data/13_K_m8_3200_t420.txt", 420])
    files.append([1.6812, "../data/15_K_m7_3200_t420.txt", 420])
    files.append([1.4827, "../data/17_K_m6_3200_t420.txt", 420])
    files.append([1.2952, "../data/19_K_m5_3200_t480.txt", 480])
    files.append([1.0993, "../data/21_K_m4_3200_t480.txt", 480])
    files.append([0.8086, "../data/23_K_m3_3200_t540.txt", 540])
    files.append([0.6954, "../data/25_K_m2_3200_t540.txt", 540])
    files.append([0.5007, "../data/27_K_m1_3200_t660.txt", 660])
    files.append([0.3030, "../data/29_K_m0_3200_t780.txt", 780])
    u = 0.760
    tu = 50

    d = DataErrors()

    for file in files:
        n = readSingleEntryFile(file[1])
        d.addPoint(file[0], n - u, 0.001, np.sqrt(n / file[2] + u / tu))

    d.saveDataToLaTeX(['Masse $m /$g', '$s_m /$g', 'Z\"ahlrate $n / (1/\\text{s})$', '$s_n / (1/\\text{s})$'],
                      ['%.3f', '%.3f', '%.3f', '%.3f'], 
                      'Z\"ahlraten von \\kalium\,f\"ur verschiedene Massen mit Fehlern', 'tab:data:kalium', '../src/data_kalium.tex', 'w')

    c = TCanvas('c2', '', 800, 600)
    g = d.makeGraph('g', 'Masse m / g', 'Z#ddot{a}hlrate n / (1/s)')
    g.SetMaximum(6)
    g.SetMinimum(2)
    g.Draw('AP')

    fit = Fitter('f', '[0]*(1-exp(-[1]*x))')
    fit.setParam(0, 'a')
    fit.setParam(1, 'b')
    fit.fit(g, 0.1, 2.5)
    fit.saveData('../fit/kalium.txt')
    
    a = fit.params[0]['value']
    sa = fit.params[0]['error']
    b = fit.params[1]['value']
    sb = fit.params[1]['error']

    l = TLegend(0.4, 0.15, 0.85, 0.5)
    l.AddEntry('g', '{}^{40} Kalium ohne Untergrund', 'p')  # TODO with error bar? (options +'e')
    l.AddEntry(fit.function, 'Fit mit n(m)=a(1-exp(-b*m))', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Paramter:', '') 
    l.AddEntry(0, 'a: %e #pm %e' % (a, sa), '')
    l.AddEntry(0, 'b: %e #pm %e' % (b, sb), '')   
    l.SetTextSize(0.03)
    l.Draw()

    NA = 6.02214129e23
    hrel = 0.000118
    mrel = 39.0983 + 35.45
    f = 1.29
    rho = fit.getCorrMatrixElem(1, 0)
    thalf = (np.log(2) * NA * hrel * f) / (1.12 * mrel * 2 * a * b) / (3600 * 24 * 365.242)
    sthalf = thalf * np.sqrt((sa / a) ** 2 + (sb / b) ** 2 + 2 * rho * (sa / a) * (sb / b))

    with TxtFile.fromRelPath('../fit/kalium.txt', 'a') as f:
        f.writeline()
        f.writeline('calculations')
        f.writeline('============')
        f.writeline('\t', 'half-life of Kalium:', '%e' % thalf, TxtFile.PM, '%e' % sthalf)

    c.Update()
    c.Print('../img/Kalium40_Massenabhaengigkeit.pdf')