Hi Frank,
Yes, you can do that. See an example in the tutorial "multifit.C".
This example shoes how to fit the sum of 3 gaussians. Just replace
one gaus by expo.
> 2) Is there a fit option which actually does not
> fit anything but takes the parameter's starting
> values, computes the fcn and plots the result?
> This would be helpfull whan trying to find
> good starting values for the parameters.
>
Yes, also possible. Create your TF1 object, set the parameter names
and initial values, then add the TF1 object to the list of functions
of your histogram object. Example
TH1F *h1; your histogram
TF1 *f1; your function
do
h1->GetListOfFunctions()->Add(f1);
now you can do h1->Draw(); this will also show the TF1.
Note that with this technique you can add as many functions as you like
to the list of functions. The list of functions follow the histogram
history. You can archive the histogram. When you read the histogram
again, it will have its list of functions.
> Now the Problem:
> When fitting the histogram with
> > TF1 *f1 = new
> >TF1("f1","[0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2]))+[3]*exp(x/[4])",70.,160.);
> > f1->SetParName(0,"gau amplitude");
> > f1->SetParName(1,"gau mean");
> > f1->SetParName(2,"gau sigma");
> > f1->SetParName(3,"exp ampl");
> > f1->SetParName(4,"exp tau");
> > f1->SetParameter(0,3960.); //initialize first parameter to 1.1
> > f1->SetParameter(1,135.);
> > f1->SetParameter(2,10.);
> > f1->SetParameter(3,330000.1);
> > f1->SetParameter(4,-20.);
> > f1->SetParLimits(0,3999.,4001.);
> > f1->SetParLimits(1,134.,136.);
> > f1->SetParLimits(2,14.,16.);
> > f1->SetParLimits(3,330000.0,330000.2);
> > f1->SetParLimits(4,-19.,-21.);
> > medusa_histo[2][2][0]->Fit("f1","RB");
>
> I always get (independent whether I use option B or not)
> a segmentation violation:
> > FCN=33185.7 FROM MIGRAD STATUS=CONVERGED 125 CALLS 126
> >TOTAL
> > EDM=4.4665e-05 STRATEGY= 1 ERROR MATRIX
> >UNCERTAINTY 0.0 per cent
> > EXT PARAMETER STEP FIRST
> > NO. NAME VALUE ERROR SIZE DERIVATIVE
> > 1 gau amplitude 3.99900e+03 4.43637e-02 1.30790e-03
> >1.75475e-02
> > 2 gau mean 1.34000e+02 3.46184e-04 -4.04984e-03** at limit **
> > 3 gau sigma 1.40000e+01 1.03863e-04 1.09873e-04** at limit **
> > 4 exp ampl 3.30000e+05 1.59870e-01 -4.82326e-03 3.26473e-03
> > 5 exp tau -1.90000e+01 fixed
> >
> > *** Break *** segmentation violation
> >
> Is there something obviously wrong? Is the function (or fcn)
> computed in a wider range than specified in TF1,
> that could explain the behavior.
>
You should protect your function aginst overflows/undeflows.
The protection is already included in the standard functions gaus
and expo.
If this is not the cause of your problem, please send me your root
file containing the histogram you want to fit.
Rene Brun