# Voigt function with parameter which depends on energy

**URL:** <https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139>\
**Category:** Newbie\
**Created:** [April 28, 2020, 12:10pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139 "2020-04-28T12:10:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![babintsev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/4af34b/32.png) [@babintsev](https://root-forum.cern.ch/u/babintsev)\
**Post date:** [April 28, 2020, 12:10pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139/1 "2020-04-28T12:10:36Z")

</div>

\_\_\_Hello  
I cannot use gauss function when width parameter depends on energy -  
compilation error. I can overcame it using my own function. -  
see attachment.  
How to solve this problem with voigt function ?

thank you,  
Vladimir[Forum-Voigt.C](https://root-forum.cern.ch/uploads/short-url/yEbXq6XyjCsPsYSjBlvwIB1LU0a.C) (5.1 KB)

---

<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 28, 2020, 12:41pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139/2 "2020-04-28T12:41:30Z")

</div>

[Voigt profile](https://en.wikipedia.org/wiki/Voigt_profile) -\> [TMath::Voigt](https://root.cern.ch/doc/master/namespaceTMath.html#a6688575b20a534a694f0b0ba89087daa)

```cpp
{
  TF1 *f = new TF1("f", "TMath::Voigt(x - [0], [1], [2], 4)", -10., 10.);
  f->SetParameters(3., 2., 1.); // median, sigma, lg
  f->Draw();
}

```

---

<div class="post-metadata">

**Author:** ![babintsev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/4af34b/32.png) [@babintsev](https://root-forum.cern.ch/u/babintsev)\
**Post date:** [April 28, 2020, 12:44pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139/3 "2020-04-28T12:44:03Z")

</div>

hi, parameter depends on x ! this scripts does not work here …

---

<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 28, 2020, 12:45pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139/4 "2020-04-28T12:45:18Z")

</div>

You can define it as you want (I’ve just written a very basic form).

---

<div class="post-metadata">

**Author:** ![babintsev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/4af34b/32.png) [@babintsev](https://root-forum.cern.ch/u/babintsev)\
**Post date:** [April 28, 2020, 12:56pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139/5 "2020-04-28T12:56:39Z")

</div>

ok, could you please give me short example, where  
parameter sigma = 1. + 1./sqrt(x)

Vladimir

---

<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 28, 2020, 1:03pm UTC](https://root-forum.cern.ch/t/voigt-function-with-parameter-which-depends-on-energy/39139/6 "2020-04-28T13:03:52Z")

</div>

```cpp
{
  TF1 *f = new TF1("f", "TMath::Voigt(x - [0], 1. + 1. / TMath::Sqrt(x), [1], 4)", 1.e-6, 10.);
  // f->SetNpx(10000);
  f->SetParameters(3., 2.); // median, lg
  f->Draw();
}

```
