# Normalization of PDFs with RooFormulaVar

**URL:** <https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485>\
**Category:** Roofit and RooStats\
**Created:** [November 23, 2022, 12:09pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485 "2022-11-23T12:09:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [November 23, 2022, 12:09pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/1 "2022-11-23T12:09:23Z")

</div>

Hi,  
I trying to understand how to shift RooHistPdf’s to get better fits (as you can see in my latest posts). But I think I have now reduced the problem to a quiet simple question. In order to visualize this, I have written the following code:

> RooRealVar x(“x”,“x”,800,1800);  
> RooPlot \*frame = x.frame();
> 
> ```
> RooRealVar mean("mean","mean",1200,1000,1400);
> RooRealVar sigma("sigma","sigma",80,50,90);
> RooGaussian Gauss("Gauss","Gauss",x,mean,sigma);
> 
> RooDataSet * Data = Gauss.generate(x,1000000);
> 
> Data->plotOn(frame);
> 
> RooRealVar mean2("mean","mean",1210,1200,1220);
> RooRealVar sigma2("sigma","sigma",80,50,90);
> RooGaussian Gauss2("Gauss","Gauss",x,mean2,sigma2);
> 
> RooDataSet * Model = Gauss2.generate(x,1000000);
> 
> Model->plotOn(frame, LineColor(kGreen), MarkerColor(kGreen));
> 
> RooRealVar Shift("Shift","Shift",10,0,20);
> RooFormulaVar xShifted("xShifted","x + Shift",RooArgSet(x,Shift));
> 
> RooDataHist Sim("Sim","Sim",x,*Model);
> 
> RooHistPdf Func("Func","func",xShifted,x,Sim);
> 
> Func.plotOn(frame, LineColor(kRed));
> Func.fitTo(*Data, Range(1000,1400));
> Func.plotOn(frame);
> Func.paramOn(frame);
> frame->Draw();
> 
> ```

This code should produce to identical, but shifted gaussian curves and use one to generate data while using the second one to create a line shape. Then I add a RooFormulaVar to move this line shape. So in theory with a shift of 10, the shapes should be identical. The result does not agree with this in the sense that I do get identical line shapes but the normalization does not manage to make them look like this (sorry, don’t know how to better express this). I get this result:  
[unnamed.pdf](https://root-forum.cern.ch/uploads/short-url/e1YcmOG0pSIxpmloUAcwRVaVpZD.pdf) (33.1 KB)

Why is the normalization not working?  
Thanks,  
Emil

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [November 23, 2022, 2:11pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/2 "2022-11-23T14:11:57Z")

</div>

Hi @Emil_R; for this we will need @moneta or @jonas; let’s ping them.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [November 23, 2022, 2:21pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/3 "2022-11-23T14:21:13Z")

</div>

I have found that this seems to be a problem with root 6.26/06 on my Mac. With root 6.24/06 on Linux the problem does not occur and fitting is not a problem. I let the exact same code run and the results are very different. As I am not sure how to install root 6.28 myself (home-brew does not have the new version yet), I cannot test whether the problem is already fixed in the newest root version, but at least in root 6.26/06 there seems to be a problem with RooFormulaVar, mainly that the integration seems to evaluate to 0 or NaN.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [November 23, 2022, 2:25pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/4 "2022-11-23T14:25:31Z")

</div>

> [@Emil\_R](#):
>
> As I am not sure how to install root 6.28 myself (home-brew does not have the new version yet), I cannot test whether the problem is already fixed in the newest root version

ROOT 6.28 has not been released yet, with tentative release date somewhere in January. In that case, to get an updated ROOT, you would need to build the `master` branch from source.

This is not recommended if you are not an experienced user. Let’s then first give some time to the RooFit experts to reply to your question. 🙂

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [November 28, 2022, 7:20pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/5 "2022-11-28T19:20:34Z")

</div>

As the solution was to use root 6.24, I wanted to do this. However, I do not find a way to install root 6.24 on my Mac (MacOS 12.2.1). Does anyone know how to install an old version of root?  
Thanks,  
Emil

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [November 29, 2022, 12:27pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/6 "2022-11-29T12:27:11Z")

</div>

I saw that you are trying to build from source here [Installing old root version - #10 by Emil\_R](https://root-forum.cern.ch/t/installing-old-root-version/52511/10). Good!

---

<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:** [December 13, 2022, 12:28pm UTC](https://root-forum.cern.ch/t/normalization-of-pdfs-with-rooformulavar/52485/7 "2022-12-13T12:28:10Z")

</div>

Closed on December 13, 2022, 12:28pm UTC

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