void data_2() { TCanvas *c1 = new TCanvas(); double x[51] = { 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163 }; double y[51] = { 1, 3, 6, 11, 30, 60, 120, 216, 346, 481, 601, 825, 1011, 1165, 1317, 1400, 1464, 1594, 1734, 1872, 2115, 2458, 2616, 2797, 3025, 2826, 3025, 2797, 2616, 2458, 2115, 1872, 1734, 1594, 1464, 1400, 1317, 1165, 1011, 825, 601, 481, 346, 216, 120, 60, 30, 11, 6, 3, 1 }; TGraph *gr = new TGraph(51, x, y); gr->SetMarkerStyle(20); gr->Draw("APL"); gr->SetTitle(" "); double par[8]; TF1 *fit1 = new TF1("fit1", "gaus", 60, 90); fit1->SetLineColor(kMagenta); fit1->SetLineStyle(2); fit1->SetParameters(1500, 95, 1); // fit1->SetParameter(0, 1500); gr->Fit(fit1, "RB"); TF1 *fit2 = new TF1("fit2", "gaus", 100, 120); fit2->SetLineColor(kGreen); fit2->SetLineStyle(2); fit2->SetParameters(3500, 115, 1); // fit2->SetParameter(0, 3000); gr->Fit(fit2, "R+B"); TF1 *fit3 = new TF1("fit3", "gaus", 130, 170); fit3->SetLineColor(kMagenta); fit3->SetLineStyle(2); fit3->SetParameters(1500, 135, 1); // fit3->SetParameter(0, 1500); gr->Fit(fit3, "R+B"); fit1->GetParameters(&par[0]); fit2->GetParameters(&par[3]); fit3->GetParameters(&par[6]); TF1 *total = new TF1("total", "gaus(0)+gaus(3)+gaus(6)", 60, 180); total->SetLineColor(kBlue); total->SetParameters(par); gr->Fit(total, "R+"); fit1->SetRange(60,120); fit1->Draw("same"); fit2->SetRange(60,160); fit2->Draw("same"); fit3->SetRange(100,170); fit3->Draw("same"); gPad->RedrawAxis(); double a = fit1->Eval(100); double b = fit2->Eval(100); double c = fit3->Eval(100); double d = total->Eval(100); cout << "The value of function at x = 100 is " << a << "," << b << "," << c << "," << d << endl; TLine *line1 = new TLine(100,0,100,3330); line1->Draw(); TLine *line2 = new TLine(55,a,170,a); line2->Draw(); TLine *line3 = new TLine(55,b,170,b); line3->Draw(); TLine *line4 = new TLine(55,c,170,c); line4->Draw(); TLine *line5 = new TLine(55,d,170,d); line5->Draw(); TLegend *leg = new TLegend(0.7796902,0.6464646,0.9661503,0.889899); leg->AddEntry(gr, "Expt.", "p"); leg->AddEntry(fit1, "Gaus-1", "l"); leg->AddEntry(fit2, "Gaus-2", "l"); leg->AddEntry(fit3, "Gaus-3", "l"); leg->AddEntry(total, "Fit", "l"); leg->SetTextFont(132); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextSize(0.03535354); leg->Draw(); //c1->Print("data_2.pdf"); }