Extended unbinned likelihood fit using ROOT::Fit

Hello,

I am trying to do an extended unbinned likelihood fit using the ROOT::Fit methods (no RooFit). I would expect that, apart from the parameters of my PDF, the total expected counts N of my data sample is also a free parameter, that could be retrieved after the fit is done via, e.g. FitResults. But I don’t find in the documentation how can I access this value. The standard fit result output only lists the bestfit results for the PDF parameters. Can someone help me or point me to an example on how this must be done?

Thank you very much for your help,
Igor

Hello again,

Sorry for my question, I read it now and I understand now it is not well expressed. Of course the normalisation of the PDF is not itself (necessarily) a new free parameter in an extended likelihood fit, but it just may depend on other free parameters of the PDF. I was just confused with the requirement that the PDF must be normalised to 1 for unbinned likelihood fits. I understand this is not a requirement anymore for extended likelihoods, do I understand right? I think so because that is how I do the fit now and it works fine, giving meaningful results. Sorry for the noise!

(in any case the documentation could be more explicit on when the requirement of normalization is needed -for the normal case but not for the extended-, and an example of an extended likelihood fit would be very useful to the user - right now there is none)

Best,
Igor

Hi @igarciai; perhaps @moneta can confirm and also consider clarifying the documentation.

Cheers,
J.

Hi @igarciai, thanks for asking on the forum and sorry for the late reply!

Which documentation are you referring to exactly, can you post a link maybe? And concerning the correctness of your fit, would it be possible for you to upload your code so I can reason about it? That would make it much simpler for me to come up with answers to your questions.

Thanks!
Jonas

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

Hi,

the extended likelihood method assume that the number of observations is itself a Poisson random variable [1]. You may need to crosscheck if your data fulfills the assumptions of the method.

Cheers,
atd
[1] G.Cowan, Statistical Data Analysis, Oxford Science Publications (1998), section 6.9 Extended maximum likelihood.

well, they do. I generated them randomly from the same model I am using to fit them.

Hi,
In the case of an unbinned extended maximum likelihood fit, you still need to compute the normalization of your function, otherwise you will not be able to interpret the obtained result correctly.
The function normalization will not be needed if you are performed a binned extended likelihood fit.

Best regards

Lorenzo

1 Like

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