Fitting histograms convolution


I have a code, it fit my histograms. I need in convolution for 2 histograms. If I use convolution only for phi, i have:

But if i use convolution for first and second, i have:

Why secnd fit is broken?! For convolution i use code:

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);
  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, 800);
  total3->SetParameter(1, 1.020);
  //total3->SetParameter(2, 0.0045);
  //total3->SetParameter(3, 0);
  total3->SetParameter(4, 0.005);
  total3->SetParameter(5, 6);
  total3->SetParameter(6, 10);
  //total3->FixParameter(0, 0.0045);
  //total3->FixParameter(1, 1.020);
  total3->FixParameter(2, 0.0043);
  total3->FixParameter(3, 0);
  //total3->FixParameter(4, 0.0045);
  //total3->FixParameter(5, 0.0045);
  //total3->FixParameter(6, 0.0045);

  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");

  // do a background only fit to get the parameters for bg3

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

  Mphi->Fit("tot3", "", "", inf, sup);//1.020 - 0.02, 1.020 + 0.02);

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/08
Platform: Not Provided
Compiler: Not Provided

Perhaps @moneta can help.

please add your full macro and data, so it can be run. Looking just at the code snippet I cannot understand what is happening in your second case



this is like to google drive folder with a data and codes:

This is a development of my code. I have previously written in support about function folding, and you contributed:

I have no problem running your script. Also, I do not understand what is the problem compared to the previous post.


You’ve probably launched the first option. How many parameters do you have on a Momega histogram? Should be 7.

Hello again,
I think we need to explain it more to make it clearer. In script.C, lines 155-174 are responsible for pure Gaussian fitting. If you fit only with them, then everything is built normally. But I need a convolution here. Stages 176-221 are fitted with Breit-Wigner and Gaussian convolution using CONV. This is what I need, but then the next fit breaks. This can be seen in the second picture above. In the file on disk, lines 176-221 are commented out, so if you just run it, it fits with pure Gaussian. Uncomment them and comment out 155-174.

As I understand it, this is due to the peculiarities of using CONV, but I did not find anything about CONV in the root documentation.


Thank you for the explanation to reproduce the crash. I can reproduce it and I found the origin to a bug when using the CONV syntax in the TFconstructor a second time. It will be fixed it, but for the time being, you can use this workaround by adding these two lines before re-using theCONV` operator a second time:


Best regards


Actually there is even a simpler workaround, just re-set the range for the second TF1 created with the CONV operator In your case, just do after created the TF1 core3 object:


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