# Fit gaussian and exponential in the same plot

Here I want to fit the exponential and Gaussian together, but I don’t get a desired outline of the histogram.
Can you please point out the mistake ?

``````void f1()
{
TH1F *h4 = new TH1F("h4","Exponential+Gaussian",100,-1.,6.);
TF1 *f1 = new TF1("f1", "expo");
f1->SetParameter(0, 3);
f1->SetParameter(1, -0.3);
h4->FillRandom("f1",100000);

TF1 *f2 = new TF1("f2", "gaus");
f2->SetParameters(1, 2.1, 0.67);
h4->FillRandom("f2",15000);

TCanvas *c4 = new TCanvas("c4","Fit-1",800,600);

h4->Draw();

TF1 *fit1 = new TF1("fit1","f1",-1.,1.3);
TF1 *fit2 = new TF1("fit2","f2",1.3,3.);
TF1 *fit3 = new TF1("fit3","f1",3.,6.);
h4->Fit(fit1,"R");
h4->Fit(fit2,"R");
h4->Fit(fit3,"R");

c4->Print("H4.jpg");
}
``````

ROOT Version: 6.27/01
Platform: Linux
Compiler: C++17

``````	h4->Fit(fit1, "R");
h4->Fit(fit2, "R+");
h4->Fit(fit3, "R+");
``````

Thank you. It works, but I am getting a break in the line (as expected).
Is there any way to get a continuous curve , by this method (without specifying the range)?

``````TF1 *f = new TF1("f", "gaus(0) + expo(3)", 0., 1.); // "range" is unimportant
f->SetParameters(600., 2., 0.7, 8., -0.3); // "reasonable" initial parameters
h4->Fit(f);
``````

Yes, it works perfect.
Actually , this is a very easy method as compared to the tutorial examples.
Thank you so much.

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