Re: Gaussian Fit on TH2F

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Tue, 2 Nov 2010 11:48:51 +0100


Hi,

 If you have multiple peaks, your fitting result will depend very heavily on your initial parameters. If they are not close enough to the final solution you will end up in local minima (i.e. only one peak found).
A possible solution is to use the TSpectrum2 class to find the peaks and their positions. As Rene already mentioned, see the example in $ROOTSYS/tutorials/spectrum/peaks2.C

 Best Regards

 Lorenzo

On Nov1, 2010, at 9:01 AM, <nguler_at_jlab.org> <nguler_at_jlab.org> wrote:

> Hello,
> I am using root version 5.26. My problem is not exactly root problem but a
> generic fitting problem on 2D histograms. I am sorry if it is inappropriate to
> ask about here. I am trying to make a Gaussian fit on many different 2D
> histograms with two prominent peaks on each but moving around from histogram
> to histogram. Later, I will also try other histograms with multiple peaks. I
> am using a fit function like:
> double g2(double *x, double *par)
> {
> double r1 = double((x[0]-par[1])/par[2]);
> double r2 = double((x[1]-par[3])/par[4]);
> return par[0]*TMath::Exp(-0.5*(r1*r1+r2*r2));
> }
> Also tried combination fit like:
> double fun2(double *x, double *par)
> {
> double *p1 = &par[0];
> double *p2 = &par[5];
> double result = g2(x,p1) + g2(x,p2);
> return result;
> }
> But in both cases, the fit result is hugely dependent on the the initial
> parameters and often fails for many of the histograms since the peaks are
> moving around. Only way I could think is to find peak locations in each
> histogram and supply initial parameters based on those. I would like to ask
> your opinions if this is worth trying or are there better ways.
> Thanks, - Nevzat Guler
>
>
Received on Tue Nov 02 2010 - 11:48:58 CET

This archive was generated by hypermail 2.2.0 : Tue Nov 02 2010 - 23:50:01 CET