RooFit - Fitting 2D histograms


I am trying to fit a 2D combination of RooHistPdf’s to a 2D RooDataHist obtained from a TH2. The Pdf’s are formed from MC TH2 histograms using the RooDataHist class. There are two background shapes bg1 and bg2 and one signal shape sig. The shapes are scewed with either a linear or exponential PDF and then combined to one extended PDF which is then fit to data. The fit contains 8 variables. When I try to fit it RooFit runs infinitely. The below snippet describes how I generate the fit model:

// Define Dimension Variables
RooRealVar x(“x”,“x”,1.5,2.5);
RooRealVar y(“y”,“y”,-10.0,2.0);

// Define Scew Variable
RooRealVar b1(“b1”,“b1”,-3,3);
RooRealVar b2(“b2”,“b2”,-3,3);
RooRealVar c0(“c0”,“c0”,-500,500);
RooRealVar c1(“c1”,“c1”,-500,500);
RooRealVar c2(“c2”,“c2”,-500,500);
RooRealVar xoffset(“xoffset”,“xoffset”,1.85);

// Define Weight Functions
RooAbsPdf* weightSig = new RooLinearScew(“weightSig”, “weightSig”, x, b1, xoffset);
RooAbsPdf* weightBg1 = new RooLinearScew(“weightBg1”, “weightBg1”, x, b2, xoffset);
RooAbsPdf* weightBg2 = new RooExponentialScew(“weightBg2”, “weightBg2”, x, c0, c1, c2, xoffset);

// Import Histograms
RooDataHist* rhData = new RooDataHist(“rhData”,“rhData”,RooArgSet(x,y),TH2data);
RooDataHist* rhSig = new RooDataHist(“rhSig”,“rhSig”,RooArgSet(x,y),TH2Sig);
RooDataHist* rhBg1 = new RooDataHist(“rhBg1”,“rhBg2”,RooArgSet(x,y),TH2Bg1);
RooDataHist* rhBg2 = new RooDataHist(“rhBg2”,“rhBg2”,RooArgSet(x,y),TH2Bg2);

// Define PDFs from Signal and Background shapes
RooHistPdf* rpSig = new RooHistPdf(“rpSig”,“rpSig”, RooArgSet(x,y),rhSig,2);
rpBg1 = new RooHistPdf(“rpBg1”,“rpBg1”, RooArgSet(x,y),rhBg1,2);
rpBg2 = new RooHistPdf(“rpBg2”,“rpBg2”, RooArgSet(x,y),*rhBg2,2);

// Multiply each HistPdf with its weight PDF
RooAbsPdf* rpSigWeight = new RooProdPdf(“rpSigWeight”, “rpSigWeight”, RooArgSet(*weightSig, rpSig));
rpBg1Weight = new RooProdPdf(“rpBg1Weight”, “rpBg1Weight”, RooArgSet(*weightBg1, rpBg1));
rpBg2Weight = new RooProdPdf(“rpBg2Weight”, “rpBg2Weight”, RooArgSet(*weightBg2, *rpBg2));

// Set Signal yields
RooRealVar nSig(“nSig”,“nSig”,550000);
RooRealVar nBg1(“nBg1”,“nBg1”,50000);
RooRealVar nCombBg(“nBg2”,“nBg2”,110000);

// Add all PDFs to form fit model
RooAbsPdf* fitModel = new RooAddPdf(“fitModel”, “fitModel”, RooArgSet(*rpSigWeight, *rpBg1Weight, *rpBg2Weight), RooArgSet(nSig, nBg1, nBg2));

// Fit the fit model to data
fitModel->fitTo(*rhData, Extended(kTRUE));

I generated the Scew PDFs using RooClassFactory::makePdf and they are simple shape functions which only depend on x and not on y:

// Linear PDF
return 1 + slope*(x - xoffset);

// Exponential
return 1 - exp(c0 + c1(x - xoffset) + c2*(x - xoffset) * (x-xoffset))

If I seperate the fit model into only one HistPDF and one ScewPDF it sometimes works, but the full fit always freezes. Am I maybe overloading the fit with too many loose parameters? Could someone let me know what I am doing wrong or if there is a better way of doing this? I am running Root 5.20. Thank you for your help.



Hi Peter,

I see no immediately obvious problems. However If you send me a file
with your input histograms I will try to run myself and find out what’s


Hi Wouter,

Thank you for your reply. I made a tar ball of the files. May I e-mail them to your slac e-mail since I would rather not post them publicly? Thank you for your help.



Hi Peter,

That’s fine.