# Problem in adjusting the parameters

**URL:** <https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937>\
**Category:** Newbie\
**Created:** [April 17, 2020, 5:53am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937 "2020-04-17T05:53:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 17, 2020, 5:53am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/1 "2020-04-17T05:53:24Z")

</div>

Hi @Wile_E_Coyote @couet  
A plot is made by me and i am fitting this plot by a user defined function.  
Below are the files that I’m working on:  
[eu\_gu\_1.txt](https://root-forum.cern.ch/uploads/short-url/kn9woacPX2mqQI0v5OngH2uYeGm.C) (44.1 KB)  
[rough.C](https://root-forum.cern.ch/uploads/short-url/yNQzOo8n19jJ2eZsQ4XJYuLaylK.C) (1.1 KB)

 ![ee](https://root-forum.cern.ch/uploads/default/original/3X/c/4/c43df69fdbcdd15c4a3906262efaaf957b8ab0b4.png)  
I want this red line to pass from the middle of the dark black part.  
please help me in adjusting the parameters.

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 17, 2020, 6:21am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/2 "2020-04-17T06:21:09Z")

</div>

I guess @moneta can help.

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 17, 2020, 8:35am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/3 "2020-04-17T08:35:15Z")

</div>

@Wile_E_Coyote @couet @moneta  
The problem seems to arise as soon as i change the parameters even so slightly.  
nan is shown in the parameter error.  
The parameters that i got are the best that i could get so far.  
Please see how and why this nan appears in parameters error even after changing the parameters slightly.  
Help me!!!

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 18, 2020, 3:31am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/4 "2020-04-18T03:31:34Z")

</div>

@Wile_E_Coyote  
Is there any possible way of reducing the Chi sqaure or Chi square/ndf value.

 ![ee](https://root-forum.cern.ch/uploads/default/original/3X/3/3/33554eb8883eb2e49b206c77383a06e466379c60.png)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 18, 2020, 9:54am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/5 "2020-04-18T09:54:18Z")

</div>

Your fit function tries to describe the “background” only.  
But all “data points” contribute to the chi^2.  
If you “remove” peaks, you will get lower chi^2.

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 18, 2020, 10:07am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/6 "2020-04-18T10:07:07Z")

</div>

Thanks @Wile_E_Coyote.  
Can we do anything about fixing parameters?  
because each parameter is showing large error as you can see above.  
Also, if i am changing the values slightly error becomes nan.

 ![e](https://root-forum.cern.ch/uploads/default/original/3X/9/7/9702c56e40e9debd53d792d7dea6dafb0a4476ab.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 7:30am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/7 "2020-04-20T07:30:29Z")

</div>

@Wile_E_Coyote suggested you to try to remove the peaks.

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 20, 2020, 8:11am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/8 "2020-04-20T08:11:21Z")

</div>

@couet @Wile_E_Coyote  
I see a decrease in the value of chi square and there comes the next question which is how can this nan be removed? because when i slightly change the parameter it shows nan.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 8:26am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/9 "2020-04-20T08:26:56Z")

</div>

> [@robertfroast](#):
>
> I see a decrease in the value of chi square

You have changed something in you macro ? If yes, can you post the last version ?

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 20, 2020, 8:32am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/10 "2020-04-20T08:32:45Z")

</div>

ok. @couet  
I have only remove the peak points.  
The only file that gets changed is [rough.txt](https://root-forum.cern.ch/uploads/short-url/hGNPF4QYqatHuPz2E61MUhqORh.txt) (40.7 KB)  
rest of the files are same as before.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 8:50am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/11 "2020-04-20T08:50:22Z")

</div>

I tried a very stupid thing which seems actually working:

```auto
   RT->SetParameter(0,1.);
   RT->SetParameter(1,1.);
   RT->SetParameter(2,1.);
   RT->FixParameter(3,1.);
   RT->SetParameter(4,1.);
   RT->SetParameter(5,1.);
   RT->SetParameter(6,1.);

```

And I get:

 ![Screenshot 2020-04-20 at 10.49.55](https://root-forum.cern.ch/uploads/default/original/3X/a/8/a8faa37d45fe02842396881d06be8372c4c092cd.png)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 20, 2020, 9:00am UTC](https://root-forum.cern.ch/t/problem-in-adjusting-the-parameters/38937/12 "2020-04-20T09:00:13Z")

</div>

There are still many peaks which need to be “removed” before trying to fit the “background”.
