Re: [ROOT] GetParameter difficulty

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 29 2001 - 08:20:15 MET


Hi Mike,

In interpreted or compiled code, do:

  TF1 *gaus = hadcGCs[k]->GetFunction("gaus");
  Double_t peakGCs = gaus->GetParameter(1); etc

TF1::GetFunction will return to you the pointer to a copy of the function
used for the fit with its parameters. This is the recommended way.
Because the same prototype function may be used to fit more than one histogram,
you should access the copy and not the original prototype.
In case your function is used to fit only one histogram or if you access
the fit parameters immediatly after the fit, you can also use the original
prototype.

Rene Brun

Mike R wrote:
> 
> Hello,
> 
>   I'm am having trouble accessing fit parameters.  I'm fairly new to
> ROOT and C++ so the answer may be simple.  I'm running on Red Hat
> 7.0 or 7.1 and am using ROOT 3.01.  I can fit my histograms to a
> Gaussian with no problems from the command prompt or with
> a ROOT macro using the predefined function 'gaus'  However, for the
> application I'm working on now, I need to do it from compiled C++ code.
> 
>   I do get this warning when compiling, but it does compile:
> 
>         "`TF1 *gaus' might be used uninitialized in this function"
> 
> I don't know what to do to get rid of this.  I don't know if it is related
> to the problem I'll explain below...
> 
>   I am able to Draw the histogram.  I am able to fit the histogram to a
> Gaussian (hadcGCs[k]->Fit("gaus","","",lowGCs[k],highGCs[k])), and the
> numbers are reasonable:
> 
>   "FCN=301.889 FROM MIGRAD STATUS=CONVERGED  88 CALLS   89 TOTAL
>               EDM=4.31488e-09    STRATEGY= 1    ERROR MATRIX ACCURATE
>   EXT PARAMETER                             STEP        FIRST
>   NO.  NAME       VALUE        ERROR        SIZE      DERIVATIVE
>    1  Constant 2.89594e+02  9.22416e+00  5.06654e-02 -1.18601e-05
>    2  Mean     1.30441e+02  6.90035e-01  5.85323e-03 -5.57058e-05
>    3  Sigma    3.27019e+01  8.30520e-01  3.43433e-05 -5.39811e-03 "
> 
> I update the canvas and see a good Gaussian fit, so I know the fit
> is being done correctly.  ...BUT... when I try the following lines,
> which work fine in my macro, I get a segmentation violation (core
> dumped) error:
> 
>         "Double_t peakGCs = gaus->GetParameter(1);
>          Double_t sigmaGCs = gaus->GetParameter(2);"
> 
>   I need to use these numbers for further plots and calculations.  I
> searched your archived roottalk correspondence and found a couple
> somewhat similar problems, but none of the suggested fixes corrected my
> problem.  (e.g. adding the option 'N' in the Fit did not change anything.)
> I tried using the GetParameters(par) approach from the FittingDemo example
> in the ROOT manual but it gave a segmentation violation as well.
> 
>                                                 Thanks,
>                                                 Mike



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