Error while calculating X or Y mean of a 2D probablity distribution (TF2)

ROOT Version: 5
Platform: Ubuntu

Hello. Yes, I am on ROOT 5 – because our teacher demands the older version… So I can’t update.
I’m trying to calculate mean of X of a TF2D function. Let’s say for x and y both in [0, 1].

double func(double *x, double *params) 
    return TMath::Sin(x[0] * x[1]);
TF2* funcTF2 = new TF2("funcTF2", func, 0, 1, 0, 1, 0);
double meanX = funcTF2->Mean2X(0, 1, 0, 1);

This throws an error:

Error in <TFormula::Compile>:  Empty String
Error in <TF2::TF2>: function: TF2_ExpValHelper/density_tf2*pow(x,1.000000)*pow(y,0.000000) has 0 parameters instead of 2


There is a limitation in the function computing the mean TF2::Mean2X. The function works only for formula (expression) based functions and not for compiled functions or functors are in your case.

I will open a JIRA issue for this to then able to fix it. The workaround, which I hope is not too much a limitation, is to define TF2 as following:

TF2* funcTF2 = new TF2("f", "TMath::Sin(x*y)", 0., 1., 0., 1.);


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