void Re_Smear() { 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("gaus(0)+gaus(3)", "gaus", 30.,150., true); TF1 *gaus_1=new TF1("gaus_1","gaus",30.,150.); TF1 *gaus_2=new TF1("gaus_2","gaus",30.,150.); f_conv->SetRange(30.,150.); f_conv->SetNofPointsFFT(1000); TF1 *f = new TF1("f", *f_conv, 40., 140., f_conv->GetNpar()); f->SetParameters(1e3,90.,13., 1e3 ,100.,30., 1.,0.,3.5); f->SetParNames("A_{1}","#mu_{1}","#sigma_{1}","A_{2}","#mu_{2}","#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,60.,120.); // 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.); 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"); gaus_1->SetParameters(f->GetParameters()); gaus_2->SetParameters(f->GetParameters()+3); gaus_1->SetParameter(0, 3.5*TMath::Sqrt(2*TMath::Pi())* gaus_1->GetParameter(0)); gaus_2->SetParameter(0, 3.5*TMath::Sqrt(2*TMath::Pi())* gaus_2->GetParameter(0)); gaus_1->SetLineColor(kBlue); gaus_2->SetLineColor(kBlue); gaus_1->Draw("same"); gaus_2->Draw("same"); auto h2 = new TH1D("h2","h2_Mass_resolution",101.0,39.5,140.5); h2 = (TH1D*)f->GetHistogram(); c1->cd(3); gStyle->SetOptStat(2211); gStyle->SetOptFit(111); h2->Draw("E1"); }