Re: how to fit a histogram with fixed parameters

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 20 Jun 2006 12:21:58 +0200


see your code modified below with some comments

Rene Brun

{
  h=new TH1F("h","",100,0,1);
  for(int i=0;i<10000;i++){
    Double_t x1=gRandom->Gaus(0.3,0.05);     h->Fill(x1);
  }
  h->Draw();

  //fixed parameters cannot be used with teh built-in functions gaus,expo,pol
  //TF1 *f=new TF1("f","gaus",0,1);
  TF1 *f=new TF1("f","[0]*TMath::Gaus(x,[1],[2])",0,1);

  f->SetParameters(1,0.3,1);
  f->FixParameter(1,0.3);
  h->Fit(f);

}

Xianguo (Hsien-Kuo) LU wrote:
> Hi Rene,
>
> Here is the code:
>
>
> test()
> {
> h=new TH1F("h","",100,0,1);
> for(int i=0;i<10000;i++){
> Double_t x1=gRandom->Gaus(0.3,0.05);
> h->Fill(x1);
> }
> h->Draw();
>
> TF1 *f=new TF1("f","gaus",0,1);
> //f->FixParameter(1,0.3);
> f->SetParLimits(1,0.3,0.3);
> h->Fit(f);
> }
>
>
>
> When FixParameter is used, the result is:
> FCN=32.5374 FROM MIGRAD STATUS=CONVERGED 37 CALLS
> 38 TOTAL
> EDM=1.80376e-09 STRATEGY= 1 ERROR MATRIX
> ACCURATE
> EXT PARAMETER STEP FIRST
> NO. NAME VALUE ERROR SIZE DERIVATIVE
> 1 Constant 8.10627e+02 1.00062e+01 2.29596e-02 -6.79730e-06
> 2 Mean 3.00915e-01 fixed
> 3 Sigma 4.90648e-02 3.54994e-04 5.52081e-06 -2.63700e-02
>
> And about the SetParLimits:
> FCN=38.4282 FROM MIGRAD STATUS=CONVERGED 37 CALLS
> 38 TOTAL
> EDM=2.83056e-07 STRATEGY= 1 ERROR MATRIX
> ACCURATE
> EXT PARAMETER STEP FIRST
> NO. NAME VALUE ERROR SIZE DERIVATIVE
> 1 Constant 8.00170e+02 9.92677e+00 2.45814e-02 -8.89375e-05
> 2 Mean 2.99435e-01 fixed
> 3 Sigma 4.96739e-02 3.64274e-04 6.04274e-06 -3.11864e-01
>
> In both cases, you can see the value of Mean is changed.
> How can I really fix it?
> I am using 5.10/00.
>
> Thanks!
> Cheers!
> Xianguo
>
>
>
> On 6/12/06, *Rene Brun* <Rene.Brun_at_cern.ch <mailto:Rene.Brun_at_cern.ch>>
> wrote:
>
> Could yous end the SHORTEST POSSIBLE RUNNING script reproducing
> the problem?
>
> Rene Brun
>
> Xianguo (Hsien-Kuo) LU wrote:
> > Hi, rooters!
> >
> > I want to fit a histogram with fixed parameters.
> > I did the following:
> >
> > f=new TF1("f","gaus",0,1);
> >
> > f->SetParLimits(1,1.1156 ,1.1156)
> > or
> > f->FixParameter(1,1.1156)
> >
> > but after fitting, the parameter changed.
> > Can somebody tell me why and how to solve it?
> >
> > Thanks in advance!
> >
> > Cheers!
> > Xianguo LU
> >
> >
> >
> > --
> > Take flight into the sky, beyond the moon, beyond my mind.
> >
> > Xianguo LU (Hsien-Kuo LU)
> > Physics Department, Peking University
> > Beijing, China
> > Tel: 0086-10-62753888(o)
>
>
>
>
> --
> Take flight into the sky, beyond the moon, beyond my mind.
>
> Xianguo LU
> Physics Department, Peking University
> Beijing, China
> Tel: 0086-10-62753888(o)
Received on Tue Jun 20 2006 - 12:22:04 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET