TF1::Mean()

Hello,

I am having a problem is that when I try to find a mean value of TF1 with user defined function (script is saved in a file):

Double_t gauss(Double_t *x, Double_t *par)
{
return (par[0] * TMath::Gaus(x[0],par[1],par[2]));
}

TF1 *g = new TF1(“gmy”, gauss, 0, 10, 3);
g->SetParameters(norm, mean, sig);

Double_t m1 = g->Mean(1, 2);
cout << "mean = " << m1 << endl;

The result is:

ERROR 26 :
Unknown name : "gauss"
Error in TF1::TF1: function: TF1_ExpValHelper/gmy
pow(x,1.000000) has 0 parameters instead of 1
mean = 3.84049e-267

What does it mean?
Thanks

Send a very short script reproducing the problem. See also:
root.cern.ch/root/roottalk/RoottalkRules.html

Rene

I am isung ROOT 3.10/02 at PII, Linux.
This is my script:

#include <TMath.h>
#include <TF1.h>

Double_t gauss(Double_t *x, Double_t *par)
{
return (par[0] * TMath::Gaus(x[0],par[1],par[2]));
}

void scr()
{
TF1 *g1 = new TF1(“g1”, gauss, 0, 10, 3);
g1->SetParameters(1, 1, 1);
g1->Draw();
Double_t m1 = g1->Mean(0, 10);
}

ROOT prints error:
ERROR 26 :
Unknown name : "gauss"
Error in TF1::TF1: function: TF1_ExpValHelper/g1
pow(x,1.000000) has 0 parameters instead of 1
mean = 1.79511e-269

Thanks

Hi,

Currently TF1::Mean (and TF1::Moment) can only be used if the TF1 is based solely on the string version of TFormula (i.e. not your case; you have a TF1 based on a C++ function). There is currently no work-around (you might be able to populate an histogram with your value and get the mean for it).

Cheers,
Philippe.

Thanks,

Regards,
Bair