Fitting a sum of gaussian and exponential

Hello. I am trying to fit a momentum distribution as a sum of a gaussian plus an exponential. I followed the example multifit.C in the tutorials folder. In the first range I fit an exponential and in the second range a gaussian. Each individual fit looks ok, but the sum of the two is horrible and looks nothing like the individual fits. Any suggestions? I’ve attached the code and the plot that I get. Also, any suggestions on how to reduce the chi^2 once I do get the sum to look ok?

Thank you for your time!
momentum.pdf (15.7 KB)
momentum.cpp (1.5 KB)

Two things:
-the definition of your function total is wrong. It should be something like

TF1 *total = new TF1("total","(x<3.172)*exp([0]+[1]*x)+(x>3.172)*[2]*exp(-0.5*((x-[3])/[4])^2)",3.0,3.26);
-your chi2 is huge because your errors seem to be wrong (far too small)

Rene

Thank you!! That was the problem. The sum does what I expect now, and I’ll work on my error bars…

Thanks again for your response!