def main(): periods = [30, 45, 60] fitresults = [] for period in periods: fitresults.append(fitX0(period)) # output xm with TxtFile('../calc/fixed_T_xm.txt', 'w') as f: for i, result in enumerate(fitresults): f.writeline('\t', str(periods[i]), *map(str, result[0])) f.writeline('\t', *map(str, avgerrors(*zip(*zip(*fitresults)[0])))) # weighted average # calculate + output alphas alphas = [] for i, result in enumerate(fitresults): alphas.append(calcAlpha(periods[i], X0Data.ST, *result[1])) with TxtFile('../calc/fixed_T_alpha.txt', 'w') as f: for i, alpha in enumerate(alphas): f.writeline('\t', str(periods[i]), *map(str, alpha)) f.writeline('\t', *map(str, avgerrors(*zip(*alphas)))) # make latex tables for fit results an alphas with TxtFile('../src/fit_x0.tex', 'w') as f: f.write2DArrayToLatexTable(zip(*([(periods)] + zip(*zip(*fitresults)[0]) + zip(*zip(*fitresults)[1]))), ['$T$ / ms', '$x_m$ / mm', '$s_{x_m}$ / mm', '$m$ / (mm / kHz)', '$s_m$ / (mm / kHz)'], ['%d', '%.3f', '%.3f', '%.4f', '%.4f'], 'Fitergebnisse von $x_0\'(\Delta \\nu)$ bei festen Periodendauern $T$.', 'tab:fit:x0') with TxtFile('../src/fit_x0_alpha.tex', 'w') as f: f.write2DArrayToLatexTable(zip(*([(periods)] + zip(*alphas))), ['$T$ / ms', '$\\alpha$', '$s_{\\alpha}$'], ['%d', '%.3f', '%.3f'], 'Mitf\\"uhrungskoeffizienten bei festen Periodendauern $T$. ', 'tab:x0:alpha')
def main(): x0s = [36, 40, 53, 57] fitresults = [] for x0 in x0s: fitresults.append(fitT(x0)) xm, sxm = getXm('../calc/fixed_T_xm.txt') alphas = [] for i, result in enumerate(fitresults): alphas.append(calcAlpha(x0s[i], TData.SX, xm, sxm, *result[1])) with TxtFile('../calc/fixed_x0_alpha.txt', 'w') as f: for i, alpha in enumerate(alphas): f.writeline('\t', str(x0s[i]), *map(str, alpha)) f.writeline('\t', *map(str, avgerrors(*zip(*alphas)))) # make latex tables for fit results an alphas with TxtFile('../src/fit_T.tex', 'w') as f: f.write2DArrayToLatexTable(zip(*([(x0s)] + zip(*zip(*fitresults)[0]) + zip(*zip(*fitresults)[1]))), ['$x_0\'$ / mm', '$a$ / kHz', '$s_{a}$ / kHz', '$b$ / (kHz $\cdot$ ms / rad)', '$s_b$ / (kHz $\cdot$ ms / rad)'], ['%d', '%.1f', '%.1f', '%.0f', '%.0f'], 'Fitergebnisse von $\Delta \\nu(\\omega)$ bei festen Auftrittpunkten $x_0\'$.', 'tab:fit:T') with TxtFile('../src/fit_T_alpha.tex', 'w') as f: f.write2DArrayToLatexTable(zip(*([(x0s)] + zip(*alphas))), ['$x_0\'$ / mm', '$\\alpha$', '$s_{\\alpha}$'], ['%d', '%.3f', '%.3f'], 'Mitf\\"uhrungskoeffizienten bei festen Auftreffpunkten $x_0\'$. ', 'tab:T:alpha')
def main(): gROOT.Reset() gROOT.SetStyle('Plain') gStyle.SetPadTickY(1) gStyle.SetPadTickX(1) params = [] fitlist = [False, True, True, True] for i in xrange(4): param = eval('pock_saege_winkel%d' % i, fitlist[i]) if fitlist[i]: params.append(param) print(params) with TxtFile('../calc/fitparams_parabolas.txt', 'w') as f: for par in params: f.writeline('\t', *map(lambda x: '%.6f\t%.6f' % x, par)) difflist = [] for i in xrange(3): difflist.append((params[i][1][0]-params[i][0][0],np.sqrt(params[i][1][1]**2 + params[i][0][1]**2))) av = avgerrors(*zip(*difflist)) with TxtFile('../calc/diff_minmax.txt', 'w') as f: for dif in difflist: f.writeline('\t', *map(str, dif)) f.writeline('\t', str(av[0]),str(av[1]),'weighted average')
def main(): setupROOT() elems = ['Si', 'Ge'] filterxs = [(0, 1.8), (0, 1)] ymaxs = [0.25, 0.25] yundergrounds = [0.03, 0.1] energies = [] for elem, filterx, ymax, yunderground in zip(elems, filterxs, ymaxs, yundergrounds): energies.append(fitAbsTrans(elem, filterx, ymax)) plotMultiChannelSpectrum(elem, 'Messung', [(P1SemiCon.CANGLE, P1SemiCon.CPYRO), (P1SemiCon.CANGLE, P1SemiCon.CSAMPLE)], ['Signal des Pyrodetektors', 'Signal der Probe'], (-5, 80), connect=True) plotMultiChannelSpectrum(elem, 'Untergrund', [(P1SemiCon.CANGLE, P1SemiCon.CPYRO), (P1SemiCon.CANGLE, P1SemiCon.CSAMPLE)], ['Untergrund des Pyrodetektors', 'Untergrund der Probe'], (-5, 80), (0, yunderground)) plotMultiChannelSpectrum(elem, 'Lampe', [(P1SemiCon.CANGLE, P1SemiCon.CPYRO)], ['Signal des Pyrodetektors'], (-5, 80), connect=True) plotMultiChannelSpectrum(elem, 'Messung', [(P1SemiCon.CANGLE, P1SemiCon.CENERGY)], ['Energie E(#alpha)'], (0, 80), connect=True, addlabel='_ea') for i, energie in enumerate(energies): listenergy = [] listnewerrors = [] with TxtFile('../calc/part1/%s_bandgap_syserror.txt' % elems[i], 'w') as f: for e, se in energie: listenergy.append(e) sesys = calcsE(convertEnergyToAngle(e, elems[i]), elems[i]) newerror = np.sqrt(se ** 2 + sesys ** 2) listnewerrors.append(newerror) f.writeline('\t', str(e), str(se), str(sesys), str(newerror)) with TxtFile('../calc/part1/%s_bandgap_avg.txt' % elems[i], 'w') as f: f.writeline('\t', *map(str, avgerrors(listenergy, listnewerrors)))
def eval(freq): # load data data = loadCSVToList('../data/pock_gleich_%dhz.txt' % freq) sv = 1 # error on single meassurement # calculate r41 diffs = map(lambda x: (x[0] + x[1], np.sqrt(2) * sv), data) avg = avgerrors(*zip(*diffs)) return calcr41(*avg)
def main(): freqs = [1e3, 1e4] with TxtFile('../calc/pock_dc.txt', 'w') as f: r41s = [] for freq in freqs: r41 = eval(freq) r41s.append(r41) f.writeline('\t', str(freq), *map(str, r41)) f.writeline('average:') f.writeline('\t', *map(str, avgerrors(*zip(*r41s))))
def evalTotalGamma(gammas): gammas.append(avgerrors(list(zip(*gammas))[0], list(zip(*gammas))[1])) with TxtFile('../calc/gamma_total.txt', 'w') as f: f.write2DArrayToFile(gammas, ['%f'] * 2) table = [] desc = [LATEXE, LATEXM, LATEXT, LATEXQ, "gew. Mittel"] for i, (gamma, sgamma) in enumerate(gammas): table.append([desc[i], gamma, sgamma]) with TxtFile('../src/tab_gamma_total.tex', 'w') as f: f.write2DArrayToLatexTable(table, ["Zerfallskanal", r"$\Gamma_\text{Z}$ / GeV", r"$s_{\Gamma_\text{Z}}$ / GeV"], ['%s', '%.3f', '%.3f'], r"Durch Fits bestimmte totale Zerfallsbreite des \Z-Bosons und gewichtetes Mittel.", "tab:gamma:total")
def evalMasses(masses): masses.append(avgerrors(list(zip(*masses))[0], list(zip(*masses))[1])) with TxtFile('../calc/mass.txt', 'w') as f: f.write2DArrayToFile(masses, ['%f'] * 2) table = [] desc = [LATEXE, LATEXM, LATEXT, LATEXQ, "gew. Mittel"] for i, (mass, smass) in enumerate(masses): table.append([desc[i], mass, smass]) with TxtFile('../src/tab_mass.tex', 'w') as f: f.write2DArrayToLatexTable(table, ["Zerfallskanal", r"$M_\text{Z}$ / GeV", r"$s_{M_\text{Z}}$ / GeV"], ['%s', '%.3f', '%.3f'], r"Durch Fits bestimmte Masse des \Z-Bosons und gewichtetes Mittel.", "tab:mass")
def evalTotalGamma(gammas): gammas.append(avgerrors(list(zip(*gammas))[0], list(zip(*gammas))[1])) with TxtFile('../calc/gamma_total.txt', 'w') as f: f.write2DArrayToFile(gammas, ['%f'] * 2) table = [] desc = [LATEXE, LATEXM, LATEXT, LATEXQ, "gew. Mittel"] for i, (gamma, sgamma) in enumerate(gammas): table.append([desc[i], gamma, sgamma]) with TxtFile('../src/tab_gamma_total.tex', 'w') as f: f.write2DArrayToLatexTable( table, [ "Zerfallskanal", r"$\Gamma_\text{Z}$ / GeV", r"$s_{\Gamma_\text{Z}}$ / GeV" ], ['%s', '%.3f', '%.3f'], r"Durch Fits bestimmte totale Zerfallsbreite des \Z-Bosons und gewichtetes Mittel.", "tab:gamma:total")
def evalMasses(masses): masses.append(avgerrors(list(zip(*masses))[0], list(zip(*masses))[1])) with TxtFile('../calc/mass.txt', 'w') as f: f.write2DArrayToFile(masses, ['%f'] * 2) table = [] desc = [LATEXE, LATEXM, LATEXT, LATEXQ, "gew. Mittel"] for i, (mass, smass) in enumerate(masses): table.append([desc[i], mass, smass]) with TxtFile('../src/tab_mass.tex', 'w') as f: f.write2DArrayToLatexTable( table, [ "Zerfallskanal", r"$M_\text{Z}$ / GeV", r"$s_{M_\text{Z}}$ / GeV" ], ['%s', '%.3f', '%.3f'], r"Durch Fits bestimmte Masse des \Z-Bosons und gewichtetes Mittel.", "tab:mass")
def main(): phis = [0, 45, 90] tempDict = loadTempDict() avgphis = dict() taus = [] for phi in phis: # read data datalist = loadCSVToList('../calc/taus_%02d.txt' % phi) datas = {0: [], 1: [], 2: []} for T, tau, stau, fitphi, sfitphi in datalist: p, sp = tempDict[T] datas[TempToSeries(T)].append((p, tau, sp, stau)) # sort in right series list # make graphs with different series printGraph(datas, phi) printGraph(datas, phi, '_total', True) del datas[0] taus.append(printGraph(datas, phi, '_day2', True)) del datas[2] printGraph(datas, phi, '_partial', True) # calculate average fitted phi philist = zip(*datalist)[3] avgphis[phi] = np.average(philist), np.std(zip(*datalist)[3], ddof=1) / np.sqrt(len(philist)) # print out average fittet phis with TxtFile('../calc/avgphis.txt', 'w') as f: for phi, avgphi in avgphis.iteritems(): f.writeline('\t', str(phi), *map(str, avgphi)) # print out extraplated taus as LaTeX table with TxtFile('../src/taus_final.tex', 'w') as f: f.write2DArrayToLatexTable(zip(phis, *zip(*taus)), ['$\\Phi$ / ${}^{\\circ}$', '$\\tau$ / ns', '$s_{\\tau}$ / ns'], ['%d', '%.1f', '%.1f'], 'Extrapolierte mittlere Lebensdauern bei verschiedenen Winkeleinstellungen.', 'tab:tau:final') # print out extrapolated taus as csv and calculate weighted average with TxtFile('../calc/taus_final.txt', 'w') as f: for tau, error in taus: f.writeline('\t', str(tau), str(error)) f.writeline('weighted average') f.writeline('\t', *map(str, avgerrors(*zip(*taus))))
def main(): evalGraph('141022', 'Spule_R1', 1, 'both') # make fits fitfiles = [('141022', 'Spule_R1', 100), ('141022', 'Spule_R2', 100), ('141022', 'Spule_R3', 100), ('141022', 'Spule_R4', 100), ('141022', 'Spule_R5_1', 100), ('141021', 'Magnet', 1), ('141022', 'Magnetspan_0grad', 100), ('141022', 'Magnetspan_45grad', 20), ('141022', 'Magnetspan_90grad', 50)] results = dict() rfbs = dict() for dir, file, rfb in fitfiles: results[file] = evalGraph(dir, file, rfb, 'fit') rfbs[file] = rfb # print fit results to file reslabels = {0: 'Amplitude', 1: 'omega', 2: 'phi'} for i, label in reslabels.iteritems(): with TxtFile('../calc/%s.txt' % label, 'w') as f: for key in results: f.writeline('\t', key, *map(str, results[key][i])) # calculate b-field from fitted amplitudes bfields = [(key, results[key][0], ampToB(rfbs[key], *results[key][0])) for key in results] bfields.sort(key=lambda x: x[0]) with TxtFile('../calc/bfields_fit.txt', 'w') as f: for key, res, bfield in bfields: f.writeline('\t', key, *map(str, res + bfield)) with TxtFile('../calc/bfields_leiterschleife_fit.txt', 'w') as f: for key, res, bfield in bfields[-5:]: f.writeline('\t', *map(str, bfield)) # calculate average omega omegas = [results[key][1] for key in results] avgomega = avgerrors(*zip(*omegas)) with TxtFile('../calc/omega_avg.txt', 'w') as f: f.writeline('\t', *map(str, avgomega)) # print graphs without fitting, averaged omega from fits is used for polar plot drawfiles = [('141022', 'Au-Plaettchen', 100), ('141022', 'emptyHolder', 100), ('141022', 'emptyHolder_afterShaking', 100), ('141022', 'emptyHolder_perpendicular', 100), ('141022', 'Fe-Span', 100), ('141022', 'Stabmagnet_parallel', 1), ('141022', 'Untergrund', 100)] for dir, file, rfb in drawfiles: evalGraph(dir, file, rfb, omega=avgomega[0])
def main(): print('make graphs') print('===========') makeGraphs() print('eval etalon data') print('================') freqCalibrations = evalEtalonData() print('eval hfs peak data') print('==================') hfspeaks = evalHFSPeakData() litvals = (-3.07, -2.25, mean([-1.48, -1.12]), mean([1.56, 1.92]), 3.76, 4.58) reflit = litvals[3] litvals = list(map(lambda x: x - reflit, litvals)) spectra = dict() for key in freqCalibrations.keys(): gps, sgps = freqCalibrations[key] isUp = key[:2] == "up" spectrum = [] if isUp: refpeak, srefpeak = hfspeaks[key][2] m = 1 else: refpeak, srefpeak = hfspeaks[key][3] m = -1 for peak, speak in hfspeaks[key]: freq = m * (refpeak - peak) * 1000 * gps if not compare2Floats(refpeak, peak): sfreq = abs(freq) * sqrt((sgps / gps) ** 2 + (sqrt(srefpeak ** 2 + speak ** 2) / (refpeak - peak)) ** 2) else: sfreq = 1000 * gps * speak if compare2Floats(freq, 0): freq = abs(freq) spectrum.append((freq, sfreq)) if isUp: spectrum.reverse() spectra['up' if isUp else 'down'] = spectrum compareSpectrum('up' if isUp else 'down', spectrum, litvals) tabledata = [] names = [r"\rb{87}, F:2$\to$1", r"\rb{87}, F:2$\to$2", r"\rb{85}, F:3$\to$2, 3$\to$3", r"\rb{85}, F:2$\to$2, 2$\to$3", r"\rb{87}, F:1$\to$1", r"\rb{87}, F:1$\to$2"] # Übergänge for i, litval in enumerate(litvals): tabledata.append([names[i]] + [litval] + list(spectra['up'][i]) + list(spectra['down'][i])) with TxtFile('../src/tab_part2_spectrum.tex', 'w') as f: f.write2DArrayToLatexTable(tabledata, ["Übergang", r'$\Delta \nu^\text{theo}$ / GHz', r'$\Delta \nu^\text{exp}_\text{up}$ / GHz', r'$s_{\Delta \nu^\text{exp}_\text{up}}$ / GHz', r'$\Delta \nu^\text{exp}_\text{down}$ / GHz', r'$s_{\Delta \nu^\text{exp}_\text{down}}$ / GHz'], ['%s', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f'], "Theoretisches und (steigende und fallende Flanke) experimentell bestimmtes Hyperfeinstrukturspektrum von Rubidium.", "tab:hfs:spectrum") avgdata = [] avgspectrum = [] for name, lit, f1, sf1, f2, sf2 in tabledata: f, sf = avgerrors([f1, f2], [sf1, sf2]) avgdata.append([name, lit, f, sf]) avgspectrum.append((f, sf)) compareSpectrum('avg', avgspectrum, litvals) with TxtFile('../src/tab_part2_spectrum_avg.tex', 'w') as f: f.write2DArrayToLatexTable(avgdata, ["Übergang", r'$\Delta \nu^\text{theo}$ / GHz', r'$\Delta \nu^\text{exp}_\text{avg}$ / GHz', r'$s_{\Delta \nu^\text{exp}_\text{avg}}$ / GHz'], ['%s', '%.2f', '%.2f', '%.2f', ], r"Theoretisches und aus den experimentellen Daten (\autoref{tab:hfs:spectrum}) gemitteltes Hyperfeinstrukturspektrum von Rubidium.", "tab:hfs:spectrum:avg") evalIntervalConst(avgspectrum)
def avg2vals(val1, val2): return avgerrors([val1[0], val2[0]], [val1[1], val2[1]])