# Setting Parameter Limits, Fixing Parameters and Their effects on fitting

**URL:** <https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677>\
**Category:** ROOT\
**Created:** [February 6, 2022, 6:09pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677 "2022-02-06T18:09:29Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [February 9, 2022, 2:41pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/21 "2022-02-09T14:41:16Z")

</div>

Looking at your macro, it seems to me that you are using an ancient ROOT 5.  
That is why the `"P"` fit option is ineffective.

In any case, you’d better clean up your macro so that you can use: `.x test1.C++`

BTW. To make your macro also ready for ROOT 6, you will need to replace:  
`area = function->Integral(a, b, params);`  
with:  
`function->SetParameters(params); area = function->Integral(a, b);`

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 9, 2022, 3:07pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/22 "2022-02-09T15:07:38Z")

</div>

Don’t make me cry again. My laptop was broken, so I had to use my ancient DELL. There is ONLY windows 10 installed on it. I was doing everyting with .x test1.C++ style on linux before, but it doesn’t work in that way () on windows right now (I guess) due to the exe I used from ROOT website .

I think I used to installation method stated [here](https://root.cern/install/) down there in the last part.

BTW, I already use area = function-\>Integral(a, b);

For instance, what is the result in your computer, can you post it to me. I assume you haven’t seen any error or logic mistake in the code, have you?

---

<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:** [February 9, 2022, 3:18pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/23 "2022-02-09T15:18:38Z")

</div>

I only looked at the source code. I wasn’t able to run your macro with ROOT 6 so I gave up.

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 9, 2022, 3:21pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/24 "2022-02-09T15:21:58Z")

</div>

My root version: root\_v5.34.36.win32.vc12

I don’t have any clue why I can run but not compile and run in my version now.

I used to write as I was doing before in linux. Not sure, why your computer cannot run.

It seems there is ROOT6 for windows [here](https://root.cern/releases/release-62406/). Let me give it a try.

It seems root 6 is installed and giving too many errors after running. Very nice ☹

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/0/80674e66a9daa9c20d7f453482745ccf22acb80f.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:** [February 9, 2022, 6:00pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/25 "2022-02-09T18:00:02Z")

</div>

A slightly modified version is attached below (just to make it ROOT 6 and C++ compiler ready).

You can now play with different fit options and compare the results (note that the “real” shape of the “background” is usually not a simple straight line and the “real” shape of the “signal” is usually not a simple gaussian).

[test1.C](https://root-forum.cern.ch/uploads/short-url/wRK3A9ecKlDKwWI5goZZiBZQXpX.C) (10.9 KB)

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 9, 2022, 9:21pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/26 "2022-02-09T21:21:40Z")

</div>

Alright, back to the business. I installed root6 in Ubuntu as subsystem in windows 10. It took 7hours to install and compile root6. Insane!

When I compile and run with “.x …cpp++” , everything works now.

Cheers.

---

<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:** [February 10, 2022, 11:52pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/27 "2022-02-10T23:52:36Z")

</div>

“`Fit data is empty`” suggests that the macro did not find the input data file (so the histogram is empty).

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 11, 2022, 1:48pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/28 "2022-02-11T13:48:00Z")

</div>

I see. That was my first time to use ubuntu like an application on windows.  
I figured out the correct PATH, now it worked. Let me investigate.  
I am happy to see that I can compile + run now finally and properly.

BTW, it turns out the correct PATHs are:  
file.open("/mnt/c/root-6-24-06-build/macros/Co60.txt", ios::in);  
//ON UBUNTU While running WINDOWS  
///file.open(“C:\root-6-24-06-build\macros\Co60.txt”, ios::in);  
//ON WINDOWS ROOT terminal

For some reason, I had to install [Xming X server](https://sourceforge.net/projects/xming/) for visualization. Also, I had to type : export DISPLAY=“localhost:0” before entering the root.

Is there any another way to get the visualization working when I just run the code.Plus, background area style looks different than before.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/0/e0b0e0ff21e9c02cfbe9eb48a2d3e46e738374e4.png)

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 11, 2022, 6:59pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/29 "2022-02-11T18:59:50Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> You can now play with different fit options and compare the results (note that the “real” shape of the “background” is usually not a simple straight line and the “real” shape of the “signal” is usually not a simple gaussian).

Alright, I can turn back to my discussion again since root6 issue an compilation issues are done.

Before starting the analysis, I did some assumptions. Actually, I try many methods all together to compare the results. Anyway, I know the peaks might not even be a Gaussian or the backgrounds might be some quadratic polynomials in higher degrees. Putting all aside as options, my purpose is not the test all now.

My main goal at the moment is to compare the basics. For instance, I want to compare the histogram results for gross , background and net areas with the results of ROOT fittings through the functions.

All I see is that they differ if I don’t fix my parameters. When I do, I loose the errors in return.  
The conclusion is that SHOULD I accept the ROOT results as OK? or SHOULD I find a new method which I think I did?

BTW, here are some results again:  
Form fitting: TFitResultPtr r\_total = h1-\>Fit(total, “EMRS”);  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/6/869774595607fe771781f95fa8fe45bf6b28ff51.png)

From histogram:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/f/7ff7fe976ad1ec6fe0b70b74c21ea3e7902e1b38.png)

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 11, 2022, 7:18pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/31 "2022-02-11T19:18:02Z")

</div>

I know that part. Thus, you suggest me to play with , for instance, pol1 and pol2 to see which one is closer to the histogram results? Is there any right or wrong results at all? Or, is it all model dependent procedures?

Should I infer this from your answer? What do you guys do normally? Do you set one method as your reference or do you give all results together and let the people decide?

I surely assume that you will start your work with some pre-defined accepted assumptions. Right!

BTW, thanks for the enlightning discussion.

---

<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:** [February 11, 2022, 11:33pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/32 "2022-02-11T23:33:55Z")

</div>

I think you should start to play with some “well-defined” histograms. That means running a simple, dedicated simulation (a “toy MC”) at least several times. Each time you run it, it will create a slightly different histogram, so you will get a “feeling” of how the fitting procedure behaves, as the “exact” parameters’ values will always be the same (and known, of course).

> [@Should we use integral method in TF1 or GetBinContent method in TH1 to get the integral from overlapping Gaussian peaks?](https://root-forum.cern.ch/t/should-we-use-integral-method-in-tf1-or-getbincontent-method-in-th1-to-get-the-integral-from-overlapping-gaussian-peaks/47398/10):
>
> Play with a simple, dedicated simulation (a “toy MC”). The histogram is filled with each component separately (it is the preferred method, I guess): { Bool\_t bg\_pol2 = kFALSE; // simulate a "pol2" or a "broken line" background // gRandom-\>SetSeed(0); // make it "really random" // gStyle-\>SetOptFit(); // print fit parameters in the statistics box ROOT::Math::MinimizerOptions::SetDefaultMinimizer("Minuit2"); Int\_t n = 200; // number of bins Double\_t xl = 360., xr = xl + n; // make s…

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 12, 2022, 12:29pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/33 "2022-02-12T12:29:15Z")

</div>

Political answers again. I see your “well-defined histograms" point if I am not mistakenly wrong. By creating the functions in advance and then filling the histogram, I think you get rid of the blur fog on the clarity of the histogram with unproved and unambigious peak shapes in advance. I guess it’s the same thing of saying that this is my accepted MODEL in the begining.

> [@Wile\_E\_Coyote](#):
>
> as the “exact” parameters’ values will always be the same (and known, of course).

When you say “known and exact parameters”, we haven’t fix the parameters but just set the parameters in the beginning in your simulation code. Is it still regarded as fixed in that occasion?

My sincere appreciation to our discussion.

---

<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:** [February 12, 2022, 12:41pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/34 "2022-02-12T12:41:14Z")

</div>

You can compare the “fitted” parameters (e.g., playing with different fit options) with the “true” ones (that were used to simulate the histogram, but note that each time you run the simulation, you will get a slightly different histogram).  
Of course, for test purposes, you can also use one kind of background for the simulation but then a different type for fitting and so on.

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 12, 2022, 12:54pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/35 "2022-02-12T12:54:14Z")

</div>

No worries, I’ll play with all. That’s my job.

> [@Wile\_E\_Coyote](#):
>
> but note that each time you run the simulation, you will get a slightly different histogram).

I noticed the Random filling method , no worries. For instance, all answers below are slightly different than each other.

Can you tell me what MinFCN, NDF, and edm stand for as words here on the terminal results?

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/e/8ec58fa6c592e7270e669e46c981044c43242536.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:** [February 12, 2022, 4:21pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/36 "2022-02-12T16:21:52Z")

</div>

> [@Minuit/Migrad Fitter](https://root-forum.cern.ch/t/minuit-migrad-fitter/42525):
>
> Hello, When I execute the command fitr-\>Print(); ROOT prints the following statistics MinFCN Chi2 NDf Edm NCalls What are MinFCN, Edm, and NCalls?

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 13, 2022, 11:52am UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/37 "2022-02-13T11:52:44Z")

</div>

I’ll have couple of follow up questions about the discussion for the update. I start to change the code’s approach a bit.

Problems in my mind:

1. TH1F or TH1D, which one is more suitable to the data?

2. I got round of error on gross area 1, how can be fixed? I’ll attach the terminal view.

3. After all is done properly, I may fill the histogram with the integrals from functions instead of the real data. I think it will be pre-defined MODEL based analysis in that way. What is your thought about that?

![image](https://root-forum.cern.ch/uploads/default/original/3X/6/e/6e7fe3e8165f83cba76036c7bb1a45572c41fa19.png)

[DigitalIntegrationProcedures.cpp](https://root-forum.cern.ch/uploads/short-url/t66v1LSmTpfUrlBZVYxWytREBtD.cpp) (10.4 KB)  
(UPDATED)

[Co60.txt](https://root-forum.cern.ch/uploads/short-url/2V3MjTLmHmflNJxuqoXZjQoyWoe.txt) (3.5 KB)

Cheers.

---

<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:** [February 13, 2022, 4:17pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/38 "2022-02-13T16:17:55Z")

</div>

Try with: `g...->IntegralError(..., 1e-6)`

In your case, I don’t think it makes sense to try to “minimize” the RAM usage by using [single-precision](https://en.wikipedia.org/wiki/Single-precision_floating-point_format), instead of the default [double-precision](https://en.wikipedia.org/wiki/Double-precision_floating-point_format), floating-point format for histograms’ contents.

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 13, 2022, 4:43pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/39 "2022-02-13T16:43:31Z")

</div>

I forgot. Is this epsilon (1e-6) related to the precision of finding the mean? Should I keep playing with that number until the roundoff error is demolished? I found [Moneta](https://root-forum.cern.ch/t/gslerror-nan-and-minuit/7789) mentioned about that.

My conclusion: error disappears as I play with my integral limits. If I go from Lower bin 400 to upper bin 530, I see NO ERROR. Thus, it’s a matter of limits and the ability of fitting procedure within those limits. Am I right?

I see the terminal resuls and the fit result DONOT MATCH. First parameters of each gaussian should be the integral of those peaks due to the usage of Gausn, but the results give different outcomes comparison to parameter outcomes.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/d/a/dafe35f164e8a2283d22e71decf7199a21ed13c1.png)

One more thing is that the broken line is not broken where I set the value. I want it to break at the bin number 462. Why is that?

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/3/5/35fc7ba729f576a70b96ade9be7f6bbbf82fbd01.png)

What about my 3rd question?

> [@spyhunter01](#):
>
> 1. After all is done properly, I may fill the histogram with the integrals from functions instead of the real data. I think it will be pre-defined MODEL based analysis in that way. What is your thought about that?

---

<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:** [February 13, 2022, 5:24pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/41 "2022-02-13T17:24:39Z")

</div>

If `1e-6` is still too small, try `1e-5`.

The position of the “breakpoint” is a fitted parameter.

Yes, I think it is a good idea to start with [a “well-known” histogram](https://root-forum.cern.ch/t/should-we-use-integral-method-in-tf1-or-getbincontent-method-in-th1-to-get-the-integral-from-overlapping-gaussian-peaks/47398/10).

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [February 13, 2022, 5:29pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/42 "2022-02-13T17:29:46Z")

</div>

What happens when I fix the break point parameter which I needed. Otherwise, it will be wrong.  
I fixed it to the bin number 460, and it looks like OK.

However, the roundoff error 18 is so sensitive to the limits I choose. It only worked from 400 to 460 for the 1st peak and from 460 to 430 bin numbers for the 2nd peak.

Do you think that it’s totally OK to play with numbers until getting NO ERROR?

[Previous page](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677.md?page=1)

[Next page](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677.md?page=3)
