Hi @jonas , thanks for answering.
The documentation I am referring to is section 7.7. of the ROOT guide, where the ROOT::Fit methods are described: link.
According to this entry in the forum, the PDF must be normalized to 1, whatever the value of the parameters, for the case of unbinned likelihood. But I believe this is not the case for extended unbinned likelihood, as the normalization of the PDF is to be changed and fitted to the data too.
I haven’t found any indication of this in the above documentation.
This is an example of what I am doing. The data sample is a very sparsely filled 2D histogram and the model is just a 2D gaussian with fixed mean and sigma, and amplitude S, on top of a flat background B. Both S and B are the free parameters of the fit.
void ext_unbinned_test()
{
gStyle->SetOptStat(0);
double datax[]={-3.5,-2.3,-2.3,-1.9,-0.7,-0.3,0.9,1.1,2.1,2.3,2.9,4.1,4.5,4.9,6.3};
double datay[]={-1.9,-3.7,0.1,0.1,-2.1,-9.3,1.7,0.1,-1.1,-9.1,2.7,0.5,-7.9,-1.7,-8.9};
int npoints = sizeof(datax)/sizeof(datax[0]);
// just plot data
TGraph *gr = new TGraph(npoints,datax,datay);
TH2F *dummy = new TH2F("dummy","low count 2D histogram",10,-10,10,10,-10,10);
TCanvas *c1 = new TCanvas("c1","low count 2D histogram",200,10,700,600);
dummy->Draw("col");
gr->SetMarkerStyle(20);
gr->SetMarkerColor(2);
gr->Draw("P");
gr->GetXaxis()->SetTitle("x (mm)");
gr->GetYaxis()->SetTitle("y (mm)");
gr->SetTitle("low count image");
gPad->Modified();
gr->GetXaxis()->SetRangeUser(-10,10);
gr->GetYaxis()->SetRangeUser(-10,10);
//unbinned fit
ROOT::Fit::DataOptions opt;
ROOT::Fit::DataRange range(-10,10,-10,10);
ROOT::Fit::UnBinData data(npoints, datax, datay, range);
cout <<"ncounts in datasample = " << npoints << endl;
TF2 *fitfun = new TF2("fitfun","([1]/400+[0]*0.0795776*TMath::Exp(-(x*x+y*y)/4))",-10,10,-10,10);
// fitfun is defined so that [1] and [0] are directly the total number of counts of B and S respectively
// that is the integral of fitfun in the 2D range [-10,10] is [0]+[1]
ROOT::Math::WrappedMultiTF1 fitFunction( *fitfun, 2 );
ROOT::Fit::Fitter fitter;
fitter.SetFunction( fitFunction, false);
double initialParams[] = {10,10};
fitter.Config().SetParamsSettings(2,initialParams);
fitter.Config().SetUpdateAfterFit();
fitfun->SetParameters(1,0);
fitter.LikelihoodFit(data, true);
TFitResult r=fitter.Result();
r.Print("V");
fitfun->SetParameters(r.Parameters().data());
fitfun->Draw("same");
}
As I said, I believe the script is correct and is giving meaningful results, but if you could confirm it would be great. Also, I have not found any example of an extended unbinned likelihood in the ROOT page, so maybe posting such an example is useful for more people.
Best,
Igor