Several different fits using TMinuit at the same time

Hi!

I have problem. I would like to use Minuit to fit the position of a detector. So I define a function to use with minuit ( void(…)) that returns the value I want to minimize. In this function I wouldl like to fit a gaussian peak with a background. I tried just using

TH1::Fit()

but this destroys my instance of Minuit!!! In short i did

void figureofmerit(Int_t &, Double_t *, Double_t &f, Double_t *x, Int_t iflag)

{
//Some things to read data
//Fills a histogram and fits a gaussion with background
h.Filll(e);
TF1 ff(“ff”,“pol1(0)+gaus(2)”);
ff.SetRange(1350,1450);
h.Fit(“ff”,“RNQ”);
//Calculates my figure of merit

f = exp((ff.GetParameter(3)-1400)*(ff.GetParameter(3)-1400))*fabs(f.GetParameter(4));
}

int main()
{
TVirtualFitter minuit = TVirtualFitter::Fitter(0, 6);
minuit->SetFCN(figureofmerit);
minuit->SetParameter(0,"Psi(Rz) ",-30
deg, 0.1deg, 0.,0.);
minuit->SetParameter(1,“Theta(Ry)”, 92
deg, 0.1deg, 0.,0.);
minuit->SetParameter(2,"Phi(Rz) ", 90
deg, 0.1*deg, 0.,0.);
minuit->SetParameter(3,"dx ", 0, 0.1, 0.,0.);
minuit->SetParameter(4,"dy ", 102, 0.1, 0.,0.);
minuit->SetParameter(5,"dz ", -7.5, 0.1, 0.,0.);

  Double_t arglist[100];
  arglist[0] = 1;
  minuit->ExecuteCommand("CALL FCN", arglist, 1);
  arglist[0] = 0;
  minuit->ExecuteCommand("SET PRINT", arglist, 1);
  minuit->ExecuteCommand("MIGRAD", arglist, 0);
  minuit->ExecuteCommand("MINOS", arglist, 0);
  arglist[0] = 3;
  minuit->ExecuteCommand("CALL FCN", arglist, 1);

}

and this does not work…

cheers

Joa

Hi,

you should directly the TFitter class. The line:

TVirtualFitter *minuit = TVirtualFitter::Fitter(0, 6);

returns the current fitter (which is a static variable).

Do instead:

TFitter * minuit = new TFitter(6);

this creates a new fitter instance.

Cheers

Lorenzo