Identifying Parameters in TF*s

I am wondering if it is possible to identify two parameters in a TF* so that when doing a fit, the two parameters are treated as a single parameter. E.g. if I have a TF1,

TF1 f1("f1","x*[0]+[1]/x")

can I after the fact set the two parameters as one? As if I had written “x*[0]+[0]/x”?

The reason I want to do this is that I have a big TF2 which is the sum of three two-dimensional Gaussians. It has 18 parameters (each Gaussian has an amplitude, (x,y) central value and sigma, and correlation coefficient). To make this function I first create a single 2D Gaussian using a TFormula:

TF2 f2_e("f2_e","[0]/(2.0*pi*[2]*[4]*sqrt(1.0-[5]**2))*exp( -1.0/(2*(1-[5]**2)) * ( ((x-[1])/[2])**2 + ((y-[3])/[4])**2 - 2*[5]*(x-[1])*(y-[3])/([2]*[4]) ) )",xmin,xmax,ymin,ymax);

Then I clone it twice, giving the clones the names “f2_mu” and “f2_pi”. Then I add them into a big TF2:

I set the parameters and parlimtis of this big TF2 and use it to fit a TH2D. I want to try the fit with the correlation coefficients all equal [5], [11], and [17], but I would rather not have to put in a TFormula with 17 parameters…



I think the best is to create a new TF1 object using the first one, and treat the two parameter as one.
You can use the capability of create a TF1 from a functor to do this (see )

For example, if you have

TF1 f1("f1","x*[0]+[1]/x")

You can create a new functor object:

struct MyFunc { 

 MyFunc( TF1 * f) : func(f) {}
 TF1 * func; 
 double par[2]; 

 double operator() (double *x, double *p) {
     // set the parameters in f1
     par[0] = p[0];
     par[1] = p[0];
     return func->EvalPar(x, par); 


MyFunc myf2(f1); 
TF1 * f2 = new TF1("f2",myf2, xmin, xmax, 1);