Bool_t reject; Double_t fitf(Double_t *x, Double_t *par) { //if (reject && x[0] > 25 && x[0] < 35) { // TF1::RejectPoint(); // return 0; //} return par[0]*exp(-1*20e-9*x[0]*par[1]); } Double_t ftotal(Double_t *x, Double_t *par) { if (reject && x[0] > 28 && x[0] < 35) { TF1::RejectPoint(); return 0; } return fitf(x,par) + fitf(x,&par[4]); } void myfit2() { //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); reject = kFALSE; 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+"); TF1 *f1 = (TF1*)histup->GetListOfFunctions()->FindObject("mstotal"); histup->GetListOfFunctions()->Remove(f1); histup->GetListOfFunctions()->AddFirst(f1); double ChiSq = total->GetChisquare(); double NDF = total->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 */ reject = kTRUE; /* 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->SetBinError(18, 0); histup2->SetBinError(19, 0); histup2->SetBinError(20, 0); histup2->SetBinError(21, 0); histup2->SetBinError(22, 0); histup2->SetBinError(23, 0); histup2->SetBinError(24, 0); histup2->SetBinError(25, 0); */ histup2->SetMaximum(220); 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+"); f1 = (TF1*)histup2->GetListOfFunctions()->FindObject("mstotal"); histup2->GetListOfFunctions()->Remove(f1); histup2->GetListOfFunctions()->AddFirst(f1); reject = kFALSE; double ChiSq = total->GetChisquare(); double NDF = total->GetNDF(); printf("ChiSq/NDF: %.2f\n",ChiSq/NDF); }