Funny thing with fit ranges?

Dear All,

I’m fitting a linear function to some data that I took and I found a strange thing when I want to fit a certain range only.

The code that I use is written below:

// Fit function to obtaing the threshold in Vcth for a given signal
TF1 *fitFcn=NULL;

double linearFunction(double *x, double *par){
  return par[0] + par[1]*x[0]; // y=b+ax
}//end double linear function

// Fit limets per measurement
Double_t lowerLimit[nMeasurements]={104, 106, 100, 108, 120, 104, 106, 100, 108, 120, 80}; // Vcth
Double_t upperLimit[nMeasurements]={110, 110, 110, 110, 100, 110, 110, 110, 110, 100, 72}; // Vcth

void initializeFit(unsigned int measurement){
  //fitFcn = new TF1("fitFcn", linearFunction, lowerLimit[measurement], upperLimit[measurement], 2);
  fitFcn = new TF1("fitFcn", linearFunction, 72, 80, 2);  
  fitFcn->SetNpx(100);
  fitFcn->SetLineWidth(3);
  fitFcn->SetLineColor(allColors[measurement]);
  fitFcn->SetParameters(1e-4, 1e-6);
}//end void initializeFit()

You will find that there is one line commented out

//fitFcn = new TF1("fitFcn", linearFunction, lowerLimit[measurement], upperLimit[measurement], 2);

When I use that line instead of this line:

//fitFcn = new TF1("fitFcn", linearFunction, 72, 80, 2);

the fit actually is performed over some random range. While if I put the number there explicitely the fit will be nicely performed within the limit that I specify. I checked and I do not access an element outside of the array, I use measurement=10 which is within the range of the array.

This is how I call the fit function:

  // Initialize the fit function and make the fit
  initializeFit(measurement);
  TFitResultPtr r = data->Fit("fitFcn","RS");

I was wondering, why does it not accept one of the values from the arrays with the upper and lower limits for the fit range?

Thanks a lot in advance,

Nikkie

For some “measurement” values, “xmin = lowerLimit[measurement] > upperLimit[measurement] = xmax”. This can create problems.

Hi Wile_E_Coyote,

Thanks a lot, that solved my issue. I should have spotted this.

Cheers,

Nikkie

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.