Fitting multiple gaussians to dataset


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)
fit_1 = g1.Fit(‘func_1’, ‘SR’)
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))
fit_2 = g1.Fit(‘func_2’, ‘SR’)
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?


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


400.dqm.root (169.2 KB)

You must have the config_dqm file as well as the actual program … 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 ?

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


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


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