Normalization of PDFs with RooFormulaVar

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 (33.1 KB)

Why is the normalization not working?
Thanks,
Emil

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

Cheers,
J.

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.

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. :slight_smile:

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

I saw that you are trying to build from source here Installing old root version - #10 by Emil_R. Good!