Using RooGaussian with mean/sigma defined as RooFormulaVars

Hi,

Can’t one pass a RooFormulaVar the same way as RooRealVar into a pdf as a parameter (e.g. as a sigma to RooGaussian)?
If I try to convolute a simple model (e.g. landau) with a gaussian resolution function which has mean and sigma declared as RooRealVars, everything works fine.
However, if I want to make the sigma of the gaussian a simple function of the observable (as is the case, for one example, in scintillator experiments), the convoluted pdf does not make sense and I get a bunch of problems:
a) if I use RooFFTConvPdf, I get “pdf normalization integral is zero” as a WARNINGs when trying to plot, and ERRORs when trying to generate toy data with the convoluted pdf.
b) if I use RooNumConvPdf, I get “pdf value is not-a-number” as a Warning during plotting, and Error during “generate” command (if I do this on linux with rootv5.24, rather than on cygwin with root5.26, I get Error during plotting, and nothing during generation)

if I declare both mean and sigma as RooFormulaVars, RooNumConvPdf does not complain neither during plotting, not during toy data generation, but the convoluted function does not seem to make sense.
RooFFTConvPdf keeps giving ERRORs and WARNINGS.
But, again, while the details of errors depend on the number of RooFormulaVars I am passing to RooGaussian and the platform (cygwin/linux, root v5.24/26), the convoluted function never makes sense (i.e if it is not null at all, there is neither smearing nor shift present).

I was able to find a poor-man solution by hacking the RooGaussian class. To do so, in constructor I pass pointers to RooFormulaVars for mean and sigma, instead of passing references to RooAbsReal. Consequently, I declare RooFormulaVar pointers for mean and sigma in protected part of the header, instead of RooRealProxies, and make appropriate changes in the .cxx file
If I do that, all my problems disappear. I can convolute my model with a gaussian that has variable mean/sigma and everything works and looks just fine.

But that means giving up the flexibility of universal interface that accepts RooRealVars, RooFormulaVars etc, which I thought is an awesome feature of RooFit.

Could someone please either point out my mistake that was causing the problems in the first place, or, if it is indeed a RooFit issue, suggest a better solution?

Thanks,
Igor

The macro looks like that (the modified RooGaussian class is attached):

RooRealVar e("e","e",0,15); //observable

//version 1. works all the time
//---------------------------------------------------------
RooRealVar mean("mean","mean",0);
RooRealVar sigma("sigma","sigma",0.75);
RooGaussian res("res","res",e,mean,sigma);

RooRealVar m("m","m",4);
RooRealVar s("s","s",0.75);
RooLandau model("model","model",e,m,s);

e.setBins(10000,"cache");
RooFFTConvPdf fconv("fconv","fconv",e,model,res);
fconv.generate(e,1000);
//-----------------------------------------------------------------

//version 2. works only with modified RooGaussian
//------------------------------------------------------------------
RooFormulaVar mean("mean","mean","-0.1*@0",RooArgList(e));
RooFormulaVar sigma("sigma","sigma","0.25*sqrt(@0)",RooArgList(e));
MyGaussian res("res","res",e,&mean,&sigma); //mean and sigma are declared as RooFormulaVars in MyGaussian

e.setBins(10000,"cache");
RooFFTConvPdf fconv("fconv","fconv",e,model,res);
RooNumConvPdf nconv("nconv","nconv",e,model,res);
nconv.setConvolutionWindow(mean,sigma,4);
nconv.generate(e,1000);
fconv.generate(e,1000);
//---------------------------------------------------------------------------

CUgaussianPdf.cxx (3.93 KB)
CUgaussianPdf.h (2.18 KB)

Hi,

Substituting arguments with functions of arguments is generally supported in RooFit.
You have to take care however that the argument values generated by such functions
are always sensible.

In your particular example, you construct your formula such that the width of your Gaussian is zero for e=0, which gives rise to the ‘pdf normalization error you observe’ as you have constructed a Gaussian of width zero here.

If you modify your function to include a small finite width for e=0, your fit will likely behave
OK.

Wouter

Of course! That obviously takes care of the warning messages. Thanks for pointing this out.

There is still that thing, though, that I can’t make sense of the convoluted function if the gaussian is provided with varied means/sigma.
It is probably again my silliness, but could you please take a look at the attached plots? One is generated with the following macro and the other one with the same macro only the gaussian is MyGaussian described before:

using namespace RooFit;

RooRealVar e("e","e",0,15); RooPlot* frame = e.frame();
RooRealVar s0("s0","s0",4); RooRealVar s1m("s1m","s1m",0.75);
RooLandau lan("lan","lan",e,s0,s1m);

////first make sure everything looks fine if there is no variation
RooFormulaVar bias ("bias","bias","-0.1-0.0*@0",RooArgList(e));
RooFormulaVar sigma("sigma","sigma","0.1+sqrt(@0)*0.0",RooArgList(e));
RooGaussian res("res","res func",e,bias,sigma);
RooNumConvPdf conv("conv","conv",e,lan,res);
conv.setConvolutionWindow(bias,sigma,5);

///Introduce variable shift/sigma
RooFormulaVar bias2 ("bias2","bias2","-0.1-0.1*@0",RooArgList(e));
RooFormulaVar sigma2("sigma2","sigma2","0.1+sqrt(@0)*0.2",RooArgList(e));
CUgaussianPdf res2("res2","res func",e,bias2,sigma2);
RooNumConvPdf conv2("conv2","conv2",e,lan,res2);
conv2.setConvolutionWindow(bias2,sigma2,5);

conv.plotOn(frame,LineColor(kViolet));
conv2.plotOn(frame,LineStyle(kDashed),LineColor(kRed));
frame->Draw();

I may be misunderstanding something, but should not addition of more bias and smearing look more like the picture with modified gaussian?

Thank you for your patience,
Igor
convpdf_plots.pdf (85.5 KB)

Hi.

I recently tried to use RooAbsReal derived classes for bias and sigma, instead of RooFormulaVars.
Yet the RooGaussian still behaves like it never updates the values of its bias/sigma.
Could it be that that chache is not getting updated for some reason?

Hi,

The variable->parameter substitution mechanism works generally fine, but I suspect there might be a specific problem here with RooNumConvPdf. I have filed a Savannah bug report #69249 for this issue and will get back to you.