Re: [ROOT] Fitting problems

From: Emily Nurse (emily@hep.man.ac.uk)
Date: Sat Apr 20 2002 - 02:17:22 MEST


Hi Rene,
Here is the code I use to get a function from the histogram in fit.root
(attached file):


Double_t norm2 ( Double_t *x2, Double_t *par2)
            {
	    Double_t xx2=x2[0];
            Int_t bin2 = w_pte2->GetXaxis()->FindBin(xx2);
            return par2[0]*(w_pte2->GetBinContent(bin2));

	    }
This is written in my macro. Then in the command line I type:

TF1 *f2 = new TF1("norm2",norm2,0.,200.,1)
f2->SetParameter(0,1)

and I fit f2 to a TGraphErrors, wt2, which is defined in a macro :
TGraphErrors *wt2=new TGraphErrors(n,x,y,dx,dy)

using:

 wt2.Fit("norm2")

If I get the integral of f2 before and after the fit and then multiply the
y and dy entries in wt2 by the correct ratio and then do:

 wt2.Fit("norm2,"w")

I get an extremely high chisquare.

If, instead, I get the ratios then scale w_pte2 before doing the fit (with
weights=1) I get a smaller chisquare, but still larger than the original
one. I have called Sumw2() on w_pte2 now and this makes no difference.

Cheers,
 Emily.

On Fri, 19 Apr 2002, Rene Brun wrote:

> Emily,
>
> It looks like your histogram bin errors are not defined
> correctly.
> By default (if TH1::Sumw2 was not called before filling),
> the bin error will be the sqrt(bin content).
> In case you have filled your histograms with weights
> or have made an operation (add,multiply,divide,scale)
> and you did not call TH1::Sumw2, your errors are
> meaningless. The fit parameters may be OK, but
> certainly not the chisquare and the errors on the
> parameters.
> So, check this point first. If you do not find a solution,
> send me a Root file containing the histogram you want
> to fit together with a small script containing
> your fitting function and the calls to TH1::Fit
>
> Rene Brun
>
> On Fri, 19 Apr 2002, Emily Nurse wrote:
>
> > Hi Rene,
> >
> > I am fitting a user defined function (just the bin content from a
> > histogramme as a function of x-axis) to data points. I want to do it
> > without changing the normalisation scale how-ever when I use the option
> > "w" my chisquared value is too large. I have checked by getting the
> > integral of my function before and after fitting without the "w" option so
> > as to get the normalisation constant. I then weight my function by the
> > ratio of these integrals and then make a fit with the "w" option. My
> > chisquared value is nearly a factor 10 higher when really it should be the
> > same. Can you explain?
> > Cheers,
> > Emily.
> >
> >
> > On Fri, 15 Mar 2002, Rene Brun wrote:
> >
> > > Hi Emily,
> > >
> > >
> > >
> > > On Thu, 14 Mar 2002, Emily Nurse wrote:
> > >
> > > > Hello,
> > > > I have a couple of questions involving the Fit function.
> > > > Firstly when I use it it normalises my user defined function for me to
> > > > give the loest possible chisquared value when fitted to my data points. I
> > > > was wandering if I could switch this action off and just get a straight
> > > > forward chisquared value as I will be fitting different ranges seperately
> > > > that need to be normalised by the same amount even though this may not
> > > > give the lowest chi-squared value.
> > >
> > > If you use the fit option "w" (all weights equal to 1), you should obtain
> > > what you want.
> > >
> > > >
> > > Secondly I am getting an error message when I run my macro which includes
> > > > the function:
> > > >
> > > >  Double_t norm ( Double_t *x, Double_t *par)
> > > >             {
> > > > 	    Double_t xx=x[0];
> > > >             Int_t bin = w_pte1->GetXaxis()->FindBin(xx);
> > > >             return par[0]*(w_pte1->GetBinContent(bin));
> > > >             }
> > > >
> > > > (where w_pte1 is a TH1D object). Then at the root prompt I type:
> > >
> > > But where do you define it ?
> > > If the code above is in a macro, declare your TH1D object as global.
> > >
> > > Rene Brun
> > >
> > > >
> > > > root [3] TF1 *f1 = new TF1("norm",norm,0.,50.,1)
> > > > root [5] f1->SetParameter(0,1)
> > > > root [6] f1->Draw()
> > > > <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
> > > > Error: non class,struct,union object $w_pte1 used with . or ->Error: non
> > > > class,struct,union object $w_pte1 used with . or ->Error: non
> > > > class,struct,union object $w_pte1 used with . or ->root [7]
> > > >
> > > > Things do seem to work but I was wandering what I was doing wrong,
> > > > thanks for your help,
> > > > Emily.
> > > >
> > >
> >
>





This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:50 MET