Function convolution with parameters

Hi,

There were some problems in the definition of the tot3 function.
First of all (apologies for the mistake I did in my previous post, I will correct it now), the tot3 funciton must be defined using a lambda capturing by value and not by reference ! So the correct definition of tot3 is (note that now one used [=] instead of [&])

 TF1 *total3 = new TF1("tot3",[=](double* x, double* p){ return core3->EvalPar(x, p) * 0.001 + bg3->EvalPar(x, p+npar3);}, inf, sup, npar3 + bg3->GetNpar());

This is needed otherwise one gets a crash when painting the function, since painting is called outside the scope of the macro and the reference is not any more valid.

There was also an error in defining the initial parameters for fitting of tot3. Here is the correct code defining the fitting function:


  TF1 *core3 = new TF1("core3", "CONV([0]*TMath::BreitWigner(x,[1],[2]), TMath::Exp(-0.5*((x-[0])/[1]*(x-[0])/[1]))/(sqrt(2*TMath::Pi())*[1]))",inf,sup);
  core3->Print();
  TF1 *bg3 = new TF1("bg3","pol1", inf, sup);
  int npar3 = core3->GetNpar();
  TF1 *total3 = new TF1("tot3",[=](double* x, double* p){ return core3->EvalPar(x, p) * 0.001 + bg3->EvalPar(x, p+npar3);}, inf, sup, npar3 + bg3->GetNpar());


  total3->Print(); cout << endl;

  total3->SetParameter(0, 10000);
  total3->SetParameter(1, 1.020);
  total3->SetParameter(2, 0.0016);
  
  total3->SetParameter(3, 0); // this initial parameter must be zero and  not 1.02
  total3->SetParameter(4, 0.0016);

  // do a background only fit to get the parameters for bg3
  Mphi->Fit(bg3);

  total3->SetParameter(5, bg3->GetParameter(0));
  total3->SetParameter(6, bg3->GetParameter(1));
  

  total3->SetParName(0, "N");
  total3->SetParName(1, "M");
  total3->SetParName(2, "#Gamma");
  total3->SetParName(3, "#mu");
  total3->SetParName(4, "#sigma");
  total3->SetParName(5, "Const 1");
  total3->SetParName(6, "Const 2");

 total3->SetParLimits(1, 1.000, 1.030);
// the  setted limits were wrong, I think they should be [0.00,0.020]
  total3->SetParLimits(2, 0.0, 0.020);

  Mphi->Fit("tot3", "", "", 0.97, 1.07);//1.020 - 0.02, 1.020 + 0.02);

For me it works and the fit gives a good result

Cheers
Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.