double gauss(double *x, double *par) { return par[0]*TMath::Gaus(x[0],par[1], par[2]) ; } double fitFunc(double *x, double *par) { return gauss(x,par) + gauss(x,&par[3]); } void double_simple_gauss_fit() { delete gRandom; gRandom = new TRandom(123456); // Setting the seed TH1F *gauss = new TH1F ("gauss", "Double Gauss Distribution", 200, 0, 20); double a; for(int i=0; i<100000; ++i){ a=gRandom->Gaus(7,1); gauss->Fill(a) ; a=gRandom->Gaus(12,1.5); gauss->Fill(a); } TF1 *f1 = new TF1("f1", fitFunc, 0, 20,6); f1->SetLineColor(2); // Orismos oriwn kai onomatwn parametrwn prwtis gaussianis f1->SetParameter(0,4000); f1->SetParName(0, "Constant 1"); f1->SetParameter(1,7); f1->SetParName(1, "Mean_1"); f1->SetParameter(2,1); f1->SetParName(2, "Sigma_1"); // Ovismos oriwn kai onomatwn parametrwn deyteris gaussianis f1->SetParameter(3,2500); f1->SetParName(3, "Constant 2"); f1->SetParameter(4,12) ; f1->SetParName(4, "Mean_2") ; f1->SetParameter(5,1.5); f1->SetParName(5, "Sigma_2") ; gStyle->SetOptFit(111); TCanvas *c1 = new TCanvas("c1", "Gauss", 800, 500); c1->cd() ; gauss->Fit("f1","","",4,16); }