"Fit data is empty" 当"TH1::SetDefaultSumw2"打开时

"Fit data is empty" when `TH1::SetDefaultSumw2` is on

本文关键字:SetDefaultSumw2 Fit data is empty TH1      更新时间:2023-10-16

我有来自NaI(Tl)检测器的数据,该检测器具有大量的bin和每个bin的低计数(约5-30)。

我编写了这个函数来提取数据并绘制它;然而,当我试图减去背景时,我得到"警告:Fit数据是空的"。这只发生在我有未注释的TH1::SetDefaultSumw2(kTRUE)时。

为什么会发生这种情况(我的信号太低了吗?)我可以解决这个问题,同时仍然确保正确的错误传播?

数据太长,无法内联;但是,我已经托管了文件:Co60和Background。

代码(文件名Graph1.C):

#include <vector>
#include <cmath>
#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();
}

根被调用:

.x Graph1.C("Co60.TKA", "Background.TKA", "Co60", 12200, 13500)

使用"LL" fit参数解决的问题:

改进的Log Likelihood适合于非常低的统计量和bincontents_不是整数的情况。如果bin内容很大(大于100),请不要使用此选项。

https://root.cern.ch/root/html534/guides/users-guide/FittingHistograms.html the-fit-method