# Fitting Cs137 spectrum from Compton scattering experiment

**URL:** <https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854>\
**Category:** Newbie\
**Created:** [June 10, 2020, 12:15am UTC](https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854 "2020-06-10T00:15:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [June 10, 2020, 12:15am UTC](https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854/1 "2020-06-10T00:15:01Z")

</div>

[Compton.cxx](https://root-forum.cern.ch/uploads/short-url/lt9gRX2AkNrBurmf5ybR46G8xZR.cxx) (960 Bytes) [Compton.txt](https://root-forum.cern.ch/uploads/short-url/nF2iistqRYTvdmP2ChLIr3Ad1Dn.txt) (329.3 KB)  
Hello,

I am struggling to fit data of Cs137 spectrum from Compton scattering experiment with a single function which is the sum of the gaussian for the signal and the polynomial or an exponential for the background (or it could be sum of exponential and polynomial). I tried using the predefined functions, but my fit doesn’t look good. I am aware there is a way to create a customized function, though I don’t know how to create one that would fit the data well. I am very lost and any help would be greatly appreciated  
\_ROOT Version:\_ROOT 6.23/01

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 10, 2020, 6:06am UTC](https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854/2 "2020-06-10T06:06:59Z")

</div>

Maybe @moneta can give you some hints

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [June 10, 2020, 7:49am UTC](https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854/3 "2020-06-10T07:49:53Z")

</div>

Hi,  
att your mod macro  
main problem was TF1… ,pol20+gaus  
Cheers  
Otto

[Compton.cxx](https://root-forum.cern.ch/uploads/short-url/lBNbo6ceBgA81RiiQ0pVF3jqXVF.cxx) (1.1 KB)

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [June 10, 2020, 4:45pm UTC](https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854/4 "2020-06-10T16:45:14Z")

</div>

Wow, thank you very much! Just one question, how did you know to set the parameters to  
`g->SetParameters(1000, -2, 0, 0, 2000,450,40);`

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [June 11, 2020, 8:38am UTC](https://root-forum.cern.ch/t/fitting-cs137-spectrum-from-compton-scattering-experiment/39854/5 "2020-06-11T08:38:40Z")

</div>

Hi Edward,  
first 4 params are the pol3 (the background) which in your case  
looks approx linear crossing 0 around 1000-2000 with  
negative slope, the quadratic and cubic terms we let for the fit.  
The last is the gauss width, so approx 100/2, last but one the  
center of the peak and then the constant, it must be quite big.  
Btw. Its good practice before doing the fit to draw the function  
with the initial parameters.  
Cheers  
Otto
