# RooFit: convolution of 2 Gaussians of mean 0 has MPV less than 0

**URL:** <https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436>\
**Category:** Newbie\
**Created:** [April 3, 2019, 6:19am UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436 "2019-04-03T06:19:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [April 3, 2019, 6:19am UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/1 "2019-04-03T06:19:08Z")

</div>

Hello everyone,

I’m new to RooFit. I’m trying to create a convolution of 2 Gaussian function of variable x by using RooFFTConvPdf. In principle, the convolution should return a Gaussian whose mean is the sum of the means of the initial Gaussians.

To make the case simple, I just set the means of the initial Gaussians to 0, so the expected mean should also be 0.

In my code, I also try to generate a histogram that obey the distribution of the convolution using TRandom to compare with the function it self. When I plot the histogram and the function together, the result shows the shape of the histogram and the function is almost identical, the only difference is the mean of the histogram is at 0, but the mean of the function is less than 0. I also found that the distance from the mean of the function to 0 is about 0.5% the range of x variable (for example, if I define x to be in the range of [-20, 20], then the mean of the convolution is -0.2)

I attach my code below, and also a plot that shows the difference between the function and the histogram.

I cannot figure out what is causing the problem, is it caused by an error in my code or is it a limitation of RooFit? Please give me your suggestions, thanks a lot.

Hoa.

[TestRooFit\_Model.h](https://root-forum.cern.ch/uploads/default/original/3X/5/b/5b303b1a0f478563035fec09e963f339ffcd1b78.h) (2.4 KB)

[xAna\_TestRoofit\_Gaussian.C](https://root-forum.cern.ch/uploads/default/original/3X/7/3/7325748fb5387b3179d1a34b661c51f421f47aed.C) (3.8 KB)

 ![Fit_Gaussian_20](https://root-forum.cern.ch/uploads/default/original/3X/5/3/53e74eb0bf48529352f175fa57734d8c999833de.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:** [April 3, 2019, 9:02am UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/2 "2019-04-03T09:02:48Z")

</div>

Hi,  
I cannot reproduce this problem with both master and root 6.16 version. Maybe you are using an older version of ROOT, which had a bug in the FFT convolution

Lorenzo

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [April 3, 2019, 9:52am UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/3 "2019-04-03T09:52:46Z")

</div>

Hi,

Thanks a lot for your reply. Since I’m working on lxplus to do my analysis, I use root provided by CMS Software.

The current version of root is 6.12/07, corresponding to CMSSW\_10\_5\_0 (It seem to be one of the latest version of CMS Software) and I can still encounter the problem (the mean is around -1.0 for x from -100 to 100)

So I think I will try to install the standalone version of root on lxplus and rerun the code. I will let you know when I have the new result.

Thanks again for your suggestion.

Hoa.

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [April 3, 2019, 4:58pm UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/4 "2019-04-03T16:58:30Z")

</div>

Hi Lorenzo,

I was able to use root 6.16, which is installed as default on lxplus. However I ran into the Segmentation violation error.

> Error in TVirtualFFT::FFT: plugin not found  
> Error in TVirtualFFT::FFT: plugin not found  
> Error in TVirtualFFT::FFT: plugin not found
> 
> \*\*\* Break \*\*\* segmentation violation

The error occurred when I extracted my RooAbsPdf into a TF1 object:

> TF1 \*function = model\_Gaus → asTF (RooArgList(var\_x));

and also when I plotted it:

> model\_Gaus → plotOn (frame);

The version of ROOT is 6.16/00. How can I fix it?

Hoa.

---

<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 4, 2019, 8:37am UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/5 "2019-04-04T08:37:44Z")

</div>

HI,  
This means that version of ROOT is not installed with FFTW support.  
How did you setup up ROOT ? Did you use the cvmfs installation, for example from  
`/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.16.00/x86_64-centos7-gcc48-opt`

Lorenzo

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [April 4, 2019, 10:06am UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/6 "2019-04-04T10:06:20Z")

</div>

Hi,

I didn’t do any setup, the version 6.16 of ROOT I used is the default installation on lxplus. I mean I just simply login to lxplus and run my code without doing any setup.

As you recommended, I try to set up with:  
source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.16.00/x86\_64-centos7-gcc48-opt/bin/thisroot.sh

The problem with segmentation error is gone. However, the mean of the convoluted pdf is still less than 0. For x in the range of -100 to 100, 6.12 returns the mean at -0.9999999993…, 6.16 returns the mean at -0.107527.

Is the result of 6.16 expected?

Hoa

---

<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 4, 2019, 12:46pm UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/7 "2019-04-04T12:46:06Z")

</div>

Hi,

The FFT convolution is discrete and works by binning the function in the range. When doing it is recommended to increase the number of bins in the variable. I think the default number of bins in 6.12 was too small and this has causd the effect that you observe.  
For the latest version is larger but probably not sufficient for you.  
One should add then this line in the code after creating the convoluted ODF,

`x->setBins(10000,"cache")`

where x is your observable object (called `var+x` in your example)

Lorenzo

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [April 4, 2019, 1:30pm UTC](https://root-forum.cern.ch/t/roofit-convolution-of-2-gaussians-of-mean-0-has-mpv-less-than-0/33436/8 "2019-04-04T13:30:58Z")

</div>

Hi,

Increasing the number of bins works well! Thank you very much!

Hoa.
