Fitting multiple gaussians to dataset

Hi

I’m trying to fit two gaussians to my dataset in pyROOT but I’m facing some problems… The code I’m using right now is as follows:

func_1 = TF1(‘func_1’, ‘[0]*TMath::Gaus(x,[1],[2])’, np.min(x), 567)
func_1.SetParameters(-500,557,0.09)
fit_1 = g1.Fit(‘func_1’, ‘SR’)
graphs.append(fit_1)
fit_1.Draw(“L” “Same”)
ROOT.SetOwnership(fit_1, False)
func_2 = TF1(‘func_2’, ‘[0]*TMath::Gaus(x,[1],[2])’, 565, np.max(x))
func_2.SetParameters(-580,570,0.1)
fit_2 = g1.Fit(‘func_2’, ‘SR’)
graphs.append(fit_2)
fit_2.Draw(“L” “Same”)

The main problem is that I never see a fit for the first peak and sometimes it also doesn’t preform a fit on the second peak (they are both negative fyi). I first tried to use 1 function for the complete data set which was a sum of two gaussians, but this didn’t do the thing I wanted either. As you can see I’m now trying to fit the two peaks separatly by giving them their own range… anybody any ideas?

Hi,

This should work, maybe there is a problem with the negative Gaussian., I would need to have a working macro, including the data object, to understand the issue

Lorenzo

400.dqm.root (169.2 KB)

You must have the config_dqm file as well as the actual program EventDisplay.py … the part I’m talking about is implemented in the MakePlot function…

Can you please extract the code and make a minimal simple script, with the few lines of code you have written before ?
Thanks
Lorenzo

This isn’t really possible because of all the different methods that are applied before making the plot :confused:

Hi,

You should save the histogram in a file and then have a macro to fit the histogram with the code you have written above

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.