Double_t fitf(Double_t *x, Double_t *par) { return par[0]*exp(-1*20e-9*x[0]*par[1]); } Double_t ftotal(Double_t *x, Double_t *par) { return fitf(x,par) + fitf(x,&par[4]); } void myfit() { gROOT->Reset(); gStyle->SetOptFit(); TH1F *h = (TH1F *) gROOT->FindObject("histup"); if (h) h->Delete(); TH1F *h = (TH1F *) gROOT->FindObject("histup2"); if (h) h->Delete(); Double_t par[6]; TFile *file = new TFile("spike_data.root","update"); TCanvas *c1 = new TCanvas("c1", "Spike data", 0, 0, 700, 700); c1->Divide(0,2); c1->cd(1); TH1F *histup = new TH1F("histup", "Up Decay Histogram", 291,10,300); spike_data_UP->Draw("UP_time >> histup"); /* Defining the various fit functions and their ranges */ TF1 *g1 = new TF1("Fit1", fitf,10,28,2); TF1 *g2 = new TF1("Fit2", fitf,35,300, 2); total = new TF1("mstotal",ftotal,10,316,4); g1->SetLineColor(kRed); g2->SetLineColor(kGreen); histup->Fit(g1,"R"); histup->Fit(g2,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[2]); total->SetParameters(par); total->SetLineColor(kBlue); total->SetParLimits(1, 33333, 1e6); total->SetParLimits(3, 33333, 1e6); histup->Fit(total,"R+"); double ChiSq = mstotal->GetChisquare(); double NDF = mstotal->GetNDF(); printf("ChiSq/NDF: %.2f\n",ChiSq/NDF); c1->cd(2); TH1F *histup2 = new TH1F("histup2", "Up Decay Histogram (Edited)", 291,10,300); spike_data_UP->Draw("UP_time >> histup2"); /* Setting the bin contents of where the spike is to more "appropriate" values */ histup2->SetBinContent(18, 150); histup2->SetBinContent(19, 145); histup2->SetBinContent(20, 143); histup2->SetBinContent(21, 136); histup2->SetBinContent(22, 130); histup2->SetBinContent(23, 127); histup2->SetBinContent(24, 130); histup2->SetBinContent(25, 125); histup2->Draw(); TF1 *g1 = new TF1("Fit1", fitf,10,28,2); TF1 *g2 = new TF1("Fit2", fitf,35,300, 2); total = new TF1("mstotal",ftotal,10,316,4); g1->SetLineColor(kRed); g2->SetLineColor(kGreen); histup2->Fit(g1,"R"); histup2->Fit(g2,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[2]); total->SetParameters(par); total->SetLineColor(kBlue); total->SetParLimits(1, 33333, 1e6); total->SetParLimits(3, 33333, 1e6); histup2->Fit(total,"R+"); double ChiSq = mstotal->GetChisquare(); double NDF = mstotal->GetNDF(); printf("ChiSq/NDF: %.2f\n",ChiSq/NDF); }