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
couet
May 31, 2021, 7:36am
2
There is similar examples in the Fit Tutorials .
Did you look at them ?
Axel
May 31, 2021, 8:31am
3
That looks like a homework assignment! So let’s turn on teacher mode
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?
couet
June 1, 2021, 10:34am
6
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?
couet
June 1, 2021, 10:53am
8
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?
couet
June 1, 2021, 11:06am
11
I would guess the limits (range) of the integral ?
@moneta can confirm.
couet
June 1, 2021, 11:16am
13
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!
system
Closed
June 16, 2021, 7:28am
17
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.