‘Functor1D’ is not a member of ‘ROOT::Math’

ROOT Version: 6.22/02
Platform: Ubuntu 20.04.1 LTS
Compiler: g++

What am I doing wrong actually? Is it something related to namespace or what? I have
just taken the code from the available user guide for ROOT and using a function and then
compiling it with g++ -o File test.cc `root-config --cflags --libs`. Here is the code :

#define EPS 1e-5
#include <iostream>
#include <cmath>
#include "Math/Integrator.h"
using namespace std;

const double R = 6.38;
const double a = 0.535;
const double w = 0.;

double Fermi(double* r){
  double rho = (1. + w*pow(r[0]/R, 2))/(1. + exp((r[0] - R)/a));
  return rho;
}

int test(){
  ROOT::Math::IntegratorOneDimOptions::SetDefaultAbsTolerance(EPS);
  ROOT::Math::IntegratorOneDimOptions::SetDefaultRelTolerance(EPS);

  ROOT::Math::Functor1D F(&Fermi);
  ROOT::Math::Integrator I(ROOT::Math::IntegrationOneDim::kADAPTIVESINGULAR);
  I.SetFunction(F);
  double t = I.Integral(0., 3*R);
  cout << t << endl;

  return 0;
}

Here is the error :

test.cc: In function ‘int test()’:
test.cc:20:15: error: ‘Functor1D’ is not a member of ‘ROOT::Math’
   20 |   ROOT::Math::Functor1D F(&Fermi);
      |               ^~~~~~~~~

You’d need to #include "Math/Functor.h" in order to make ROOT::Math::Functor1D available to the compiler. Note that in this case you also need a main function, something like

int main() {
  test();
}

You can run the macro unmodified interpreted with ROOT like

root test.cc

Note that you cannot use a function that takes a pointer to a double for Functor1D. The Fermi function can take just a double r though.

Yeah I had forgotten to replace the test() with main() :sweat_smile:. But inclusion of Functor.h makes the code work. Thanks for the help!