Hi,
I’m fitting a signal histogram using two template histograms. This works fine with a chi-squared fit, but when I do a log-likelihood fit, I get an error. My code looks like:
// Function
Double_t ftotal(Double_t *x, Double_t *par) {
Double_t x0 = x[0];
Int_t bin = basis1->GetXaxis()->FindBin(x0);
Double_t trans = par[0]*basis1->GetBinContent(bin);
Double_t longit = par[1]*basis2->GetBinContent(bin);
return trans + longit;
}
// - Fit Signal with Linear Combination of Basis Histograms
void fithist() {
delete basis1; // - Cleanup from previous run
delete basis2;
TFile f = new TFile(“basis.root”); // - Retrieve Histograms from file
basis1 = (TH1F)f->Get(“basis1”);
basis2 = (TH1F*)f->Get(“basis2”);
TF1 *ftot = new TF1(“ftot”,ftotal,-1,1,2);
TFile *g = new TFile(“signal.root”);
TH1F signal = (TH1F)g->Get(“signal”);
signal.Fit(“ftot”,“L”); // - Fit
The error I get is within TFit. It reads "TH1F::Fit: Abnormal termination of minimization."
Is there another some way to fix this, or another method of using a log-likelihood fit to fit basis histograms to a signal histogram?
Thanks,
Ning