[ROOT] Help needed : GetParameter(s) problems ...

From: Patrick Jarry (patrick.jarry@cern.ch)
Date: Tue Oct 30 2001 - 11:39:19 MET


Hi rooters ,

Thanks a lot for this very nice tool that I appreciate a lot but
I spend a lot of time sometimes to try to unserstand what is going
on (I am also a C++ beginner) , I would like to present you one of 
my problem today :
(I want to precise that I am used to fit histograms/profile with
user function and up to know never got any problems)

I get a profile on a root file that I read and store with the
following way :

>TH1D *h1=new TH1D( name, title, numbin,xmin,xmax);
>  for(int j=nmini;j<nmaxi;j++) h1->Fill( (Double_t)j*step+step/2., *(pf+j) );

This is fine , h1 is filled and OK.

Then I declare a user function :

>TF1 *funtofit= new TF1("lastShape",lastShape,xfitmin,xfitmax,4) ;
  
Which should be used to fit histogram h1 ...

I set the parameters after initialization :

>>  par[0] = 1.00 ;
>>  par[1] = 8.60 ;
>>  par[2] = 1.27 ;
>>  par[3] = 4.0  ;
>>  funtofit->SetParameters(par) ;
>>  funtofit->SetParNames("b1","b2","alpha","beta") ;

fine ...

But when I try :

>> h1->Fit("lastShape") ;

------>  I get a segmentation violation !.

The only way to go out from this is to set :

>> h1->Fit("lastShape","+WNR") ;

Then it works fine !!! ( my first question is why ? due to errors missing ?)

BUT in the following step , I want to read fitted parameters :


>> funtofit->GetParameters(par) ;
  
It works fine ( I get right values ) for the first call to the
function with the first histogram ... but then for the second
histogram fitted and all the others : the fitted parameters are
the same than before the fit ( the one from SetParameters) !!!
All the fits are correct ( converged and seen in the minuit output) but
there is a problem with the output of the fitted parameters ...

I tried the very well known way :

 >> TF1 *ffi=(TF1 *)h1->GetFunction("lastShape") ;
 >> Double_t chi2=ffi->GetChisquare();
 >> for(int ij=0;ij<4;ij++) {
 >> parout[0][ij]=ffi->GetParameter(ij) ;
 >> parout[1][ij]=ffi->GetParError(ij) ;	
>>}

But in this case I get a segmentation fault when I ask the
chisquare ... ( second line )

The only way to get the right parameters in an array every time
that I call the function with a different histogram is to do :

> delete funtofit

at the end of the routine ...

As you can imagine I am not really happy just because I don't understand
what is going on , my low level in C++ must be the main reason ...

any Idea about this feature ?

Thanks a lot by advance

Patrick







This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET