I’m trying to fit some data points from a ROOT file using TMinuit, but I’m unable to do so.
Could anyone help me in figuring out whether this is an error in my code or not?
the data have entries at the beginning and end with zero error, but
in the calculation of chi-square you divide through it. So either skip
these points or use a log-likelihood.
in your gamma function, you divide through f1 and f3 without any zero
check.
Are your start value for alpha and beta any good ?
Your fitting function is very non-linear, why don’t you have parameter limits
defined.
In general you seem to attempt to put the data in a histogram but then
you do a fit on the raw data ?
Thanks a lot for your reply!.
I think it’s the zeros that caused the issue. My start values for alpha and beta were the expected outputs, hence I started off with them. I see that I should also put limits rather than bluntly defining them.
Thanks a lot once again.
Besides the numerical issues, I believe your function to be incorrect. Just for
fun I inserted your function and fixed the parameters on your start values.
Due to numerical issues, it crashes. So check your functional form
Hi Eddy,
So as you suggested, I put in a check for f1 and f3, but its always going to inf and 0 respectively.
But these are published results from an analysis. So these are definitely the values.
My take on it is that, the alpha value is really high which makes the gamma(alpha) to return a really high value as well, and on the other hand beta^alpha is a very small value, but their product would still be finite. But that’s not how the fitting is done, hence I have to find a way around this, because individually, f1 and f3 are diverging but their product will not.
Currently I’m trying to figure a way out to perform the fit such that f1 and f3 don’t diverge individually.
If you have any suggestions, do let me know and thank you once again for being so helpful!
#include "TMath.h"
#include "TF1.h"
Double_t MyGamma(Double_t *x, Double_t *par) {
Double_t a = par[0], b = par[1], c = par[2];
if ((a <= 0.) || (b <= 0.) || (x[0] <= 0.)) return 0.;
return c * TMath::Exp( ((a - 1.) * TMath::Log(x[0]) - x[0] / b) -
(TMath::LnGamma(a) + a * TMath::Log(b)) );
}
void MyGamma_test() {
TF1 *f = new TF1("f", MyGamma, 0., 1., 3);
f->SetParNames("alpha", "beta", "constant");
f->SetNpx(1000);
f->SetParameters(561.451, 0.00110568, 55.);
f->Draw();
}
Note: the "constant" parameter is actually the MyGamma function’s integral. For the hAvgPt histogram, it will be approximately equal to: hAvgPt->Integral("width")