# Fitting peak under background

**URL:** <https://root-forum.cern.ch/t/fitting-peak-under-background/56337>\
**Category:** Newbie\
**Created:** [September 11, 2023, 10:07pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337 "2023-09-11T22:07:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 11, 2023, 10:07pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/1 "2023-09-11T22:07:58Z")

</div>

Hi,

I have the following energy spectrum. I would like to fit the peak lying in the energy range 500 - 800 keV. I am not sure what function would best fit the peak and the background. I would like to extend the background from 430 to 1000 keV. I tried pol1 for the background and gaus for the peak but it didn’t work. Could anyone give any comments or suggestions? I have attached the histogram also.

 ![hEgamma](https://root-forum.cern.ch/uploads/default/original/3X/d/c/dc68ab48dfd54d278c3a02111fd6c0870c96273e.png)  
[hEgamma\_dc\_c\_eff.root](https://root-forum.cern.ch/uploads/short-url/wSYfjSHmVBbmNbAknWjVntAaMkr.root) (32.5 KB)

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [September 14, 2023, 10:00pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/2 "2023-09-14T22:00:58Z")

</div>

Hi @Mustak_Ali , that line shape from 600 → 750 keV is due a resonance decay thereby  
resulting in a Breit-Wigner. Fit this histogram with a Gauss around 420, a Breit-Wigner around 700 and again a Gaussian line shape around 1025. The background looks linear.  
-Eddy

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 18, 2023, 8:00pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/3 "2023-09-18T20:00:25Z")

</div>

Apologies for my delayed response.

Thanks a lot for your comments @Eddy_Offermann ! I had tried to fit the peak with multiple gaussians and for the background I used a quadratic fit. But I am going to use Breit-Wigner for the 718 keV peak.

 ![GT_Fit_5](https://root-forum.cern.ch/uploads/default/original/3X/8/b/8b80cf2b151e33e8ed2632975ae57273e875458a.png)

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [September 18, 2023, 8:39pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/4 "2023-09-18T20:39:08Z")

</div>

These multiple Gaussians would be odd. The detector resolution is given by the peak at 420 and 1025.

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 18, 2023, 8:55pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/5 "2023-09-18T20:55:50Z")

</div>

Hi @Eddy_Offermann,  
Are there any inbuilt Breit-Wigner functions available in ROOT?

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [September 18, 2023, 9:11pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/6 "2023-09-18T21:11:43Z")

</div>

Have a look at [BeitWigner](https://root.cern/doc/master/BreitWigner_8C.html)

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 18, 2023, 10:06pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/7 "2023-09-18T22:06:15Z")

</div>

Hi @Eddy_Offermann ,  
I tried to fit using Breit-Wigner+quadratic background. But the fit isn’t nice. I attach both the macro and the plot here. Any suggestions what am I missing?

 ![BW_fit](https://root-forum.cern.ch/uploads/default/original/3X/d/e/de47fc007d0b10a5d6af3fc11bfdf905d8ed0ca1.png)  
[fit\_GT\_gamma\_BW2.C](https://root-forum.cern.ch/uploads/short-url/n7dtmICxho3fPojSVtTSgGv7VQB.C) (1.4 KB)

Best regards,  
Mustak

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 18, 2023, 10:10pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/8 "2023-09-18T22:10:37Z")

</div>

Here I have attached the histogram.  
[hEgamma.root](https://root-forum.cern.ch/uploads/short-url/ywCjZPyR6Yz8qkH9laSePSQEjPJ.root) (32.5 KB)

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [September 21, 2023, 7:24pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/9 "2023-09-21T19:24:19Z")

</div>

This root file does not contain a histogram, only a TCanvas

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 21, 2023, 9:24pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/10 "2023-09-21T21:24:38Z")

</div>

Hi @Eddy_Offermann,  
If you open the canvas with TBrowser you can see the histogram.

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 21, 2023, 9:32pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/11 "2023-09-21T21:32:15Z")

</div>

I have now saved the histogram in a root file. You can find it just by opening the root file attached.  
Thank you.  
[output.root](https://root-forum.cern.ch/uploads/short-url/6CbqAJmkltFaFIJDKt3b7lbx7OR.root) (22.9 KB)

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [September 22, 2023, 10:08pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/12 "2023-09-22T22:08:25Z")

</div>

Reminding myself a bit more about gamma spectroscopy, this 700 bump is probably due to Compton scattering, see [overview](https://en.wikipedia.org/wiki/Gamma_spectroscopy) of gamma spectroscopy. Its line shape will depend very much on your experimental setup.`

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 22, 2023, 10:14pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/13 "2023-09-22T22:14:56Z")

</div>

Hi @Eddy_Offermann,  
The broad peak at ~ 0.7 MeV is due to the decay of the 10B(1+,0.718 MeV) → 10B(3+,gs). It is broad because of its half-life of 0.71 ns and the decay occurs over an extended distance after the target. This distorts the gamma-ray angle measurement and the Doppler reconstruction.

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [September 22, 2023, 10:47pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/14 "2023-09-22T22:47:01Z")

</div>

good, so it is a decay with a large half-life and therefore a Breit-Wigner line shape. Just puzzling why the right side is so steep, not like a Breit-Wigner. Can this limit on the gamma-ray angle be the explanation, aka what folding function makes it so steep ?

---

<div class="post-metadata">

**Author:** ![Mustak\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mustak_ali/32/26508_2.png) [@Mustak\_Ali](https://root-forum.cern.ch/u/Mustak_Ali)\
**Post date:** [September 25, 2023, 7:51pm UTC](https://root-forum.cern.ch/t/fitting-peak-under-background/56337/15 "2023-09-25T19:51:50Z")

</div>

Yes, the steep right side of the peak is not typical of a simple Breit-Wigner line shape. I am not sure what folding function makes it so steep.
