# Clarifying a user defined function (skewed gaussian)

**URL:** <https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186>\
**Category:** Newbie\
**Tags:** roofit\
**Created:** [November 9, 2020, 6:18pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186 "2020-11-09T18:18:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bassam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@Bassam](https://root-forum.cern.ch/u/Bassam)\
**Post date:** [November 9, 2020, 6:18pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/1 "2020-11-09T18:18:31Z")

</div>

Hello,

I am trying to figure out how to use a skewed gaussian to fit my data. In the process of searching for how to implement this in root, I came across the following resource that seems relevant, but I am unsure about one thing.

Resource:  
[https://root.cern.ch/root/roottalk/roottalk04/att-2524/01-fnc.C](https://root.cern.ch/root/roottalk/roottalk04/att-2524/01-fnc.C)

My question:  
What does `(x<[1])` do in the following line?

```auto
TF1 *sgf = new TF1("sgf","[0]*exp(-0.5*pow((x-[1])/([2]+(x<[1])*[3]*(x-[1])),2))");

```

Does anyone have a better recommendation of how to implement a skewed gaussian?

Thank you very much for your help!

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [November 9, 2020, 9:11pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/2 "2020-11-09T21:11:53Z")

</div>

Perhaps @moneta can help.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [November 10, 2020, 8:40am UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/3 "2020-11-10T08:40:15Z")

</div>

Hi,

I don’t think what provided there is a good implementation. `(x<[1])` means that this term is equal to zero when false (x greater than Gaussian mean, parameter [1]) and has value = 1 when is true. Now in that implementation you multiply with a negative term which for some value of x \< [1] you will get negative sigma.

For the skewed normal I would use the implementation as suggested in [https://en.wikipedia.org/wiki/Skew\_normal\_distribution](https://en.wikipedia.org/wiki/Skew_normal_distribution)

```auto
TF1 * f = new TF1("f","2.*gaus(x,[0],[1],[2])*ROOT::Math::normal_cdf([3]*x,1,0)",-3,3);
f->SetParameters(1,0,1,4);
f->Draw(); 

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![Bassam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@Bassam](https://root-forum.cern.ch/u/Bassam)\
**Post date:** [November 10, 2020, 3:35pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/4 "2020-11-10T15:35:45Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![Bassam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@Bassam](https://root-forum.cern.ch/u/Bassam)\
**Post date:** [November 10, 2020, 3:35pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/5 "2020-11-10T15:35:57Z")

</div>

Thank you very much for the help!

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [January 12, 2023, 1:57pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/6 "2023-01-12T13:57:54Z")

</div>

Hi, I would like to fit the derivative of a histogram (positive peak) using the skewed Gaussian. Since the distribution is not normalized, I think I should account for the amplitude for better description of the distribution. But I dont understand How to do it. Attached is the root file with the histogram and its derivative.

[derivative.root](https://root-forum.cern.ch/uploads/short-url/5qXGFgUbyGhlO8xomLS5DfzynPp.root) (14.0 KB)

Thank you

---

<div class="post-metadata">

**Author:** ![garciaduarte1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/garciaduarte1/32/35005_2.png) [@garciaduarte1](https://root-forum.cern.ch/u/garciaduarte1)\
**Post date:** [July 5, 2023, 6:44pm UTC](https://root-forum.cern.ch/t/clarifying-a-user-defined-function-skewed-gaussian/42186/7 "2023-07-05T18:44:08Z")

</div>

I noticed this implementation doesn’t work for x different than zero. For some reason you cannot just change the mean (parameter [1]) to move the skewed gaussian along the x-axis. Instead, if you add another parameter for the mean it works beautifully. In the implementation below [0] is the amplitude, [1] is sigma, [2] is the skewness and [3] is the mean.

```auto
TF1 * f = new TF1("f","2.*gaus(x-[3],[0],0,[1])*ROOT::Math::normal_cdf([2]*(x-[3]),1,0)",-3,10);
f->SetParameters(1,1,4,5);
f->Draw();

```

Jeremias
