Hi @sanjeeda, thank you so much for providing the full code and data files to reproduce your problem!
You can read about the allowed parameter ranges in the RooGamma documentation and see how they are checked in the TMath source code.
So gamma and beta have to be positive. You should define the ranges for your a
and b
variables accordingly. Your data is distributed in a short interval of roughly 0.01, so I would pick a starting value for your scale parameter b = 1/0.01 = 100 that is already in the good ballpark.
Another problem that I spotted was that you defined a RooRealVar called #beta
twice in the code. So I renamed the one for the gamma distribution to beta_for_gamma
.
Finally the problem with your x0
. The RooGamma is only defined for x > x0. So you can either put a range for x0 that is below your smallest value of x (which is d0pi
in your case), or you can define another intermediate variable that you substitute for x0
but you define it such that the resulting pdf becomes not undefined for x < x0 but instead becomes zero. Maybe the latter option is better because it puts less constraints on the fit.
I have done all these three things in these lines here that you can substitute in your d0pi_fit.C
macro:
RooRealVar x0("x0","x0", 2.005, 0.0, 5.00);
RooRealVar a("a","a", 1.0, -1.0, 10.);
RooRealVar b("b","b", 100.0, 0.0, 1000.);
RooFormulaVar x0prime("#xprime", "x[0] < x[1] ? x[0] : x[1]", RooArgList(d0pi, x0));
RooFormulaVar gamma("#gamma", "a + 1", RooArgList(a));
RooFormulaVar beta_for_gamma("beta_for_gamma", "1./b", RooArgList(b));
RooGamma model("model", "Gamma pdf", d0pi, gamma, beta_for_gamma, x0prime);
To see if the RooGamma does the job, I made a fit with only the RooGamma model for the signal and it looks like it’s going in the right direction:
I hope this answers your question about defining your own function and then doing a fit with the correct parameter ranges!
By the way, have you considered using the RooJohnson pdf which was recently added to ROOT instead of your own class?