Trying to define imaginary error function

I need to use the imaginary error function to fit some data. ROOT does not have a predefined erfi(), so I tried using the definition
erfi(z) = -i * erf(i*z)
I found an error function in RooMath that will take complex z, but it uses the std::complex class. I’m using TF1 to define this function, but it will not take the std::complex variable, instead it will only use the TComplex version of i. RooMath won’t take TComplex so I can’t get the erfi() to work. Is there a way to implement this?

`std::complex j = 1i;
TF1 *erfi = new TF1(“erfi”,"-[0]*RooMath::erf([0]*x)",0,10);

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

@moneta can help you.

You should be able to use std::complex inside the TFormula string , but then the expression should evaluate to a real number, otherwise you can construct a TF1. You can use either the imaginary part, the real , the module or the phase, depending on your problem, or you need to define two different TF1 classes, (actually TF2) for one of the case. Example:

typedef std::complex<double> complex_t;
TF2 * erfReal = new TF2("erfR", "RooMath::erf(complex_t(x,y)).real()",0,10,0,10);
TF2 * erfImag = new TF2("erfI", "RooMath::erf(complex_t(x,y)).imag()",0,10,0,10);


I tried using the TF2 functions you provided, but it’s now giving me this error:

I also tried passing in a std::complex variable through the FixParameter and got this error:


I’m somewhat intrigued by your problem as there are no complex observables… what are you actually fitting?



I’m just fitting some data that has to do with the momentum of kaons coming out of particle collisions. Part of the fit I’m doing requires an imaginary error function erfi(). I know erfi(x) is real if x is real, but ROOT doesn’t have a built in erfi(), so I’m trying to construct it from the regular error function and running into some problems.

You should be able to get the Dawson function from GSL (which can then be used to calculate erfi).

root [0] #include "gsl/gsl_sf.h"
root [1] std::cout << gsl_sf_dawson(1.) << std::endl;

I think this worked! Thank you so much!!

The template signature is not supported for the TFormula expression, for this you need to define before a typedef (such as complex_t) to use inside TFormula.
Then the TF1 parameters needs to be real numbers not complex ones. You would need to define two parameters to describe a complex one.