TTree::Fit() problem

I wrote a program to fit 5 branches in a root file with TF1Convolution landau_gaus
First, I need to get the initial parameters.
When I did it like

for (Int_t ch = 0; ch < 5; ch++) {
	if (xmin[ch] == 0 && xmax[ch] == 0) {
		Double_t para[5]{};
		get_fit_para(tree, branchname[ch], para);
		con[ch] = para[0];
		mpv[ch] = para[1];
		std[ch] = para[2];
		xmin[ch] = para[3];
		xmax[ch] = para[4];
	}
}

(there is a tree->Fit("landau", varexp, "", "Q"); in the function get_fit_para())
It reports Warning in <Fit>: Fit data is empty for ch=4
When I did it like

for (Int_t i = 0; i < 5; i++) {
	Int_t ch = 4 - i;
	if (xmin[ch] == 0 && xmax[ch] == 0) {
		Double_t para[5]{};
		get_fit_para(tree, branchname[ch], para);
		con[ch] = para[0];
		mpv[ch] = para[1];
		std[ch] = para[2];
		xmin[ch] = para[3];
		xmax[ch] = para[4];
	}
}

It reports Warning in <Fit>: Fit data is empty for ch=0
What could be the reason?

_ROOT Version:6.30/06
Platform: Not Provided
Compiler: Not Provided


Can you provide a minimal reproducer, or at least the source code of get_fit_para?

Here is the source code of get_fit_para

void get_fit_para(TTree* tree, TString branchname, Double_t para[5])
{
	TString histname = "htemp";
	TString varexp = branchname + ">>" + histname;
	tree->Fit("landau", varexp, "", "Q");
	TH1D* h = (TH1D*)gPad->GetPrimitive(histname);
	Double_t mean = h->GetMean();
	Double_t rms = h->GetRMS();
	TF1* fit = h->GetFunction("landau");
	if (fit) {
		para[0] = fit->GetParameter(0);
		para[1] = fit->GetParameter(1);
		para[2] = fit->GetParameter(2);
	} else {
		para[0] = 15;
		para[1] = mean;
		para[2] = 30;
	}
	para[3] = 0.5 * mean;
	para[4] = 2.5 * mean;
}

OK, thanks. I don’t see anything obvious… Maybe @jonas could take a look

Thanks for your attention, I just found that this problem doesn’t occur for all root files (generated by the same geant4 program with different parameters).
And it never occurs when I run the code sentence by sentence in the terminal.
Anyway, I can avoid it by appoint the parameters which should be determined by get_fit_para manually.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.