return type values: 1 : normal 0 : fit fail or (Not exist this quantity of certain panel) -1 : number of points < 2 -2 : Chi2/NDF < 0.0001 -3 : NDF == 0 except the reason number of points <2
35def linearFit(h_temp, opt="QNS+"):
36 default_dic = {"p0": 0., "p0_err":0., "p1": -1., "p1_err":-1., "chi2":-1., "mean":0., "mean_err":0.}
37
38
39
40
41
42
43
44 Qtag = 0
45 if not h_temp:
46 Qtag = -1
47 return (Qtag, default_dic)
48
49 if h_temp.GetN()< 2:
50 Qtag = 1
51 return (Qtag, default_dic)
52
53
54 fit_result = h_temp.Fit("pol1", opt)
55
56 par_a = round(fit_result.Value(0), 2)
57 par_a_E = round(fit_result.ParError(0), 2)
58 par_b = round(fit_result.Value(1), 2)
59 par_b_E = round(fit_result.ParError(1), 2)
60
61 if fit_result.Ndf() == 0:
62 Qtag = 2
63 chi2 = 0
64 else:
65 chi2 = round(fit_result.Chi2()/fit_result.Ndf(), 2)
66
67 mean = round(h_temp.GetMean(2), 2)
68 mean_rms= round(h_temp.GetRMS(2), 2)
69
70 dic = {"p0": par_a, "p0_err":par_a_E, "p1": par_b, "p1_err":par_b_E, "chi2":chi2, "mean":mean, "mean_err":mean_rms}
71 return (Qtag, dic)
72
73