Home | News | Documentation | Download

Problem fit: can't find function address

Hello, I trying to launch this macro :

void Parte22(){
  gStyle->SetOptFit(1);
  gStyle->SetOptStat(1);
  
 
  TH1F *hE = new TH1F("hE", "Distribuzione Eventi", 45,-5, 7);

  const Int_t n=400;
  Double_t x[n];
  ifstream file("MLE_norm.txt");
  Int_t i=0;
  Double_t ev=0.;
  while(!file.eof()){
    file>>ev;
    x[i]=ev;
    i++;
    hE->Fill(ev);
  }
  file.close();


  TCanvas *c0 = new TCanvas("c0", "Distribuzione eventi");
  hE->SetXTitle("x");
  hE->SetYTitle("Conteggi");

  TF1* f = new TF1("f","[0] * exp(-0.5 * ( (x-[1])/[2])**2) / (sqrt(2 * pi) * [2]) ) + [3] * exp(-0.5 * ( (x-[4])/[5])**2) / (sqrt(2 * pi) * [5]) )",-6,6,6); //parametri liberi


  f->SetParameter(0,30);
  f->SetParameter(1,3);
  f->SetParameter(2,1);
  f->SetParameter(3,70);
  f->SetParameter(4,0);
  f->SetParameter(5,2);

  hE->Fit(f,"","",-6,6);
  
  //dal fit determino Ns e lo confronto con quello ottenuto in precedenza
  Double_t A = f->GetParameter(0);
  Double_t B = f->GetParameter(1);
  Double_t Ns_fit = A/(A+B);
  Double_t Ns_fitErr=1/((A+B)**2)*sqrt((f->GetParError(0)*B)**2+(f->GetParError(1)*A)**2);
 
  printf("A=%g, B=%g \n Ns_fit=A/(A+B)=%g +\- %g\n ",A,B,Ns_fit,Ns_fitErr);


}

but I get the following error:
<TF1::TF1>: can not find any function at the adress 0x55a8919a88d0. This function requested for f.

How can I solve ?

  TF1* f = new TF1("f","[0] * exp(-0.5 * ( (x-[1])/[2])**2) / (sqrt(2 * pi) * [2]) ) + [3] * exp(-0.5 * ( (x-[4])/[5])**2) / (sqrt(2 * pi) * [5]) )",-6,6,6); //parametri liberi

Check the parenthesis in your fonction. They do not match.
Also you have an extra parameter “6” at the end.

Thanks so much.
I corrected.
Now it works correctly