# Conditional PDFs in RooFit

Hi,
I am completely stuck with trying to use conditional PDFs in RooFit, despite the manuals’ extensive and assuring explanations. If anyone who has experience with this sees my problem, please let me know!

I have a text book example (I think) of when one can use conditional pdfs: a dataset with a set of vertex position measurements x, and a variance V(x) for each x. So, I want to fit a certain function to the distribution of x values, and I want to weigh each event with the information from V(x).

I describe the “physics” part and the “error” part with two separate PDFs, and then build a composite model using RooProdPDf("","",errorpdf, Conditional(targetpdf,x)).

My problem is that it does not seem to matter AT ALL if I include the error PDF at all, or if I treat V(x) (actually sqrt(V(x)) as a conditional PDF or not. The fit returns the same results in any case. Clearly something is wrong.

I have tried to use a RooHistPdf filled with the observed values of sqrt(V(X)) instead of a RooGenericPDF when I build my composite PDF, but it seems to make no difference.

Does anyone with experience of this know what’s wrong? I’ve included the important parts of the code here. Unfortunately it’s not executable since I can’t attach the real dataset, but maybe you can see some obvious mistake in my code?

cheers
Aras

``````
//observables. vertex position and variance. Fetched from a dataset.
RooRealVar vertex_x("vertex_x","vertex_x",lowlimit_x,highlimit_x);
RooRealVar cov_x("cov_xx","Cov_x",0,2);

//fit paramaters:
RooRealVar Left_x("Left_x","X Left",leftguess_x,leftguess_x-1,leftguess_x+1);
RooRealVar sigmaLeft_x("sigmaLeft_x","X sigmaLeft",0.2,0.05,1);
RooRealVar Right_x("Right_x","X Right",rightguess_x,rightguess_x-1,rightguess_x+1);
RooRealVar sigmaRight_x("sigmaRight_x","X sigmaRight",0.2,0.05,1);

//The physics PDF:
RooGenericPdf targetpdf_x("targetpdf_x",
targetformula,
RooArgSet(vertex_x,Left_x,sigmaLeft_x,Right_x,sigmaRight_x));

//The "error part" of the PDF = sigma_x = sqrt of variance of x from vertex fit:
RooGenericPdf errorpdf_x("errorpdf_x","sqrt(@0)",RooArgSet(cov_x));

//Make composite model
RooProdPdf model_x("fullpdf_x","fullpdf",errorpdf_x,Conditional(targetpdf_x,vertex_x));

//Fit to dataset "xslice":
RooFitResult *fitresultx=model_x.fitTo(*xslice,Save(true),Minos(false),Hesse(true));``````

Hi Wouter, or whoever else knows about these things,
I might be seeing some hints about what is going wrong.

To recap, the main problem is that I can’t seem to build a conditional PDF with the physics PDF * error pdf. The fit returns the same no matter if I include the error pdf or not, suggesting that the information isn’t used at all inte the fit.

I just noticed an error message that I did not see before. Before the fit is completed I get this (the variable/pdf names have changed from x to y compared to my last example):

``````RooRealVar::setRange(cov_yy) new range named 'fit' created with bounds [-1.5,2]
RooRealVar::setRange(vertex_y) new range named 'fit' created with bounds [-1.5,2]
RooMinuit::optimizeConst: activating const optimization
RooRealVar::setRange(cov_yy) new range named 'NormalizationRange' created with bounds [0,2]
RooRealVar::setRange(vertex_y) new range named 'NormalizationRange' created with bounds [-2,2]
RooRealMPFE::initialize(nll_MPFE0) server process terminating
RooAbsGoodnessOfFit::initMPMode: starting remote GOF server process #0
RooRealMPFE::initialize(nll_MPFE0) successfully forked server process 23803
RooAbsOptGoodnessOfFit::constOptimize(nll_GOF1) Action=Activate
RooAbsReal::optimize: component errorpdf_y will be cached
RooAbsReal::optimizeConst: The following unused tree branches are deactivated: (cov_yy)``````

The last line is the interesting one. Apparently, the branch used in the error pdf is considered “unused”. I have double-checked the cov_yy distribution and it looks OK, but for some reason RooFit ignores it.

Does this give any useful hints to what’s going on?

cheers,
Aras

1 Like