# Distorted gaussian function fit

Hello, I’m trying to fit two histograms by distorted gaussian function

``````

TF1 *fit = new TF1("fit","([0]/(2*[3]))*exp((x-[1])/[3]+[2]^2/(2*[3]^2))*erfc(1/sqrt(2)*((x-[1])/[2]+[2]/[3])) + [4] + [5]*x",6980,7010);
fit->SetParameters((300*10*2), 6995, 7, -4, 5,0);
fit->SetParLimits(0,10,1e4);
fit->SetParLimits(1,6990,7000);
fit->SetParLimits(2,0,15);
fit->SetParLimits(3,-10,10);
fit->SetParLimits(4,0,1);
fit->SetParLimits(5,-1e4,1e4);
``````

but it doesn’t fit it

You need to set “reasonable” initial values for all parameters of your function and try (instead of fitting): `fit->Draw();`
Once the plot looks OK, try to fit your data.

Hello @Wile_E_Coyote
I guessed that the problem is related to inital parameters…Given that it is the first time I use this function, I was looking if someone, looking the plots is able to set the initial parameters
Thanks

``````root [0] TF1 *fit = new TF1("fit","([0]/(2*[3]))*exp((x-[1])/[3]+[2]^2/(2*[3]^2))*erfc(1/sqrt(2)*((x-[1])/[2]+[2]/[3])) + [4] + [5]*x",6980,7010);
root [1] fit->SetParameters((300*10*2), 6995, 7, -4, 5,0);
root [2] fit->Draw()
``````

gives:

It does not seem close to the function you are looking for:
The Y range is completely wrong
The shape also
The X range is correct thought.

1 Like

what are the correct parameters?

the lambda is positive …I firstly tried negative values, because of Skew normal distribution - Wikipedia
but the lambda is positive

for example, for one of them

``````TF1 *fit = new TF1("fit","([0]/(2*[3]))*exp((x-[1])/[3]+[2]^2/(2*[3]^2))*erfc(1/sqrt(2)*((x-[1])/[2]+[2]/[3])) + [4] + [5]*x",6950,7050);
fit->SetParameters((300*10*2), 7000, 7, 4, 5,0);
fit->SetParLimits(0,10,1e4);
fit->SetParLimits(1,6990,7000);
fit->SetParLimits(2,0,15);
fit->SetParLimits(3,1,10);
fit->SetParLimits(4,0,100);
fit->SetParLimits(5,-1e4,1e4);
``````
1 Like

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