How can i fitting two kind of function

Hi experts.
I want to make two fittings as shown below. What should I do?


Also want to integrate the blue line function.

This is the code i wrote when i fit the function of the blue line only.
void Fit2()
{
double initparms[] = {68.37, 2.89, 0.51};
TF1 *f1 = new TF1(“f1”,“gaus”);
f1->SetParameters(initparms);
hdet_y->Fit(f1,"","",0,6);
}


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


There is similar examples in the Fit Tutorials.
Did you look at them ?

That looks like a homework assignment! So let’s turn on teacher mode :slight_smile:

What’s the shape of the blue curve? How does one calculate the integral of that?

The red curve is a combination of the blue curve and a “pol2”: "gaus + pol2" is what you’re after.

I don’t know how can i get the multi fit and integrate them.

void MultiFit()
{
 double initparms[] = {68.37, 2.9, 0.51, 24.1, -8.2, 0.74};
 TF1 *f1 = new TF1("f1","gaus(0)+pol2(3)");
 f1->SetParameters(initparms);
 hdet_y->Fit(f1,"","",0,6);
 double initparms2[] = {68.37, 2.9, 0.51};
 TF1 *f2 = new TF1("f1","gaus");
 f2->SetParameters(initparms2);
 hdet_y->Fit(f2,"","",0,6);
}

I type this code but only one fit graph came out.
What should i fix?

See this example.
What you are doing is not what is in this example. In particular the options R and +

Thaks! The problem was solved! Now i need to integrate over a Gaussian function, but how should i do it?

https://root.cern/doc/master/classTF1.html#a596e02742b00f1e265cc2dbe4daf20fe

Double_t TF1::Integral ( Double_t a,
Double_t b,
Double_t epsrel = 1.e-12
)

i can’t under stand the parameters a, b, epsrel. Whta’s mean?

And i wanna get different color of fit graph. How can i get the different color?

I would guess the limits (range) of the integral ?
@moneta can confirm.

void graphfit()
{
   gStyle->SetOptFit(1);
   Double_t x[] = {1., 2., 3.};
   Double_t y[] = {2., 3., 2.};
   auto g = new TGraph(3, x, y);
   g->Fit("gaus");
   g->Draw("A*");
   TF1 *fit = (TF1*)g->GetListOfFunctions()->FindObject("gaus");
   fit->SetLineColor(kGreen);
   fit->SetLineWidth(7);
}

How do I change it to a dotted line?
Thanks for reply!

fit->SetLineStyle(3)

Thanks :slight_smile:

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