# 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:** 3

<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:36pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/43 "2022-02-13T17:36:35Z")

</div>

You can “fix” whatever parameter you want.

BTW. Note that the “area” parameter of a “`gausn`” is always its “full” integral. You integrate the function from some “xmin” to some “xmax”, so such “integral” will always be \<= “area”.

---

<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:48pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/44 "2022-02-13T17:48:42Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> “full” integral.

When you say full integral, it is the value of this first part below: 1/sigma\*squareRoot(2Pi) .  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/7/67ee7d61fbe0c37fdcce63192a661fc7638f8022.png)  
The integral, however , is the value below.

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

A bit confusing. When we fit gausn instead of gaus, do we tell somewhere in the code before it prints out the information, show the area as the 1st parameter. Obviously, the area is NOT equal to normalizating constant.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/d/9d13d31419b7acd4abcfa1232dac353332df7a59.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 13, 2022, 5:51pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/45 "2022-02-13T17:51:08Z")

</div>

`gROOT->GetFunction("gaus")->Print();`  
`gROOT->GetFunction("gausn")->Print();`

---

<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, 6:10pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/46 "2022-02-13T18:10:26Z")

</div>

It’s nice that I can see quicker like that instead of going through the ROOT website. I wasn’t aware. Thanks for that.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/3/5/35fc1f3e755a21406ea9d9f70f6bbccfb08e771d.png)  
The word constant here is indeed the parameter p0 as we know. The height term in gaus.

That’s the [website](https://root.cern.ch/root/htmldoc/guides/users-guide/FittingHistograms.html) version.

![image](https://root-forum.cern.ch/uploads/default/original/3X/2/a/2a2774b1a8d675c0cb91859a1094410c8152c683.png)  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/7/e7b667801c9d7b22b3cca6b27f4b4d34e16c4d3b.png)

To be normalized to 1, p0 here should be set to squareRoot(2xPi )x sigma in gaus.

Gausn is actually different than PDF of the Gaussian function as said on this [website](https://en.wikipedia.org/wiki/Gaussian_function).

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/4/7/47b038d0b0268ae654306f2a22dd095948ae1bb8.png)

Ok. let me try my shot to explain my confusion.  
In gaus, we give height as parameter, it draws the shape nicely. In gausn, we need to give area to be drawn. By looking at the histogram, I can easily give the hight but not the area. I need to calculate the area from height x sigma x sqrt(2 x Pi) . Isn’t it tiring?

---

<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, 6:33pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/47 "2022-02-13T18:33:29Z")

</div>

> [@Facing Problem while fitting](https://root-forum.cern.ch/t/facing-problem-while-fitting/38305/22):
>
> You need to estimate initial function’s parameters looking at the spectrum, e.g. ([estimated\_sigma = estimated\_fwhm / 2.35](https://en.wikipedia.org/wiki/Full_width_at_half_maximum)): [estimated\_area = 2.51 \* estimated\_height \* estimated\_sigma = 1.06 \* estimated\_height \* estimated\_fwhm](https://en.wikipedia.org/wiki/Gaussian_function)

---

<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, 6:41pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/48 "2022-02-13T18:41:59Z")

</div>

Yeah, I am aware of that.

![image](https://root-forum.cern.ch/uploads/default/original/3X/c/5/c576127a1d35c00bc86862bf6129027e4fee0da5.png)  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/1/c19fef39f7727fff70c67c5339b995d693590ebf.png)

Here below, how p0 parameter turns to an area as a fit parameter after fitting?  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/a/4/a4d9cd1d9540968a60bc50da69b487b395ceda20.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 13, 2022, 7:43pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/49 "2022-02-13T19:43:23Z")

</div>

When we find the integral and error, we use these two methods:

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

Should we not use these for gausn? Instead, should we just retrieve the parameter and its error, instead?

---

<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 14, 2022, 10:03am UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/50 "2022-02-14T10:03:40Z")

</div>

@Wile_E_Coyote  
From terminal results, if I do gross area - background area with a calculator, it doesn’t match the ROOT net area result.

Is that normal!

---

<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 14, 2022, 10:45am UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/51 "2022-02-14T10:45:09Z")

</div>

Try:

```cpp
{
  TF1 *f = (TF1*)gROOT->GetFunction("gausn");
  Double_t area = 100., mean = 0., sigma = 1.;
  f->SetParameters(area, mean, sigma);
  std::cout << "area = " << area << std::endl;
  for (Int_t i = 1; i < 10; i++)
    std::cout << i << " : " << area - f->Integral(mean - i * sigma, mean + i * sigma) << std::endl;
}

```

BTW. Make sure that you use:  
`total = g1 + g2 + bg`  
`bg_g1 = total - g1 = g2 + bg` (i.e., it’s always `>= bg`)  
`bg_g2 = total - g2 = g1 + bg` (i.e., it’s always `>= bg`)

---

<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 15, 2022, 4:08pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/53 "2022-02-15T16:08:12Z")

</div>

![image](https://root-forum.cern.ch/uploads/default/original/3X/2/3/23cdee2745a0a67421e7adf6edb7b66c2e922261.png)

```auto
{

TCanvas *c1 = new TCanvas("c1", "c1", 800,400);
c1->Divide(2,1);
c1->cd(1);

  TF1 *f = (TF1*)gROOT->GetFunction("gausn");
  Double_t area1 = 100., mean1 = 0., sigma1 = 1.;
  f->SetParameters(area1, mean1, sigma1);
  f->Draw();
  std::cout << "area 1 = " << area1 << std::endl;
  std::cout << "height 1 = " << area1/ (sigma1*sqrt(2.*TMath::Pi()) ) << std::endl;

  Int_t i;
  cout << "To see the percentage of the marked area in the range of stated sigma in PDF" << endl;
  for (i = 1; i < 10; i++)
    std::cout << i << " area 1: "<< area1 << " integral: " << f->Integral(mean1 - i * sigma1, mean1 + i * sigma1) << "\t\tThe rest: " << area1- f->Integral(mean1 - i * sigma1, mean1 + i * sigma1) << std::endl;

c1->cd(2);

  TF1 *f2 = (TF1*)gROOT->GetFunction("gaus");
  Double_t height2 = 100., mean2 = 0., sigma2 = 1.;
  f2->SetParameters(height2, mean2, sigma2);
  f2->Draw();
  std::cout << "area 2 = " << sqrt(2.*TMath::Pi()) *height*sigma2 << std::endl;
  for ( i = 1; i < 10; i++)
    std::cout << i << " : " << f2->Integral(mean2 - i * sigma2, mean2 + i * sigma2) << std::endl;
}

```

I added more on that teaching code. What was your point about gausn?

BTW, I am suprised about the gaus plot above. Its x axis range is between + sigma and - sigma when we do not state it explicitly. Anyways.

> [@Wile\_E\_Coyote](#):
>
> BTW. Make sure that you use:  
> `total = g1 + g2 + bg`  
> `bg_g1 = total - g1 = g2 + bg` (i.e., it’s always `>= bg`)  
> `bg_g2 = total - g2 = g1 + bg` (i.e., it’s always `>= bg`)

That’s interesting because I wasn’t imagining the ROOT is calculating it like that. Surely, this calculation should be only valid for common (linked) background line, not for the separate bcg line approach. **Right!** I guess it won’t be valid if the peaks are way apart from each other, then in this case, we need to define 2 bcg functions. I guess ROOT regards the broken line as continous as if there was 1 line.

Question: When we say g1, don’t we mean the net area + its background ?  
Answer: Ohh. NO, it’S not because we use the integral of g1 when we get the NET area of g1.

Namely, g1 and g2 are our NET sginals. 🤦‍♂️  
That’ amazing to see how easily the ROOT finds the net area.

I made it clear below with my worst drawing.

 ![BCG LER](https://root-forum.cern.ch/uploads/default/original/3X/9/8/980a4bcb9a2c2055e1fe4e240c514b6dd1c1cdcb.jpeg)

---

<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 15, 2022, 4:14pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/54 "2022-02-15T16:14:16Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> (i.e., it’s always `>= bg`)

That’ why we limit ourselves within the g1 limits when we try to retrieve the bcg\_g1.

For instance: we use lower and upper bin edges as limits.

double bcg\_g1 = bcg-\>Integral(g1\_X\_LBE, g1\_X\_UBE) / BinWidth ;

---

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

</div>

The [“toy MC”](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) (by default) sets the “sigma” parameter = `10` for both “`gausn`” peaks. Try to play with “sigma” = `5` and then with “sigma” = `20` (for both peaks, of course).

---

<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 15, 2022, 4:45pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/56 "2022-02-15T16:45:36Z")

</div>

My little adapted code above, says nothing changes.  
I mean I knew that after around 5 sigma, the integral percentage reaches to 100 percent already, so no need to go to infinity to retrieve the whole integral.

Is that your point?  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/2/9/2995187e510f7e01b9f6fa1c8d56fa9047ad8f5b.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 15, 2022, 7:22pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/58 "2022-02-15T19:22:51Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> The [“toy MC”](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) (by default) sets the “sigma” parameter = `10` for both “`gausn`” peaks. Try to play with “sigma” = `5` and then with “sigma” = `20` (for both peaks, of course).

That’s the results respectively for 5 , 10, and 20 sigma. Plus, everytime you run it, the results change due to the randomness. Thus, I will say they are incomparable.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/c/9c297e9e24c995b513367e0b892bf401bff28f90.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 15, 2022, 7:43pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/59 "2022-02-15T19:43:26Z")

</div>

For each “sigma” setting, you can play your games with “Integral” (comparing your “gross area”, “background area” and “net area”).

---

<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 15, 2022, 7:51pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/60 "2022-02-15T19:51:16Z")

</div>

Ref: Gilmore’S fantastic book.

![image](https://root-forum.cern.ch/uploads/default/original/3X/1/1/1166b78d62da9a5e3b2c64f943bad21bf672d573.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 18, 2022, 7:54am UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/61 "2022-02-18T07:54:34Z")

</div>

One question: What’s the differerence between the area found from gausn parameter and the integral value of g1 within the specified X-axis range?

I think evertime we limit ourselves within smaller x axis range than -+3sigma, our results from gausn parameter will always be (perceptively) bigger than the area from integral within the specified range.

Supportive info:

The area found from the gausn parameter = height x sigma x sqrt(2\*pi) originally in the integral range of - infinity to + infinity.  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/f/7/f76a696113c141f26882ed246dc78941d1f941d1.png)

On the other hand, the area found from specified gausn X range =  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/6/e6479e578977ed88972726f7b6bba96f3b0a4413.png)

As we knew in advance and as we tested before, the X axis range becomes important if you choose the range smaller than -+5sigma which correspond to %99.9 . After even -+3sigma, x axis the coverage range becomes irrelavant due to %99 coverage.

Am I right in my arguments?

---

<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 18, 2022, 11:35am UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/62 "2022-02-18T11:35:43Z")

</div>

Obviously, the first parameter of the “`gausn`” function is by definition equal to the “`a*c*sqrt(2*pi)`” from your analytical formula.

---

<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 19, 2022, 8:25pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/63 "2022-02-19T20:25:54Z")

</div>

What you said is correct Not just for Me, but for everbody.

> [@spyhunter01](#):
>
> On the other hand, the area found from specified gausn X range =  
> ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/6/e6479e578977ed88972726f7b6bba96f3b0a4413.png)

My point was that we should always add this percentage (or you can call it as CORRECTION FACTOR) if you limit your range of interest (ROI) narrow in the case of , for instance, existing neighbouring peaks.

That’s all.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 5, 2022, 8:26pm UTC](https://root-forum.cern.ch/t/setting-parameter-limits-fixing-parameters-and-their-effects-on-fitting/48677/64 "2022-03-05T20:26:31Z")

</div>

Closed on March 5, 2022, 8:26pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

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