Optimal Unbinned Maximum Likelihood Fit- Python

I am using pyRoot to plot some histograms and fit some functions for parameter extraction.

My main question is: which method I should use for an unbinned maximum likelihood fit (from TTree); TTree.UnbinnedFit() or roofit. My assumption is that roofit is the better option; as I do intend to use more complex functions later on; but am not sure if there is any advantage in using the UnbinnedFit() method. I was also wondering if anyone had links to any example code/documentation of performing an unbinned maximum likelihood fit on tree data in python using roofit please? as I am struggling to find anything online

Below is my attempts at these unbinned fits using both TTree.UnbinnedFit() and roofit; both of which have thrown errors; UnbinnedFit() For a reason unknown to me and the roofit error is clearly improper use on my end; but am not sure how to use correctly

I am currently testing with a gaussian distribution, using the following fit:


t is my TTree object;“x” is the branch name and of course “gausn” the normalised gaussian function built in ROOT. When I run this I receive the following:

UnBinFit:0: RuntimeWarning: Abnormal termination of minimization.

         Invalid FitResult  (status = 4 )
Minimizer is Minuit / Migrad
MinFCN                    =     -39680.9
NDf                       =          997
Edm                       =      763.997
NCalls                    =         1360
Constant                  =  4.46208e+13   +/-   0.196126
Mean                      =  1.18295e-05   +/-   3.4608e-05
Sigma                     =  0.000101393   +/-   1.55626e-05

I believe this status means the fit did not converge. I have tried to adjust the tolerance and precision of minuit, which I am using; but to no avail.

I read online that roofit had been created to improve these fits. So I decided to attempt using this instead, though I was quite confused with the documentation. I used the following code:

x=ROOT.RooRealVar("x","x",t.GetMinimum("x"), t.GetMaximum("x")) 	
signal=ROOT.RooGaussian("signal","Signal Distribution", data,hist.GetMean(),hist.GetStdDev())
model=ROOT.RooAddPdf("model","signal dist", signal)

I was quite confused with what the last two parameters of the RooGaussian do; I have put the mean and standard deviation of my (binned) histogram; as I have assumed they are guesses of the mean and stdev of the gaussian distribution; to be changed by the fit, though I am fairly sure this is the wrong approach as I receive the following error:

 signal=ROOT.RooGaussian("signal","Signal Distribution", data,hist.GetMean(),hist.GetStdDev())
TypeError: none of the 3 overloaded methods succeeded. Full details:
  RooGaussian::RooGaussian(const char* name, const char* title, RooAbsReal& _x, RooAbsReal& _mean, RooAbsReal& _sigma) =>
    TypeError: could not convert argument 3
  RooGaussian::RooGaussian() =>
    TypeError: takes at most 0 arguments (5 given)
  RooGaussian::RooGaussian(const RooGaussian& other, const char* name = 0) =>
    TypeError: takes at most 2 arguments (5 given)

I am trying to create unbinned fits.

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24.02
Platform: Ubuntu
Compiler: Not Provided

I think @moneta can help.

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