Extract data points from a Gaussian fit

Hii experts,

I have three Gaussian fit in one canvas and want to extract data points from one Gaussian fit (the red one) as attached image.


Can I extract the data point from the red one fit? If so then how can I proceed? Waiting for your kind help.

Thanks,
Anil

_ROOT Version:_6.26/02
Platform: Not Provided
Compiler: Not Provided


pointer_to_the_red_TF1->Eval(some_x_value)

Thank you @Wile_E_Coyote for the reply.
The limit of x value for red line is -5. to 5. and TF1 defined as g1. Suppose the Eval will be print x=0.12. However I messed up. The data will save in a txt file. Here is the macro:

ofstream myfile;
myfile.open("data.txt");
TFile *f = new TFile("fit_gaus.root");
TH1F *h1 = (TH1F*)f->Get("h1");
TF1 *g1 = new TF1("fit1", "gaus", -5.,5.);
g1->Eval(0.12);
g1->SetLineColor(kRed);
TF1 *g2 = new TF1("fit2", "gaus", -5., 5.);
g2->SetLineColor(kGreen);
TF1 *f1 = new TF1("double_gaus", "gaus(0) + gaus(3)", -2.4, 3.);
f1->SetParNames("Constant 1", "Mean 1", "Sigma 1", "Constant 2", "Mean 2", "Sigma 2");
f1->SetLineColor(kBlue);
gStyle->SetOptFit(1);
h1->Fit(g1, "", "", -2.4, 0.1);
h1->Fit(g2, "+", "", 0.6, 2.9);
Double_t par[6];
g1->GetParameters(&par[0]);
g2->GetParameters(&par[3]);
f1->SetParameters(par);
h1->Fit(f1, "R+");
g1->Draw("SAME");
// g1->Eval(x);
g2->Draw("SAME");
f1->Draw("SAME");
myfile.close();

std::cout << g1->Eval(0.12) << "\n";

BTW. You can safely evaluate your function also outside of its “x limits”.

std::cout << g1->Eval(0.12) << "\n";
Output is zero for the above line.

Here my g1 limit is -5.0 to 5.0. So to get the data points within this limit,

std::cout << g1->Eval(-5.0, 5.0) << "\n";

Even the output is also zero. How to get the points within this limit?

You need to create a loop over “x” values.

BTW. I assume the “Output is zero” because you executed it before fitting.

Now it works. Thank you so much @Wile_E_Coyote