Problem: TF1 with 21 parameters

Hi,

I found some problems using TF1 function:

I am trying to do something similar to root.cern.ch/root/html/TF1.html “C - A general C function with parameters”

// Macro func.C

double yrapidity(double *x, double *par) {

  if(par[0]<0.)return 0;
  
  int xv = static_cast<int>(100*(x[0]));
  int xb = static_cast<int>(xv/10);
  
  if (xb>48) return 0;
  
  double c = 1.;
  
  double del0  = (eigen[xb])/c;
  double del1  = (eigen[xb])/c;
  double del2  = (eigen[xb])/c;
  double del3  = (eigen[xb])/c;
  double del4  = (eigen[xb])/c;
  double del5  = (eigen[xb])/c;
  double del6  = (eigen[xb])/c;
  double del7  = (eigen[xb])/c;
  double del8  = (eigen[xb])/c;
  double del9  = (eigen[xb])/c;
  double del10 = (eigen[xb])/c;
  double del11 = (eigen[xb])/c;
  double del12 = (eigen[xb])/c;
  double del13 = (eigen[xb])/c;
  double del14 = (eigen[xb])/c;
  double del15 = (eigen[xb])/c; 
  double del16 = (eigen[xb])/c;
  double del17 = (eigen[xb])/c;
  double del18 = (eigen[xb])/c;
  double del19 = (eigen[xb])/c;


  double f=(par[0]*(eigen[xb]+
  		par[1]*del0+
  		par[2]*del1+
  		par[3]*del2+
  		par[4]*del3+
  		par[5]*del4+
  		par[6]*del5+
  		par[7]*del6+
  		par[8]*del7+
  		par[9]*del8+
  		par[10]*del9+
  		par[11]*del10+
  		par[12]*del11+
   		par[13]*del12+
  		par[14]*del13+
  		par[15]*del14+
    		par[16]*del15+
  		par[17]*del16+
  		par[18]*del17+
  		par[19]*del18+
		par[20]*del19));
 
 return f;

} 

double eigen[50];

////////////////////////////////////////
/// main function  
////////////////////////////////////////
int run(){

  int Np=21;
  double lumi=1;
  
  for(int y=0; y<49; y++){
   
    eigen[y]=1.5;
   
  }

  TF1 *fitfunction = new TF1("fitfunction",yrapidity,1.9,4.7,Np);
  TF1 *f1=gROOT->GetFunction("fitfunction");  

  for(int npar=1; npar<Np;npar++){    
    f1->SetParameter(npar,0.);       
  }
  
  //  lumi=0.;
  
  f1->SetParameter(0,lumi);
  f1->Draw();
  
}

and I run with:
Root > .L func.C
Root > run();

I have a “tabulated” function, I simplified setting the value of the vector eigen[] to a constant

The problem is
When the number of parameter Np is 19 I can plot and use f1 in a fit and everything works
but when Np>19 it seems that I can’t manage the parameters and the function and SetParameter method is not working;
for example, if all the parameters (and lumi) are set to zero the function should be flat but the plot isn’t.
or if lumi is 1 i should get a constant = 1.5

p.s.
when I say Np=19 or Np>19 I changed the implementation of "double yrapidity(double *x, double *par)"
using the correct number of parameters as well.

any suggestion?

cheers,
Francesco

I cannot reproduce this problem. Which version/platform are you using?
If using an old version, could you try with 5.21/04?

Rene

I am using
Version 5.12/00e
on ubuntu

I am checking with a new one
Francesco

Hi

it works with Version 5.18/00 on Ubuntu

Francesco