void Re_Smear_3gauss() { gStyle->SetOptStat(2211); gStyle->SetOptFit(1111); /////////////////// Tree opening \\\\\\\\\\\\\\\ TFile *file1=TFile::Open("Analysis.root"); TTree *tree1=(TTree*)file1->Get("Analysis"); TH1D*h1 = new TH1D("h1","h1", 101.0,39.5,140.5); //Defining a TF1Convolution TF1Convolution *f_conv = new TF1Convolution("[0]*exp(-((x-[1])/[2])**2) + [3]*exp(-((x-([1]-[4]))/[5])**2) + [3]*exp(-((x-([1]+[4]))/[5])**2)", "gaus", 30.,150., true); f_conv->SetRange(30.,150.); f_conv->SetNofPointsFFT(1000); TF1 *f = new TF1("f", *f_conv, 40., 140., f_conv->GetNpar()); TF1 *f_no_res = new TF1("f_no_res", "[0]*exp(-((x-[1])/[2])**2) + [3]*exp(-((x-([1]-[4]))/[5])**2) + [3]*exp(-((x-([1]+[4]))/[5])**2)", 40., 140.); f->SetParameters(1e3,90.,13., 1e3 ,100.,30., 1.,0.,3.5); f->SetParNames("A_{1}","#mu_{1}","#sigma_{1}","A_{2}","#mu_shift","#sigma_{2}","Amplitude Convolution","#mu_conv","#sigma_res"); // I set the amplitude of the 2 gaussian to be positive f->SetParLimits(0,0.,1e6); f->SetParLimits(3,0.,1e6); // I set the mean of the 2 gaussian to be between 60 and 120 f->SetParLimits(1,60.,120.); f->SetParLimits(4,0.,20.); // I set the sigma of the 2 gaussian to be between 0 and 100 f->SetParLimits(2,1.,40.); f->SetParLimits(5,1.,40.); // i fix the parameters of the convoluted gaussian f->FixParameter(6,1./(3.5*TMath::Sqrt(2*TMath::Pi())) ); f->FixParameter(7,0.); f->FixParameter(8,3.5); TCanvas *c1 = new TCanvas("c1","Without constraint",800,600); c1->Divide(2,2); c1->cd(1); tree1->Draw("M_Tot>>h1"); c1->cd(2); h1->Draw("E1"); h1->Fit(f,"ME"); f_no_res->SetParameters(f->GetParameters()); auto h2 = new TH1D("h2","h2_Mass_resolution",101.0,39.5,140.5); h2 = (TH1D*)f_no_res->GetHistogram(); h2->SetStats(kTRUE); c1->cd(3); gStyle->SetOptStat(2211); gStyle->SetOptFit(111); h2->Draw("E1"); }