void fit() { TFile *f = TFile::Open("plot.root"); TFile *file = new TFile("Fit_Res.root","RECREATE"); TCanvas *c = new TCanvas("c","",1); ROOT::Math::MinimizerOptions::SetDefaultMaxFunctionCalls( 10000000); c->SetLogy(); TH1D *h1 = (TH1D*)f->Get("Hadd_Resolution_HT_total_2"); Double_t par[12]; TF1 *g1 = new TF1("g1","gaus",0.5,0.7); TF1 *g2 = new TF1("g2","gaus",0.8,1.1); TF1 *g3 = new TF1("g3","gaus",1.1,1.3); TF1 *g4 = new TF1("g4","gaus",1.3,1.8); TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)+gaus(9)",0.5,1.8); total->SetLineColor(kBlue); h1->Fit(g1,"R"); h1->Fit(g2,"R+"); h1->Fit(g3,"R+"); h1->Fit(g4,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[3]); g3->GetParameters(&par[6]); g4->GetParameters(&par[9]); g1->SetLineColor(0); g2->SetLineColor(0); g3->SetLineColor(0); total->SetParameter(0,8.20989); total->SetParameter(1,0.740543); total->SetParameter(2,0.0620681); total->SetParameter(3,697.204); total->SetParameter(4,1.00438); total->SetParameter(5,0.0547298); total->SetParameter(6,309.261); total->SetParameter(7,1.02128); total->SetParameter(8,0.0800669); total->SetParameter(9,5.29383); total->SetParameter(10,1.3149); total->SetParameter(11,0.137413); h1->Fit(total,"R+"); Double_t chi2 = total->GetChisquare(); Double_t ndf = total->GetNDF(); Double_t chi2_ndf = chi2/ndf; cout<<" chi2 : "<Draw(""); h1->SetTitle(""); h1->GetXaxis()->SetMoreLogLabels(); h1->GetXaxis()->SetNoExponent(); h1->GetXaxis()->SetLabelSize(0.04); h1->SetMarkerStyle(20); h1->SetMarkerColor(kBlack); h1->SetLineColor(kBlack); h1->SetMarkerSize(0.2); h1->GetYaxis()->SetRangeUser(0.000001,1000000.); h1->GetXaxis()->SetRangeUser(0.3,2.0); h1->GetXaxis()->SetLabelSize(0.03); h1->GetXaxis()->SetTitleSize(0.035); h1->GetXaxis()->SetTitleOffset(1.19); c->Draw(); h1->Write(); file->Write(); //file->Close(); }