TF2 Parameters Leads to Seg Fault

When I call for a parameter in a function being integrated by TF2 I receive a segmentation fault.

#include <stdlib.h>
#include "TF2.h"

//Function Integrated Over
double func_sub(double *vals, double *par)
{
  std::cout << par[0] << std::endl; //This is where the Seg happens
  return cos(vals[0]*vals[1]);
}


//Function Setting up Integral  
void func()  
{
  TF2 * inter = new TF2("tester",func_sub,0,1,0,1);
  inter->SetParameter(0,1);

  std::cout << inter->Integral(0,1,0,1) << std::endl;
}

int main()
{
  func();
}

ROOT Version: 6.28.04
Platform: Windows but running through Umbuntu
Compiler: g++


Welcome to the ROOT forum.

You missed npar. You should do:

  TF2 * inter = new TF2("tester",func_sub,0,1,0,1,1);

Thank you. I really appreciate you taking the time.

1 Like