"Fit data is empty" 当 `TH1::SetDefaultSumw2` 开启时
"Fit data is empty" when `TH1::SetDefaultSumw2` is on
我有来自 NaI(Tl) 检测器的数据,该检测器具有大量的 bin 和每个 bin 的低计数(大约 5-30)。
我写了这个函数来提取数据并绘制它;然而,当我试图减去背景时,我得到 "Warning in : Fit data is empty"。这仅在我 TH1::SetDefaultSumw2(kTRUE)
未注释时发生。
为什么会发生这种情况(是我的信号太弱了吗?)我能否解决此问题同时仍确保正确的错误传播?
数据太长,无法内嵌;但是,我已经托管了文件:Co60 and 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();
}
Root 被调用:
.x Graph1.C("Co60.TKA", "Background.TKA", "Co60", 12200, 13500)
使用 "LL" 拟合参数解决了问题:
An improved Log Likelihood fit in case of very low statistics and when bincontentsare not integers. Do not use this option if bin contents are large (greater than 100).
https://root.cern.ch/root/html534/guides/users-guide/FittingHistograms.html#the-fit-method
我有来自 NaI(Tl) 检测器的数据,该检测器具有大量的 bin 和每个 bin 的低计数(大约 5-30)。
我写了这个函数来提取数据并绘制它;然而,当我试图减去背景时,我得到 "Warning in : Fit data is empty"。这仅在我 TH1::SetDefaultSumw2(kTRUE)
未注释时发生。
为什么会发生这种情况(是我的信号太弱了吗?)我能否解决此问题同时仍确保正确的错误传播?
数据太长,无法内嵌;但是,我已经托管了文件:Co60 and 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();
}
Root 被调用:
.x Graph1.C("Co60.TKA", "Background.TKA", "Co60", 12200, 13500)
使用 "LL" 拟合参数解决了问题:
An improved Log Likelihood fit in case of very low statistics and when bincontentsare not integers. Do not use this option if bin contents are large (greater than 100).
https://root.cern.ch/root/html534/guides/users-guide/FittingHistograms.html#the-fit-method