Hey there Root Team,
my problem with the following skript i wrote is, that the fit for the used datasets sometimes doesn’t work. If i change the offset (from 0 to 100 or 1000) the plot mostly works, but not all the time.
Fyi the function is a lorentzian.
maybe you can help me.
cheers,
Paul
[code]import ROOT
import csv
from array import array
import math
import sys
import numpy as py
def main():
c1 = ROOT.TCanvas(“c1”,“Lorentz Fit”,200,10,500,500)
fit = ROOT.TF1(“fit”,fitfkt(),0.0004,0.0017,4)
fit.SetParameters(1,1,1,1)
fit.SetParNames(“vertical”,“width”,“horizontal”,“offset”)
x = array("f", [0])
y = array("f", [0])
z = array("f", [0])
with open('21_90deg_HM1508.csv','r') as file:
r = csv.reader(file,delimiter=',')
for row in r:
x.append( ROOT.Double(row[0])*0.2672*3.363*0.0001)
y.append( ROOT.Double(row[1])*100+200)
z.append( -ROOT.Double(row[2])+500)
gr = ROOT.TGraph(len(x),x,z)
gr2 = ROOT.TGraph(len(x),x,y)
gr.Fit(fit)
fit.SetLineColor(1)
gr2.SetLineColor(5)
gr.Draw()
gr2.Draw("SAME")
c1.Print("fit_21_90.png")
parameters = fit.GetParameters()
print("fitting result: {parameter1}, {parameter2}, {parameter3}, {parameter4}".format(
parameter1 = parameters[0],
parameter2 = parameters[1],
parameter3 = parameters[2],
parameter4 = parameters[3]
))
l = 1.054571800 /(parameters[1]*1.4838*9.274*10000000000)
print ("The mean lifetime is:")
print l
class fitfkt:
def call(self, x, parameters):
a = parameters[0] # shape
b = parameters[1] # location of minimum
c = parameters[2] # scale
d = parameters[3] # baseline
x = x[0]
y = (a/3.14159265359)(b/2)/((x-c)(x-c)+0.25bb)+d
return y
if name == “main”:
main()
raw_input()[/code]
21_90deg_HM1508.csv (68 KB)