I guess, the trick with the parameter “[2]” is to scale “x” and then also “u” (as they appear in your “definition”), so that the “mean” (and thus also the “variance”) remains simply the value of the parameter “[1]”.
You could try to “scale” the “x-axis” of your histogram by the value of the parameter “[2]” (then also possibly “f1->FixParameter(2, 1.0);
”) and then redo your fit:
{
gStyle->SetOptFit(112);
Double_t xmin = 0, xmax = 10;
// define the Poisson fit function
TF1 *f = new TF1("f", "[0]*TMath::Power(([1]/[2]),(x/[2]))*(TMath::Exp(-([1]/[2])))/TMath::Gamma((x/[2])+1.)", xmin, xmax);
f->SetParameters(1, 1, 1); // you MUST set non-zero initial values for parameters
// define and "fill" the histogram
TH1D *h = new TH1D("h", "h", 10, xmin, xmax);
h->SetBinContent(1, 0);
h->SetBinContent(2, 2100);
h->SetBinContent(3, 4400);
h->SetBinContent(4, 1500);
h->SetBinContent(5, 200);
h->SetBinContent(6, 100);
h->SetBinContent(7, 50);
h->SetBinContent(8, 50);
h->SetBinContent(9, 20);
h->SetBinContent(10, 0);
// fit the histogram
h->Fit(f, "R"); // "R" = fit between "xmin" and "xmax" of the "f"
std::cout << "original mean = " << f->GetParameter(1)
<< " +- " << f->GetParError(1) << std::endl;
// return; // ... "break" here ...
// "scale" the "fix bins x-axis" of the histogram
Double_t s = f->GetParameter(2); // the fitted "scaling" parameter
xmin /= s; xmax /= s;
h->GetXaxis()->Set(h->GetNbinsX(), xmin, xmax);
h->SetTitle("h scaled");
// fit the "scaled" histogram
f->SetRange(xmin, xmax); // set the new "scaled" range
// f->FixParameter(2, 1.0); // fix the "scaling" parameter
h->Fit(f, "R"); // "R" = fit between "xmin" and "xmax" of the "f"
std::cout << "scaled mean = " << (s * f->GetParameter(1))
<< " +- " << (s * f->GetParError(1)) << std::endl;
}