TVirtualFitter usage

Hi,

I was wondering how one is supposed to get out the Chi2 of a fit from the TVirtualFitter class ?
Is there a doc somewhere how to do fit using only that interface ?

Thanks,

Maybe this help:

{
  TH1F *h1 = new TH1F("h1","",100,-10,10);
  gStyle->SetOptFit(1111);
  h1->FillRandom("gaus");
  h1->Fit("gaus");
  
  TVirtualFitter *fitter = TVirtualFitter::GetFitter();
  Printf("chi2 = %g", ((TF1*)fitter->GetUserFunc())->GetChisquare() );
}

and see also minuit2*.C in tutorials.

Jan

Hum, not so sure.

I’m using the TVirtualFitter from a class, giving it a custom function to fit, and I already use the UserFunc to pass out information to the FCN (which cannot be a member function), so I doubt this will work for me.

Regards,

Laurent,

Could you explain why the solution indicated by Jan would not wprk for you.
I am afraid that you have to give more info on your setup.

Rene

Hi Rene,

You’re right. Here are some more details. The point is that I use Set/GetUserFunc already to pass objects to my FCN, so that UserFunc is not of type TF1 at all. Maybe what I do is just plain wrong ? (which is why I asked for a doc :wink: )

[code]MyClass::Fit()
{
TVirtualFitter* fitter = TVirtualFitter::Fitter(0,2);
fitter->SetFCN(FitFunction);

Double_t arg(-1);

fitter->ExecuteCommand(“SET PRINT”,&arg,1); // disable printout

fitter->SetParameter(0,“cluster X position”,xCOG,stepX,0,0);
fitter->SetParameter(1,“cluster Y position”,yCOG,stepY,0,0);

TObjArray userObjects;

userObjects.Add(&cluster);
userObjects.Add(fMathieson); // both objects here are instance variables

// I use the SetUserFunc to pass things to the FitFunction
fitter->SetUserFunc(&userObjects);

fitter->ExecuteCommand(“MIGRAD”,0,0);

Double_t results[] = { fitter->GetParameter(0),
fitter->GetParameter(1) };

Double_t errors[] = { fitter->GetParError(0),
fitter->GetParError(1) };

/// etc…
}
[/code]
where the FitFunction then uses the GetUserFunc to get back the stuff I pass to it :

[code]void
FitFunction(Int_t&, Double_t*, Double_t& f, Double_t* par, Int_t = 3)
{
TObjArray* userObjects = static_cast(TVirtualFitter::GetFitter()->GetUserFunc());

AliMUONCluster* cluster = static_cast(userObjects->At(0));
AliMUONMathieson* mathieson = static_cast(userObjects->At(1));
// compute f here, using information from cluster and mathieson objects
}
[/code]