Re: [ROOT] TMinuit

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Dec 12 2000 - 10:46:42 MET


Eiko, Cynthia,
You will find below a simple example using a profile histogram
as suggested by Petar. The example uses a straight line fit.
You can change it to any type of function according to the shape
of your 2-d distribution.

Rene Brun

void fit2d()
{
   //example illustrating how to fit a 2-d histogram of type y=f(x)
   
   const Int_t n = 6;
   Float_t x[n] = {0.092,0.83,0.94,0.81,0.12,0.1};
   Float_t y[n] = {0.71,9.4,9,8,0.3,0.71};
   TCutG *cut = new TCutG("cut",n,x,y);
   TH2F *h2 = new TH2F("h2","h2",40,0,1,40,0,10);
   Float_t u,v;
   for (Int_t i=0;i<100000;i++) {
      u = gRandom->Rndm();
      v = 10*gRandom->Rndm();
      if (cut->IsInside(u,v)) h2->Fill(u,v);
   }
   TCanvas *c1 = new TCanvas("c1","show profile",600,900);
   c1->Divide(1,2);
   c1->cd(1);
   h2->Draw();
   c1->cd(2);
   TProfile *prof = h2->ProfileX();
   prof->Fit("pol1");
}
   

Shin-Shan Yu wrote:
> 
> Hi! I want to use TMinuit and fit a 2D histogram. Say fit d0 = Acos(phi0)+
> Bsin(phi0), A and B are free parameters. Could you show me an example to
> do it? Thanks!
> 
>  -Eiko
> 
> ******************************************************************************
> Shin-Shan Yu
> Graduate Student, Dept. of Physics, University of Pennsylvania
> Office: B0 trailer 170 P
> Phone: (O) 630-840-3509
>        (H) 630-428-0230
> Home Page: http://newton.hep.upenn.edu/~eiko/my.html
> ******************************************************************************



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:39 MET