void doubleExpWithGauss() { std::vector xvals = {4490.0, 4510.0, 4530.0, 4550.0, 4570.0, 4590.0, 4610.0, 4630.0, 4650.0, 4670.0, 4690.0, 4710.0, 4730.0, 4750.0, 4770.0, 4790.0, 4810.0}; std::vector yvals = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 22.0, 140.0, 114.0, 88.0, 45.0, 30.0, 19.0, 10.0, 2.0, 2.0, 1.0}; int nbins = xvals.size(); double minval = *min_element(xvals.begin(), xvals.end()); double maxval = *max_element(xvals.begin(), xvals.end()); TH1D* h_testpulse = new TH1D("h_testpulse", "h_testpulse", nbins, minval-4630., maxval-4630); for(int i = 1; i<=nbins; i++){ h_testpulse->SetBinContent(i, yvals[i]); } TF1Convolution *f_conv = new TF1Convolution("[0]*exp(-x/[1])-[2]*exp(-x/[3])", "[0]*exp(-(x)^2/[1]^2)", -50, 150, true); f_conv->SetRange(-50., 150.); f_conv->SetNofPointsFFT(1000); f_conv->SetExtraRange(0.2); TF1 *f = new TF1("f", *f_conv, -50., 150., f_conv->GetNpar()); f->SetParameters(5., 33., -0.7, 587369., 1., 12.8); f->FixParameter(4,1); f->Draw(); //return ROOT::Math::MinimizerOptions::SetDefaultMaxFunctionCalls(10000000); // Fit. TCanvas * c = new TCanvas("c", "c", 800, 1000); c->cd(); auto res = h_testpulse->Fit("f","RS"); h_testpulse->Draw(); res->Print("V"); c->SaveAs("test.png"); }