Conditions on parameters in TF1 fit

So I would like to fit a normalized histogram corresponding to a superposition of two probability distributions, let’s call them f_1 and f_2. As a TF1 object, let’s write this as

TF1 probFit("probFit", "[0] * f_1([1] + [2] * x) + [3] * f_2([3] + [4] * x)")

When using TH1::Fit, is there a way to impose the conditions

[0] >= 0,
[3] >= 0,
[0] + [3] = 1

?
If there is, should this conditions be imposed when declaring probFit, or when using TH1::Fit?

Also, is there a notation short cut to write [1] + [2] * x and [3] + [4] * x in terms of pol 1? Perhaps something like pol(1) 1 and pol(3) 1, respectively?

Hi,

First of all when doing a standard TH1::Fit it is assumed the normalization is not fixed but also floating. The distribution in each bin is assumed to be Poisson when doing a likelihood fit (“option L”)

For doing a multinomial fit (i.e. fixed normalization) you can use the fit option MULTI.

For applying the conditions you the redefine the parameter [3] as 1. - [0] and then you set for the parameter [0] a constraints to be 0 <= [0] <= 1, by doing
probFit->SetParLimits(0,0., 1.)

You should also make sure if doing a multinomial fit that the f_1 and f_2 functions are normalized (i.e. their integral is equal =1 for every values of their parameters)

You can apply the short notation and for example re-write your function as

TF1 probFit("probFit", "[0] * f_1(pol1(1)) + [3] * f_2(pol1(4))")

where f_1 and f_2 are functions defined before

Lorenzo

Thank you for clarifying. I hadn’t thought of using SetParLimits() in the way that you described.

So then if I wanted to do an unbinned multinomial fit, I would set as options "WL MULTI"? If not, under what argument do I set "MULTI"?

I hadn’t considered pol1(1) and pol1(4) in the short notation because in my experience without setting variable indices I found pol 1 works but not pol1? Is that a bug?

So as a test to recreate the problem between using pol1 vs. pol 1, I tried both

TF1 logistic("logistic", "1 / (1 + exp(pol1))");
TF1 logistic1("logistic1", "1 / (1 + exp(pol 1))");

Both seemed to work this time when in printed them. So maybe the problem I was having with having to use pol N instead of polN has been resolved?

Hi,
the option “MULTI” will do a multinomial binned likelihood fit. From an histogram you cannot do un unbinned likelihood fit. You would need to do from a TTree or directly using the data using the Fitter class.

Using pol1 or pol 1 should be equivalent because whitespaces are removed when parsing the formula expressions. However I would use pol1 for better clarity

Lorenzo

If possible, could I please get some further clarification on usage of the “MULTI”. Do you mean it would be entered as the option or goption argument in TTree::Fit()?

It looks like when I said “unbinned fit”, I meant to say “fit with non-integer bins”. Sorry about that. Because I have been able to use TH1D::Fit() with option = "WL".

So with TH1D::Fit(), could I have option = "WL MULTI"? Looking under the class documentation for TTree and TH1, I’m having difficulty finding a description of the MULTI option and how it is used.

Hi,

The option MULTI works only for histograms (binned data). It should work also in case of weighted data (adding “WL” option).
It is true, I realised now it is not in the documentation of TH1::Fit. .I will add then add it

Lorenzo

1 Like