RooKeysPdf in ROOT 5.32 broken


I have severe problems using RooKeysPdf in ROOT 5.32. Using these in fits on data or in toy generation is not working. Generating with keys PDFs is generally not a problem. Fitting with these results in funny parameter sets not describing the data at all. Sometimes the yield of the keys PDF (in an unbinned EML fit) gets pulled to zero, sometimes other parameters are becoming weird.

Here is an example (see code below):

In a first part I generate a gaussian sample to generate a keys PDF from this. This keys PDF is saved into a RooWorkspace which itself is written to a file. I close the ROOT session and open a new one. Then I generate a new sample with two gaussians and one flat exponential (one gaussian resembles the former generated keys PDF). I load the keys PDF from the RooWorkspace and combine this with the other gaussian and the exponential. Finally, I fit with this new PDF to the generated data. One would assume this should be simple. The result however is not good (in ROOT 5.32). In ROOT 5.30 it works fine.

This is the sample that was generated:

This is the fitted pdf plotted:

The code to reproduce:

First ROOT session:

RooRealVar m("m","m",5100,5600);
RooRealVar mean("mean","mean",5200,5100,5300);
RooRealVar sigma("sigma","sigma",10,0,20);
RooGaussian pdf_gen("pdf_gen", "pdf_gen", m, mean, sigma);
RooDataSet* data = pdf_gen.generate(RooArgSet(m),12000);

RooKeysPdf pdf_keys("pdf_keys", "pdf_keys", m, *data);

RooWorkspace * workspace = new RooWorkspace("workspace","workspace");

TFile f("keys.root", "recreate");

Second ROOT session:

using namespace ROOT;
using namespace RooFit;

RooRealVar m("m","m",5100,5600);
RooRealVar mean1("mean1","mean1",5200,5100,5300);
RooRealVar sigma1("sigma1","sigma1",10,0,20);
RooGaussian pdf_gen1("pdf_gen1", "pdf_gen1", m, mean1, sigma1);

RooRealVar yield1("yield1","yield1",1200,0,10000);
RooExtendPdf pdf_ext1("pdf_ext1","pdf_ext1",pdf_gen1,yield1);

RooRealVar exp("exp","exp",0.0001,-1,1);
RooExponential pdf_gen2("pdf_gen2", "pdf_gen2", m, exp);

RooRealVar yield2("yield2","yield2",5000,0,10000);
RooExtendPdf pdf_ext2("pdf_ext2","pdf_ext2",pdf_gen2,yield2);

RooRealVar mean3("mean3","mean3",5500,5400,5600);
RooRealVar sigma3("sigma3","sigma3",10,0,20);
RooGaussian pdf_gen3("pdf_gen3", "pdf_gen3", m, mean3, sigma3);

RooRealVar yield3("yield3","yield3",1200,0,10000);
RooExtendPdf pdf_ext3("pdf_ext3","pdf_ext3",pdf_gen3,yield3);

RooAddPdf pdf_add("pdf_add","pdf_add", RooArgList(pdf_ext1, pdf_ext2, pdf_ext3));

RooDataSet* data = pdf_add.generate(RooArgSet(m), Extended());

TCanvas c1("c1","c1",800,600);
RooPlot* frame = m.frame();


TFile f("keys.root", "read");
RooWorkspace* workspace = (RooWorkspace*)f.Get("workspace");
RooKeysPdf* pdf_keys = (RooKeysPdf*)workspace->pdf("pdf_keys");

RooRealVar yield_keys("yield_keys","yield_keys",1200,0,10000);
RooExtendPdf pdf_extkeys("pdf_extkeys","pdf_extkeys",* pdf_keys, yield_keys);

RooAddPdf pdf_fit("pdf_fit","pdf_fit", RooArgList(pdf_extkeys, pdf_ext2, pdf_ext3));

RooFitResult* fitResult = pdf_fit->fitTo(*data,Extended(true),

RooPlot* frame = m.frame();


Hi Florian,

I’ve fixed the problem. I’ll commit the fix to the SVN trunk and 532 patches branch today.
(I’ve also close the corresponding Savannah bug report)