# Relativistic Breit Wigner and Relativistic Voigt

**URL:** <https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [February 17, 2022, 8:37pm UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844 "2022-02-17T20:37:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackLindon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@JackLindon](https://root-forum.cern.ch/u/JackLindon)\
**Post date:** [February 17, 2022, 8:37pm UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/1 "2022-02-17T20:37:47Z")

</div>

Non-relativistic Breit-Wigner and non-relativistic Voigts are implemented as functions in ROOT, though their relativistic versions are not. Would it be possible to implement the relativistic versions? Users implementing their own relativistic Breit-Wigner is quite straight forward (though it would still be useful to have this fairly common function available without having to be implemented by the user), however a relativistic voigt is fairly difficult to implement correctly and would be very helpful to have as an in-built function.

---

<div class="post-metadata">

**Author:** ![JackLindon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@JackLindon](https://root-forum.cern.ch/u/JackLindon)\
**Post date:** [February 18, 2022, 4:39am UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/2 "2022-02-18T04:39:35Z")

</div>

I’ve submitted a pull request for adding the relativistic breit-wigner here [https://github.com/root-project/root/pull/9926/commits](https://github.com/root-project/root/pull/9926/commits)

For the relativistic breit wigner it’s pretty straight forward since it’s just an analytical function so think the way I’ve implemented it is about as good as it can be.

For the relativistic voigt however it’s a bit more complicated since it’s non analytic.

I’ve produced an implementation below but not submitted a pull request for this. I’m wondering if anyone has any comments and such or thinks this is ok to add? (in particular I’m not sure if the integrator I use is the best for this, or if boost is ok to use in ROOT).

```auto
Double_t VoigtRelativistic(Double_t x, Double_t median, Double_t sigma, Double_t lg, Double_t integrationRange=26.615717509251260){ //t=26.615717509251260 gives exp(-t^2)=minimum value stored by double.  

  Double_t inverse_sSqrt2 = 1/(1.41421356237309504*sigma); //1.41421356237309504=sqrt(2)                                                                                                                    
  Double_t ss = sigma*sigma;
  Double_t mm = median*median;

  Double_t u1 = (x - median) * inverse_sSqrt2;
  Double_t u2 = (x + median) * inverse_sSqrt2;
  Double_t a = (lg*median) / (2*ss);

  Double_t y = sqrt(mm * (mm+lg*lg));
  Double_t k = (0.25397454373696387*a*y)/(ss*sqrt(mm+y)); //0.25397454373696387=sqrt(2)/(pi^(3/2))                                                                                                          

  auto f = [&](double t) {
    Double_t u1Minust = (u1-t);
    Double_t u2Minust = (u2-t);
    return ( (exp(-t*t)) / (u1Minust*u1Minust * u2Minust*u2Minust + (a*a)) );
  };

  boost::math::quadrature::tanh_sinh<double> integrator;
  Double_t voigt = k* (integrator.integrate(f,-integrationRange,integrationRange));

  return voigt;
}

```

Below is an image comparing the results of this to the current (non relativistic) voigt implemented in ROOT.

 ![relativisticVoigtComparison](https://root-forum.cern.ch/uploads/default/original/3X/e/a/eae8077dd3b74bfee3676a210c1d65a2207ef481.png)

---

<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:** [February 18, 2022, 9:29am UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/3 "2022-02-18T09:29:41Z")

</div>

Hi,  
Thank you for the contribution. For the Relativistic Voigt, one could use the Integrator class of Mathcore, see [ROOT: ROOT::Math::IntegratorOneDim Class Reference](https://root.cern.ch/doc/master/classROOT_1_1Math_1_1IntegratorOneDim.html) or the GSL Integrator ([ROOT: ROOT::Math::GSLIntegrator Class Reference](https://root.cern.ch/doc/master/classROOT_1_1Math_1_1GSLIntegrator.html))

In this case, since we will have this dependency, it is maybe better to have it as a separate class, which could be included in the MathMore library.

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![JackLindon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@JackLindon](https://root-forum.cern.ch/u/JackLindon)\
**Post date:** [February 19, 2022, 7:19am UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/4 "2022-02-19T07:19:43Z")

</div>

Hi @moneta ,

Thank you for the suggestions. I have changed to the IntegratorOneDim class. This requires the dependencies

> #include “Math/Integrator.h”  
> #include “Math/Functor.h”

This works correctly, though there are a lot of options for IntegrationOneDim and I am not sure which if any is the best to use. I have just left it with the default options, though are there any suggestions other than the default (or should I include function arguments for the user to set these options themselves)?

By

> it is maybe better to have it as a separate class, which could be included in the MathMore library.

You mean add it is as it’s own .h and .cxx file in MathMore yes? I think it would make more sense in TMath since the non-relativistic Voigt is defined here, but I suppose this is not possible because of the additional dependencies on Math/Integrator.h and Math/Functor.h?

Thanks again for your help

```auto
Double_t VoigtRelativistic(Double_t x, Double_t median, Double_t sigma, Double_t lg, Double_t integrationRange=26.615717509251260){ //t=26.615717509251260 gives exp(-t^2)=minimum value stored by double.                                                             
                                                                                                                                                                                                                                                                       
  Double_t inverse_sSqrt2 = 1/(1.41421356237309504*sigma); //1.41421356237309504=sqrt(2)                                                                                                                                                                               
  Double_t ss = sigma*sigma;                                                                                                                                                                                                                                           
  Double_t mm = median*median;                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                       
  Double_t u1 = (x - median) * inverse_sSqrt2;                                                                                                                                                                                                                         
  Double_t u2 = (x + median) * inverse_sSqrt2;                                                                                                                                                                                                                         
  Double_t a = (lg*median) / (2*ss);                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                       
  Double_t y = sqrt(mm * (mm+lg*lg));                                                                                                                                                                                                                                  
  Double_t k = (0.25397454373696387*a*y)/(ss*sqrt(mm+y)); //0.25397454373696387=sqrt(2)/(pi^(3/2))                                                                                                                                                                     
                                                                                                                                                                                                                                                                       
  auto integrand = [&](Double_t t) {                                                                                                                                                                                                                                   
    Double_t u1Minust = (u1-t);                                                                                                                                                                                                                                        
    Double_t u2Minust = (u2-t);                                                                                                                                                                                                                                        
    return ( (exp(-t*t)) / (u1Minust*u1Minust * u2Minust*u2Minust + (a*a)) );                                                                                                                                                                                          
  };                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                       
  ROOT::Math::Functor1D f(integrand);                                                                                                                                                                                                                                  
  ROOT::Math::Integrator integrator(ROOT::Math::IntegrationOneDim::kDEFAULT);                                                                                                                                                                                          
  integrator.SetFunction(f);                                                                                                                                                                                                                                           
  Double_t voigt = k * integrator.Integral(-integrationRange,integrationRange);                                                                                                                                                                                        
                                                                                                                                                                                                                                                                       
  return voigt;                                                                                                                                                                                                                                                        
}                                                                                                                                                                                                                                                                      

```

---

<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:** [February 21, 2022, 10:23am UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/5 "2022-02-21T10:23:33Z")

</div>

Hi,

I would suggest having a separate class, because normally using an integrator requires to allocate some space for the computation. This can be CPU expensive, and in case of repeated evaluation of the function it is better to re-use the integrator class.  
For this reason it is better that the Breit-Wigner is a class and for this reason it is better to not include in TMath, but in MathMore with its own .h and .cxx files

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![JackLindon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@JackLindon](https://root-forum.cern.ch/u/JackLindon)\
**Post date:** [February 21, 2022, 5:06pm UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/6 "2022-02-21T17:06:03Z")

</div>

Hi @moneta

Thanks, makes sense. I’ll add it as it’s own class in MathMore. Along with this would it be ok to edit the comment in the currently existing Voigt class [TMath - source file](https://root.cern.ch/root/html524/src/TMath.cxx.html#901) to mention that there is a relativistic version in MathMore?

Cheers,  
Jack

---

<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:** [February 21, 2022, 6:28pm UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/7 "2022-02-21T18:28:45Z")

</div>

Yes, it will be good to mention this in the Math documentation

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![JackLindon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@JackLindon](https://root-forum.cern.ch/u/JackLindon)\
**Post date:** [April 13, 2022, 5:02pm UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/8 "2022-04-13T17:02:16Z")

</div>

Hi @moneta ,

Apologies I’m just checking if the updates I made to my pull request have been lost in the system [Add Relativistic Breit Wigner to TMath by JackHLindon · Pull Request #9926 · root-project/root · GitHub](https://github.com/root-project/root/pull/9926)

Thanks again for your help,  
Jack

---

<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:** [April 13, 2022, 5:28pm UTC](https://root-forum.cern.ch/t/relativistic-breit-wigner-and-relativistic-voigt/48844/9 "2022-04-13T17:28:21Z")

</div>

See the review comments in the PR. Apologies for the delay
