def calcFermiKuriePlot(data): new = MyonData() for (x, y, sx, sy) in data.getPoints(): ny = sqrt(y / x**2) # sqrt(N/E^2) if not y == 0: nsy = sqrt(sy**2 / (4 * x**2 * y) + (sx**2 * y) / x**4) # sy / y^2 else: nsy = 0 new.addPoint(x, ny, sx, nsy) return new
def evalPedestal(): name = 'pedestal' data = MyonData.fromPath('../data/%s.TKA' % name) data.convertToCountrate() c = TCanvas('c_ped', '', 1280, 720) g = data.makeGraph('g_ped', 'channel c', 'countrate n / (1/s)') g.SetLineColor(1) g.SetLineWidth(1) g.GetXaxis().SetRangeUser(0, 20) g.Draw('APX') fit = Fitter('fit_%s' % name, 'gaus(0)') fit.setParam(0, 'A', 30) fit.setParam(1, 'x', 6) fit.setParam(2, '#sigma', 3) fit.setParamLimits(2, 0, 100) fit.fit(g, 3.5, 10.5) fit.saveData('../fit/%s.txt' % name) l = TLegend(0.55, 0.6, 0.85, 0.85) l.SetTextSize(0.03) l.AddEntry(g, 'pedestal', 'p') l.AddEntry(fit.function, 'fit with n(c) = A gaus(c; x, #sigma)', 'l') fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.3f', '%.3f'), ('%.3f', '%.3f')), chisquareformat='%.2f', units=('1/s', '', ''), lang='en') l.Draw() g.Draw('P') c.Update() c.Print('../img/%s.pdf' % name, 'pdf') return (fit.params[1]['value'], fit.params[1]['error'])
def evalUnderground(): data1 = MyonData.fromPath('../data/untergrund.TKA') data2 = MyonData.fromPath('../data/untergrund_2.TKA') data = MyonData.fromDataErrors(data1 + data2, data1.time + data2.time, data1.timed + data2.timed) data.convertToCountrate() datarebin = data.rebin(20) for d, suffix in [(data, ""), (datarebin, "_rebin")]: c = TCanvas('cu%s' % suffix, '', 1280, 720) g = d.makeGraph('gu%s' % suffix, 'channel c', 'countrate n / (1/s)') prepareGraph(g) g.GetXaxis().SetRangeUser(0, 700) g.Draw('APX') g.Draw('P') c.Update() c.Print('../img/underground%s.pdf' % suffix, 'pdf')
def makeEnergyPlot(): data = MyonData.fromPath('../data/betaspektrum.TKA') data.convertToCountrate() c = TCanvas('c', '', 1280, 720) g = data.makeGraph('g', 'channel c', 'countrate n / (1/s)') prepareGraph(g) g.GetXaxis().SetRangeUser(0, 250) g.GetYaxis().SetTitleOffset(1.2) g.Draw('APX') g.Draw('AP') c.Update() c.Print('../img/betaspectrum.pdf', 'pdf')
def makeGraph(channel): data = MyonData.fromPath('../data/energieaufloesung_%s.TKA' % channel) data.convertToCountrate() c = TCanvas('c_%s' % channel, '', 1280, 720) g = data.makeGraph('g%s' % channel, 'channel c', 'countrate n / (1/s)') prepareGraph(g) g.GetXaxis().SetRangeUser(0, 700) g.Draw('APX') ch = int(channel) if ch < 100: xmin, xmax = ch - 25, ch + 25 elif ch < 120: xmin, xmax = ch - 50, ch + 40 elif ch < 200: xmin, xmax = ch - 50, ch + 50 elif ch < 600: xmin, xmax = 0, 700 else: xmin, xmax = 0, ch + 45 fit = Fitter('fit_%s' % channel, '[0] + gaus(1)') fit.function.SetNpx(1000) fit.setParam(0, 'b', 0) # offset fit.setParam(1, 'A', data.getMaxY()) # amplitude fit.setParam(2, 'x', ch) # channel fit.setParam(3, '#sigma', 50) # sigma #fit.setParamLimits(0, 0, 1000) fit.fit(g, xmin, xmax) fit.saveData('../fit/energieaufloesung_%s.txt' % channel) if ch > 350: l = TLegend(0.15, 0.5, 0.45, 0.85) else: l = TLegend(0.55, 0.5, 0.85, 0.85) l.SetTextSize(0.03) l.AddEntry(g, "measurement", 'p') l.AddEntry(fit.function, "fit with n(c) =", 'l') l.AddEntry(None, "b + A gaus(c; x, #sigma)", '') fit.addParamsToLegend(l, (('%.4f', '%.4f'), ('%.2f', '%.2f'), ('%.2f', '%.2f'), ('%.2f', '%.2f'),), chisquareformat='%.2f', units=['1/s', '1/s', '', ''], lang='en') l.Draw() g.Draw('P') c.Update() c.Print('../img/energieaufloesung_%s.pdf' % channel, 'pdf') return (fit.params[2]['value'], fit.params[2]['error'], abs(fit.params[3]['value']), fit.params[3]['error']) # abs(sigma)
def evalFlythroughSpectrum(name, xmin, xmax): data = MyonData.fromPath('../data/%s.TKA' % name) data.convertToCountrate() c = TCanvas('c_%s' % name, '', 1280, 720) g = data.makeGraph('g_%s' % name, 'channel c', 'countrate n / (1/s)') prepareGraph(g) g.GetXaxis().SetRangeUser(0, 700) g.GetYaxis().SetTitleOffset(1.2) g.Draw('APX') # don't draw error bars => fit function in front maxY = data.getByY(data.getMaxY())[0] area = g.Integral(xmin, xmax) print('start fitting %s' % name) t1 = datetime.datetime.now() fit = Fitter('fit_%s' % name, langaufun, (xmin, xmax, 4)) fit.setParam(0, 's', 1) fit.setParam(1, 'm', maxY) fit.setParam(2, 'A', area) fit.setParam(3, '#sigma', 30) fit.fit(g, xmin, xmax, 'RBO') t2 = datetime.datetime.now() delta = t2 - t1 print('fitted in %d s' % int(delta.total_seconds())) fit.saveData('../fit/%s.txt' % name) if not name == "energiekalibration_100": l = TLegend(0.5, 0.55, 0.85, 0.85) else: l = TLegend(0.15, 0.55, 0.5, 0.85) l.SetTextSize(0.03) l.AddEntry(g, 'flight through with %s%% energy' % name.split('_')[1], 'p') l.AddEntry(fit.function, 'fit with n(c) =', 'l') l.AddEntry(None, '(landau(m, s) * gaus(0, #sigma))(c)', '') fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f'), ('%.3f', '%.3f'), ('%.2f', '%.2f')), chisquareformat='%.2f', lang='en') l.Draw() g.Draw('P') # redraw points with error bars c.Update() c.Print('../img/%s.pdf' % name, 'pdf') return ((fit.params[1]['value'], fit.params[1]['error']), (fit.params[3]['value'], fit.params[3]['error']))
def makeFermiKuriePlot(): data = MyonData.fromPath('../data/betaspektrum.TKA') data.convertToCountrate() data.convertChannelToEnergy() data = calcFermiKuriePlot(data) c = TCanvas('c', '', 1280, 720) g = data.makeGraph('g', 'energy E / MeV', '#sqrt{n/E^{2}}') prepareGraph(g) g.GetXaxis().SetRangeUser(0, 150) g.SetMaximum(0.004) g.GetYaxis().SetTitleOffset(1.3) g.Draw('APX') g.Draw('P') c.Update() c.Print('../img/betaspectrum_FermiKurie.pdf', 'pdf') g.GetXaxis().SetRangeUser(0, 80) g.SetMaximum(3e-3) fit = Fitter('fit', '[0]*(x-[1])*1e-6') fit.setParam(0, 'a', -0.3) fit.setParam(1, 'b', 55) fit.fit(g, 23, 45) fit.saveData('../fit/FermiKurie.txt') l = TLegend(0.65, 0.6, 0.85, 0.85) l.SetTextSize(0.03) l.AddEntry(g, 'Fermi-Kurie plot', 'p') l.AddEntry(fit.function, 'fit with a(E-b)', 'l') fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=["10^{-6}", ""], lang='en') l.Draw() c.Update() c.Print('../img/betaspectrum_FermiKurie_fit.pdf', 'pdf') return fit.params[1]["value"], fit.params[1]["error"]
def makeMultiGraph(files): c = TCanvas('c_m', '', 1280, 720) graphs = [] for file in files: if file.startswith('energieaufloesung'): data = MyonData.fromPath('../data/%s' % file) data.convertToCountrate() graphs.append(data.makeGraph('g_%s' % file, 'channel c', 'countrate n / (1/s)')) first = True for i, g in enumerate(graphs): g.SetMarkerStyle(1) g.SetMarkerColor(int(round(51 + (100. - 51) / 11 * i))) g.GetXaxis().SetRangeUser(0, 700) g.SetMaximum(100) if first: g.Draw('APX') first = False else: g.Draw('PX') c.Update() c.Print('../img/energieaufloesung_multi.pdf', 'pdf')
def main(): xmin, xmax = 0.55, 8 data = MyonData.fromPath('../data/zerfallszeit.TKA') data.convertToCountrate() data.convertChannelToTime() data.filterY(None, 0.2e-3) data.filterX(xmin, xmax) data = data.rebin(3) c = TCanvas('c', '', 1280, 720) g = data.makeGraph('g', 't / #mus', 'countrate n / (1/s)') prepareGraph(g) g.GetXaxis().SetRangeUser(0, 8.2) g.Draw('APX') fit = Fitter('fit', '[0]*1e-3*exp(-x/[1])') fit.setParam(0, 'A', 0.2) fit.setParam(1, '#tau', 2.2) fit.fit(g, xmin, xmax) fit.saveData('../fit/decayTime.txt') l = TLegend(0.6, 0.6, 0.85, 0.85) l.SetTextSize(0.03) l.AddEntry(g, 'measurement', 'p') l.AddEntry(fit.function, 'fit with n(t) = 10^{-3} A e^{- #frac{t}{#tau}}', 'l') fit.addParamsToLegend(l, (('%.3f', '%.3f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=['1/ms', '#mus'], lang='de') l.Draw() g.Draw('P') c.Update() c.Print('../img/decayTime.pdf', 'pdf') c.SetLogy() c.Update() c.Print('../img/decayTime_log.pdf', 'pdf')