Hi,

Is there a simple public example of using complex numbers in ROOT? I am trying to fit a cross-section for two Breit-Wigner’s plus a constant term. I did the single Breit-Wigner using real numbers, and that works fine, but the code would be clearer using complex numbers. But, when I try to run it, ROOT goes into an infinite loop. This is ROOT 5.28 - old, but probably not ancient. I could update if that would help. The code follows; I have commented out the parts that pertain to the second Breit-Wigner, so it should be equivalent to the old version, which worked.

A pointer to any mistakes, and/or to a simple ROOT example using complex numbers would be appreciated. I searched the ROOT documentation, but the examples I found were pretty heavy-duty.

Thanks.

Spencer Klein, Berkeley

```
double fitf(Double_t *v, Double_t *par){
#include <TComplex.h>
/* This reads histograms from Bill's TTree and fits for a rho, direct pipi and eventually an omega signal.
April 9, 2015*/
// This is the fit function for the rho
// v[0] is the dipion mass
// par is the array containing the parameters being fitted
// par[0] is the rho mass
// par[1] is the rho width
// par[2] is 'A;
//par[3] is 'B;
// par[4] is the constant background
// par[5] is the linear (in mass)background
// par[6] is reserved for the omega
double mpipi=v[0];
double mass2=mpipi*mpipi;
double polybg=par[4]+par[5]*mpipi;
// To add the omega, switch to complex numbers
double rhomass=par[0];
double rhomass2=rhomass*rhomass;
double rhowidth=par[1];
double pionmass=0.13957;
double pionmass2=pionmass*pionmass;
// rho mass-dependent width
double val=pow((mass2-4*pionmass2)/(rhomass2-4*pionmass2),1.5);
double mdwidth=rhowidth*(rhomass/mpipi)*val; // mass dependent width
// now omega, with mass-dependent width
// This is probably too narrow, since it neglects detector broadening
double omegamass=0.7872;
double omegamass2=omegamass*omegamass;
double omegawidth=0.085;
double omegaval= val=pow((mass2-4*pionmass2)/(omegamass2-4*pionmass2),1.5);
double omegamdwidth=omegawidth*(omegamass/mpipi)*val;
// try it with complex numbers
std::complex<double> ix=(0,1);
std::complex<double> denom=(mass2-rhomass2)+ix*rhomass*mdwidth;
std::complex<double> aterm=par[2]*sqrt(mpipi*rhomass*mdwidth)/denom;
std::complex<double> bterm=par[3];
// std::complex<double> omegadenom=(mass2-omegamass2)+ix*omegamass*omegamdwidth;
std::complex<double>cterm=0.;
// std::complex<double> cterm=par[6]*sqrt(mpipi*omegamass*omegamdwidth)/omegadenom;
std::complex<double> total=aterm+bterm+cterm;
double amp=abs(total);
double fitval=amp+polybg;
return fitval;
}
```