Arrays of fit functions - SetFunction question

Hi,

I have a series of around 12 histograms (TH1F) of angular distributions for a particular process, each for a different mass range. I have created a TF1 for each one - each of these contains the same function. I then fit the TF1’s to the TH1F’s.

This works fine, but is a little unwieldy if I want to change things (such as the mass ranges, number of parameters). I was wondering if there was some way to set up the fit functions (and histograms) as an array which I could then loop through. I have tried the following bit of code:


TF1 fitFcn[18];
for(int i=0;i<18;i++){
fitFcn[i]->SetNpx(500);
fitFcn[i]->SetLineWidth(1);
fitFcn[i]->SetLineColor(kBlue);
fitFcn[i]->SetRange(x_min,x_max);
fitFcn[i]->SetNDF(2);
fitFcn[i]->SetFunction(minimal_fit(fit_vars[i][2],fit_vars[i][]));
}

where:
Double_t minimal_fit(Double_t *x, Double_t *par){
return(par[0]+par[1]*x[0]*x[0]+par[2]*x[0]*x[0]*x[0]*x[0]);
}

I get an error when if gets to the last bit of the loop (the SetFunction call); I am fairly certain that I am calling this in the wrong way, and am not sure if this is even the correct method to call for what I want. I want to set the function that it will do the fit with - is this SetFunction, or is it something else? Is what I am trying to do actually possible?

Many thanks for any help you can give - I am running ROOT v4.04/02f on SL4.

Tim

Your call to SetFunction is wrong. I suggest to modify your code as follows:

TF1 *fitFcn[18]; for(int i=0;i<18;i++){ fitfcn[i] = new TF1(Form("fitfcn_%d",i),minimal_fit,x_min,x_max); fitFcn[i]->SetNpx(500); fitFcn[i]->SetLineWidth(1); fitFcn[i]->SetLineColor(kBlue); fitfcn[i]->SetParameters(array of parameters) }
see example in tutorial FittingDemo.C

Rene