“Fit data is empty” when `TH1::SetDefaultSumw2` is on

I have data from a NaI(Tl) detector with a large number of bins and low counts per bin (around 5-30).

I have written this function to extract the data and graph it; however, when I’m attempting to subtract away the background I get “Warning in : Fit data is empty”. This only occurs when I have TH1::SetDefaultSumw2(kTRUE) uncommentted.

Why is this occurring (is my signal too low?) Can I fix this while still ensuring proper error propagation?

The data is too long to fit inline; however, I have hosted the files: xed.space/Background.TKA.

The code (file name Graph1.C):

[code]#include
#include
#include “TCanvas.h”
#include “TROOT.h”
#include “TGraphErrors.h”
#include “TH1.h”
#include “TF1.h”
#include “TLegend.h”
#include “TArrow.h”
#include “TLatex.h”

#define NBINS 16384
#define LOWBIN 0
#define HIGHBIN NBINS

using std::vector;
using std::ifstream;

void Graph1(char const* filename, char const* bgfilename, char const* title,
int start_bin = LOWBIN, int end_bin = HIGHBIN) {
TH1::SetDefaultSumw2(kTRUE);
gStyle->SetOptFit();
std::ifstream in;
in.open(filename);

std::ifstream bg;
bg.open(bgfilename);

std::string titleString = title + std::string(";Bin;Count");

TH1D *counts = new TH1D(“Counts”, titleString.c_str(), NBINS, LOWBIN, HIGHBIN);
TH1D bgcounts(“Bg”, “”, NBINS, LOWBIN, HIGHBIN);

int bin = 0;

while (in.good() && bg.good()) {
double temp;
in >> temp;
counts->AddBinContent(bin, temp);
bg >> temp;
bgcounts.AddBinContent(bin, temp);
++bin;
}

counts->Add(&bgcounts, -1.0);

TF1 *fit = new TF1(“fit”, “gaus”, start_bin, end_bin);
counts->Fit(fit, “R”);
counts->GetXaxis()->SetRange(start_bin, end_bin);

auto mycanvas = new TCanvas();
mycanvas->SetGrid();

counts->SetStats(false);
counts->Draw(“C E”);

mycanvas->Update();
mycanvas->Modified();
}[/code]

Root is called with:

Issue solved with the “LL” fit parameter.

root.cern.ch/root/html534/guide … fit-method

Try: int bin; double temp; bin = LOWBIN; while (in >> temp) counts->Fill(bin++, temp); bin = LOWBIN; while (bg >> temp) bgcounts.Fill(bin++, temp);