# TF1:SetParameters inconsistency

Hi,

As far as I understand the “pol1(x)” documentation

pol1(2) is equivalent to [2]+[3]*x

However, this doesn’t seem to work consistently. The following code gives the correct result for the TF1 “upperWidth” ->Draw()

TF1 *dWidth = new TF1(“dWidth”, “pol1(2)”);
dWidth->SetParameter(2, sigmaParameters[0] );
dWidth->SetParameter(3, sigmaParameters[1] );
TF1 *upperWidth = new TF1(“upperWidth”, “dWidth”, 1, 6);

Adding another function to “upperWidth” breaks this functionality. For example, this code does NOT work correctly:

TF1 *mean = new TF1(“mean”, “pol1(0)” );
mean->SetParameters( meanParameters );
TF1 *dWidth = new TF1(“dWidth”, “pol1(2)”);
dWidth->SetParameter(2, sigmaParameters[0] );
dWidth->SetParameter(3, sigmaParameters[1] );
TF1 *upperWidth = new TF1(“upperWidth”, “mean + dWidth”, 1, 6);

Instead, I have to do this:

TF1 *mean = new TF1(“mean”, “pol1(0)” );
mean->SetParameters( meanParameters );
TF1 *dWidth = new TF1(“dWidth”, “pol1(2)”);
dWidth->SetParameter(0, sigmaParameters[0] );
dWidth->SetParameter(1, sigmaParameters[1] );
TF1 *upperWidth = new TF1(“upperWidth”, “mean + dWidth”, 1, 6);

This is completely confusing to me! What is the rule here? Who came up this? How can I ensure that the parameter numbering scheme is not redefined when I use a linear combination of functions?

Kind regards,
Martin

The notation pol1(2) makes sense only in the final expression, eg in

``` TF1 f1("f1","gaus+pol1(3)",-1,1); ```creates a function with 5 parameters (3 for gaus and 2 for pol1) with

``` par[0] = 1st gaus parameter (norm factor) par[1] = 2nd gaus parameter (mean) par[2] = 3rd gaus parameter (sigma) par[3] = 1st pol1 parameter par[4] = 2nd pol1 parameter```
and you set the parameters with something like

``` f1.SetParameters(gnorm,mean,sigma,const,slope); ```
Rene

Hi Rene,

How do I permanently assign parameters to a function (or formula?), so that I can use the function later as part of another function? – Without redefining what par[0] means. – I don’t know the value of the parameters until runtime, because they are the result of a fit.

In addition, I then want to use the TF1 as a cut on a TTree:

TTree->Draw(“variable1”, “variable2> f1(variable1)”)

where f1 represents is this user-defined function.

Regards,
Martin

[quote=“brun”]The notation pol1(2) makes sense only in the final expression, eg in

``` TF1 f1("f1","gaus+pol1(3)",-1,1); ```creates a function with 5 parameters (3 for gaus and 2 for pol1) with

``` par[0] = 1st gaus parameter (norm factor) par[1] = 2nd gaus parameter (mean) par[2] = 3rd gaus parameter (sigma) par[3] = 1st pol1 parameter par[4] = 2nd pol1 parameter```
and you set the parameters with something like

``` f1.SetParameters(gnorm,mean,sigma,const,slope); ```
Rene[/quote]