Multi-dimensional fitting using TVirtualFitter

Hi,

I’am trying to fit a histogram using TVirtualFitter in 5 dimensions I have tried to follow an example written by Rene but with little success , it appears that the only major difference is instead of using the bin center to determine the bin expectation for the chi^2 I have integrated over the bin

there seems to be an error concerning the implementation of the fitter specifically I get the following error:

parameter_Fit.C:189: error: call of overloaded `SetFCN(void (&)(THnSparseD*, Double_t&, Double_t*))

I also get the following errors which are not clear to me:

parameter_Fit.C:456: error: invalid operands of types double' andDouble_t*’ to binary operator*' parameter_Fit.C:468: error: invalid operands of typesDouble_t*’ and Double_t' to binaryoperator*’

I have attached my code if you could please have a look

thank you very much

Maki
parameter_Fitting.C (11.4 KB)

Hi,

when using the TVirualFitter class your objective function (to be minimized) must be a global function of type

void  FCN( Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag) { 
......
}

This is the signature accepted by TVirtualFitter::SetFCN.
See various examples, like tutorials/fit/line3Dfit.C

Regards

Lorenzo

P.S. Your attached example is not completed (the header file is missing) and the error are you showing are not referring exactly to that file.

Hi Lorenzo, thanks a lot for your help

I made the correction you mentioned and all the errors relating to the header file have gone, but the THnSparse histogram does not seem to be passed properly to my function stats(…), with the following error:

Error: non class,struct,union object $fSparse used with . or ->Error: Symbol fSparse is not defined in current scope parameter_Fit.C:248:

thanks
Maki

ps i have attached my updated file
parameter_Fit.C (14.7 KB)

Hi,

fSparse is not defined in the scope of your stats() objective function.
You can defined as a global variable of your program or you can set the pointer in the TVirtualFitter using TVirtualFitter::SetObjectFit and TVirtualFitter::GetObjectFit.
Before fitting (calling Migrad) you should do:

minuit->SetObjectFit(fSparse);

and inside your stats() function do:

THnSparseD* fSparse = ( THnSparseD*) (TVirtualFitter::GetFitter())->GetObjectFit(); 

Regards,
Lorenzo

Thanks so much it seems to be working now
but it does not fit the parameters, I had a look at the original code written by
Rene Brun but that also seems to not fit the parameters, why is this?
I have attached this example

thanks again

Maki
sparsefit.C (2.52 KB)