{ // gStyle->SetOptFit(); Int_t n = 160; Double_t xl = 380., xr = xl + n; // make sure "bin width" = 1. TH1D *h = new TH1D("h", "h;Channel;Counts", n, xl, xr); TF1 *f = new TF1("f", "gausn(0) + gausn(3) + pol2(6)", xl, xr); TF1 *pol2 = new TF1("Mypol2","pol2", xl, xr); TF1 *g1 = new TF1("Myg1","gausn", xl, xr); TF1 *g2 = new TF1("Myg2","gausn", xl, xr); //"gausn” Normalized form of the gaussian function with 3 parameters f(x) = p0*exp(-0.5*((x-p1)/p2)^2)/(p2 *sqrt(2PI)) f->SetParNames("Area_1", "Mean_1", "Sigma_1", // gausn(0) "Area_2", "Mean_2", "Sigma_2", // gausn(3) "c", "b", "a"); // pol2(6) // f->Print(); f->SetParameters(5.e4, 430., 10., // gausn(0) 4.e4, 490., 10., // gausn(3) 400., 0.4, -0.002); // pol2(6) // gRandom->SetSeed(0);22// make it "really random" h->FillRandom("f", Int_t(f->Integral(xl, xr) + 0.5)); //+0.5 is Just to get the “nearest” integer. h->Fit(f, "L"); // e.g., "" or "L" f->Delete(); g1->SetParameters(5.e4, 430., 10.); g2->SetParameters(4.e4, 490., 10.); pol2->SetParameters( 400., 0.4, -0.002); g1->SetLineColor(kBlue); g2->SetLineColor(kBlue); g1->Draw("same"); g2->Draw("same"); pol2->SetLineColor(kBlack); pol2->Draw("same"); }