Dependent variable on fitting

Hi everyone!
Well I want to create a fitting function which has a variable that is x and y dependent. I’m posting what I did, which is wrong, just to give you the idea. Variable is u. I was wondering if I could turn it to function through a loop or something else. The idea is that u=u(x,y) so it changes for each x,y value. I would like root to print out these u_values and also to fit Tgrapherror with the running u.

{
   c1 = new TCanvas("c1","Gamma/Z Interferance/ Cross section vs Energy  ",200,10,700,500);
   c1->SetFillColor(41);
   c1->SetGrid();
   c1->GetFrame()->SetFillColor(21);
   c1->GetFrame()->SetBorderSize(12);
   const Int_t n = 20;
   Double_t x[n]  = {20, 30, 34.4, 40, 50, 60, 70, 80, 83, 85, 88, 90, 91, 93, 95, 97, 100, 105, 110, 120};
   Double_t y[n]  = {256.8,120.6,93.42,70.54,46.92,34.46,28.91,36.58,50.69,73.88,206.9,752.2,1414,687.1,306.6,186.2,114.3,68.49,48.41,30.2};
   Double_t ex[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0,.0};

   Double_t ey[n] = {0.0562,0.04337,0.03265,0.02115,0.01525,0.01294,0.01749,0.02653,0.03903,0.11,0.4007,
0.7527,0.3525,0.139,0.0867,0.06234,0.03734,0.02657,0.01483};

   gr = new TGraphErrors(n,x,y,ex,ey);
   gr->SetTitle("Cross Section (pb) vs Energy (GeV), #gamma*/Z Interference");
   gr->SetMarkerColor(4);
   gr->SetMarkerStyle(8);
   gr->GetXaxis()->SetTitle("#sqrt{s} (GeV)");
   gr->GetYaxis()->SetTitle("#sigma (pb)");
   gr->Draw("ALP");

   Double_t b_zero[x,y] = (48*TMath::Pi()*(x**2)*y)-0.0367;
   Double_t b_one[x] = ((x**2)*0.0158)/(((x**2-91.1876**2)**2+(91.1876*2.4952)**2)**(1/2));
   Double_t b_two[x] = ((x**2)*0.0003)/((x**2-91.1876**2)**2+(91.1876*2.4952)**2);
   Double_t u = (-b_two+(b_two**2+4*b_one*b_two)**(1/2))/(2*b_one);
   

   TF1 *f1 = new TF1("f1","([0]/x**2) + (([1]*(u**2)*(x**2))/((x**2 - [2]**2)**2 + ([2]*[3])**2)) + (([4]*u)/((x**2 - [2]**2)**2 + ([2]*[3])**2)**(1/2))", 20., 130.);
   
   f1->SetParameters(0.0002433744, 9.58775074077431E-06, 91.1876, 2.4952, 6.0180462856623E-07);
    gr->Fit("f1","R");
    gr->Fit("f1","R");
    gr->Fit("f1","R");
    gr->Fit("f1","R");
    gr->Fit("f1","R");
     
   gr->Draw();

   c1->Update();
   c1->GetFrame()->SetFillColor(19);
   c1->GetFrame()->SetBorderSize(12);
   c1->Modified();
    
   return c1;
}

I guess @moneta can help you with this.

Hello @elena_573,

first, the lines

Will probably not work. Did you try putting this into a script and loading/executing it? If you do that, cling will tell you what’s not ok. You are trying to do a computation on an array, but this kind of syntax doesn’t work in C++.

Concerning your question of dependent variables:
There certainly is a way to achieve this: substitution. Let’s say you have
x + y
and y = 2x
after substituting you have:
x + 2x

If you follow this through completely, you can compose a fit function that will work with TF1.

Thank you very much!
Yes, I put it in a script and executed it. I had also tried the substitution and it worked but I was wondering if there was an easier way so that I could avoid such a complex function.

Στις Τρί, 19 Μαρ 2019, 00:05 ο χρήστης Stephan Hageboeck root.discourse@cern.ch έγραψε: