Using RooFit Model to fit a histogram


I am having trouble fitting a histogram.

This is the code I am trying:

RooRealVar x(“x”,”x”,450,600) ;
RooRealVar mean(“mean”,”mean”,498,450,600) ;
RooRealVar sigma(“sigma”,”sigma”,4,450,600) ;
RooGaussian gauss(“gauss”,”signal p.d.f.”,x,mean,sigma) ;
RooRealVar c2(“c2”,”coefficient #2”, -.03,-1,-.001) ;
RooRealVar c1(“c1”,”coefficient #1”, 10.,0,100) ;
RooRealVar c0(“c0”,”coefficient #0”, 13500,0,16000);
RooPolyVar bkg(“bkg”,”background quadratic”, x, RooArgList(c0,c1,c2)) ;
RooRealVar fsig(“fsig”,”signal fraction”,0.5,0.,1.) ;
RooAddPdf model(“model”,”model”,RooArgList(gauss,bkg),fsig) ;
RooDataHist data(“data”,”dataset with K0 mass”,x,hkmass) ;
RooPlot* xframe = x.frame() ;
data.plotOn(xframe) ;
model.plotOn(xframe) ;

But this is what I get:

I am not sure what I am doing wrong.


Hi ,

It’s already mentioned in the tutorial of roofit. Try to follow the steps and correct your missing things.

If not done then please give running example code.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.