HI everyone,
I’m trying to fit a vector of histograms, but when I execute the macro, after a while root 6 write this warning:
“Warning: Fit Data is Empty”
And when I try to draw the fitted function, root crashes.
Now I’ll explain better: the code is very long but basically I create two vector of TH1F, one for electron and one for muon.
I fit all the vector of electron without problem, with the follower function:
void vechisto_gaus_fit(vector<TH1F*> fit_hist) { //fit_hist is the vector that I want to fit
for(i=0;i<fit_hist.size();i++) {
TF1 *f = new TF1("Gaussian","gaus",-fit_hist.at(i)->GetRMS(),fit_hist.at(i)->GetRMS());
f->SetParameter(0, fit_hist.at(i)->Integral()/2.5);
f->SetParameter(1, fit_hist.at(i)->GetMean());
f->SetParLimits(1,fit_hist.at(i)->GetMean()-fit_hist.at(i)->GetRMS(),fit_hist.at(i)->GetMean()+fit_hist.at(i)->GetRMS());
f->SetParameter(2, fit_hist.at(i)->GetRMS()/2);
f->SetParLimits(2,2*(fit_hist.at(i)->GetRMS()),0.25*(fit_hist.at(i)->GetRMS()));
fit_hist.at(i)->Fit(f, "QMR","",-fit_hist.at(i)->GetRMS(), fit_hist.at(i)->GetRMS()); //here's the warning
TF1 *myfunc = fit_hist.at(i)->GetFunction("Gaussian");
myfunc->Draw("same"); //here's the crash
}
}
No problem, since here.
When I try to use the same function in order to fit the other vector of histograms, the muon one, at the first iteration, at the instruction Fit, root writes the warning above, while at the instruction Draw (see comment on the code), root crashes. The crash report is here:
I read that this problem occurs when I’m trying to fit an histo with no entries. So, before calling this fit function, I wrote all vector of histo in a TFile, and i checked all histograms of the vector of muon, one by one, and no one of them is empty.
Please, help me!