So I am fitting a histogram with a Poisson distribution. I do not use directly ROOT, I use g++ to compile an executable which links to ROOT.
Here is the problem which unfortunately I cannot show but just explain:

I run my code -> it works
The histogram shows up, but the fit is flat when I declared it as Poissonian-> problem
I open fit panel.
I fit manually a gaussian to the histogram -> it works (that means I get a gaussian fit but it is obviously not what I want)
I fit manually the exact same Poisson distribution that I have on my code -> it works!!

Note that I do not get any error messages during the whole process and that I NEED to first fit a gaussian before fitting Poisson for it to work. (and yes I did try to do exactly that in the code but without success)
Problem is, I have over 1000 histograms to fit and I just can’t do this manually for each of them.

Anyone ever encountered this problem? Can you help?

Here are some portion of my codes which I think could be relevant to the problem:

TH1F *h1[i][j];
char *hist2name = new char[10];
for (int v=0; v<i; v++){
for (int p=0; p<j; p++){
sprintf(hist2name, "h2v%dp%d",i,j);
h1[v][p]=new TH1F(hist2name,"",500,0,0.05);
}
}
TF1 *f2 = new TF1("f2","[0]*TMath::Power(([1]/[2]),(x/[2]))*(TMath::Exp(-([1]/[2])))/TMath::Gamma((x/[2])+1)",lowerbound,upperbound);
f2->SetParameters(0.1, 0.1, 0.1);
h1[1][24]->Fit("f2","R"); // I have many histogram but for now I am just drawing/fitting this one to figure out the problem

I see… indeed the problem comes from the parameter initialization. Thank you

However this poses another problem. Like I said I have many histograms to fit and unfortunately many require different parameters from one another. If I use SetParLimits, it doesn’t help because the range gets too big and I receive a warning and the fit is not optimal. So isn’t there an automated way to check for the ideal parameters for example?

For every “histo” that you need to “fit”, try to estimate initial parameters playing with:

// 1 = "X axis"
histo->GetMean(1)
histo->GetRMS(1)
// the "X" values of the first and last bins
histo->GetBinCenter(1)
histo->GetBinCenter(histo->GetNbinsX())
// 2 = "Y axis"
histo->GetMean(2)
histo->GetRMS(2)
// the "Y" values of the first and last bins
histo->GetBinContent(1)
histo->GetBinContent(histo->GetNbinsX())
// the "Y" minimum value and its "X" position
histo->GetMinimum()
histo->GetBinCenter(histo->GetMinimumBin())
// the "Y" maximum value and its "X" position
histo->GetMaximum()
histo->GetBinCenter(histo->GetMaximumBin())