# How to improve fit/add background function and gaussians to one fit function?

I am trying to fit an NaI gamma spectrum in order to get the peaks (and FWHMs) of the spectrum, calculate the energies of the spectrum, and find the parents within the Radium-228 decay chain. As you can see, my Gaussian fits work correctly, but the background fit looks broken and could be improved. How could my code be modified to improve the fit and/or combine a background and gaussians properly to one fit function?

Please read tips for efficient and successful posting and posting codeWatch.C (3.9 KB)

ROOT Version: 6.22
Platform: Ubuntu 18.02
Compiler: Not Provided

Hi. If you want to combine gaussians and background in one fit function you could try

``````TF1 *total = new TF1("ftotal","gaus(0)+gaus(3)+gaus(6)+gaus(9)+gaus(12)+gaus(15)+gaus(18)+#form of your background #",35,950)
``````

(gaus (i)= fit for 1 peak)
, this way you will have a single function that fits gaussians on background. Your background has a strange shape so you can only fit it approximatively: you will have a general background trend (a function) with some strange peaks/valleys/“blobs” superimposed over it(e.g. you can remark a change in the background trend near the last peak (maybe an unresolved peak from an isotope???)) . Using only one function I think you can improve a bit your fit ( at least graphically) but your background will always spoil it a bit if you use a “simple” function.
Maybe this can help you
Ps: set attentively fit parameters with SetParameters, otherwise you can obtain a straight line at the bottom of your plot if you use such an elaborate fit function

Hi there.

So I attempted to implement a linear background fit to the fit function in the following Eu spectrum. As you can tell, my fit is way off the mark, even with the starting parameters. Is there something I am missing here?
Eu_CalibrationV2.C (7.8 KB) Eu.pdf (26.4 KB) Europium_152.txt (10 KB)

Try to eliminate the background first, using available one-dimensional background estimation methods from the TSpectrum class.