Error: operator '/' divided by zero

Hi guys,
I’ve been working on a fitting routine that’s just not going the way i would like it to! Below is a macro ( 1 file for script, 1 file for function definitions) that worked just fine, until i added the function ngaussian which defines ‘ng’ gaussian distributions, where ‘ng’ is set by the user running the script.

Here is fit.C


//Johnny Goett

int nb;
int ng;

void fitrout(TH1F *h , Double_t blo , Double_t bhi , Double_t glo , Double_t ghi, int ngauss = 1, int nback = 2)

nb = nback;
ng = ngauss;

//Define parameter array
Double_t par[50];

char bkgd[10];
cout << bkgd << endl;

//Define background function
TF1 *bkgrd = new TF1("bkgrd" , bkgd ,  blo , bhi );

//Define gaussian peak
TF1 *peak = new TF1("peak" , ngaussian ,  glo , ghi , 3*ng);

//Define gaussian + peak (functions.C must be loaded)
TF1 *sum = new TF1("sum" , fitfunc ,  blo , bhi , 3*ng+1+nb );

    //initialize widths
    for(int i=0; i < ng; i++)
      peak->SetParameter(2+3*i , 0.05);


//Get bkgrd and peak parameters

// for(int i = 0; i<50; i++)
//	cout << par[i] << " ";
// cout << endl;

//Use parameters as inital values for "sum"

//Fit with the sum function

//Integrate peak....
//sum->Integrate( glo , ghi );



Here is functions.C


extern int nb;
extern int ng;

//Quadratic Background
Double_t background(Double_t *x, Double_t *par) {
Double_t ret = 0.0;
for(int i=0; i <= nb; i++) {
return ret;
// return par[0] + par[1]*x[0] + par[2]*x[0]*x[0];

//Gaussian Peak
Double_t ngaussian(Double_t x, Double_t par) {
Double_t ret = 0.0;
for(int i=0; i < ng; i++) {
i]=0.0) par[2+3
return ret;
// return par[0]TMath::Exp(-0.5((x[0]-par[1])/par[2])*((x[0]-par[1])/par[2]));

//background + gausspeak -> fit function
Double_t fitfunc(Double_t *x, Double_t par) {
return background(x , &par[3
ng]) + ngaussian(x , &par[0]);

When i run the script I recieve the error:
Error: operator ‘/’ divided by zero FILE: LINE:17

This repeats indefinitely until i kill ROOT…Not exactly sure where this could be coming from though, as i’ve initialized the widths to .05. My guess that this error messages is not telling me what is really going on.

Thanks for any advice you might have.



I see at least one C++ issue:

if(par[2+3i]=0.0) par[2+3i]=1.0e-10;

which should read

if(par[2+3i]==0.0) par[2+3i]=1.0e-10;

Since a negative width is not allowed change it to

if(par[2+3i]<=0.0) par[2+3i]=1.0e-10;


ps. Ever considered the possiblity of overflow using exp(1.0e+10…)