ROOT logo

From $ROOTSYS/tutorials/fit/fit2d.C

void fit2d()
{
   //example illustrating how to fit a 2-d histogram of type y=f(x)
   //Author: Rene Brun
   
   // generate a 2-d histogram using a TCutG
   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);
   
   //use a TProfile to convert the 2-d to 1-d problem
   TProfile *prof = h2->ProfileX();
   prof->Fit("pol1");
}
   
 fit2d.C:1
 fit2d.C:2
 fit2d.C:3
 fit2d.C:4
 fit2d.C:5
 fit2d.C:6
 fit2d.C:7
 fit2d.C:8
 fit2d.C:9
 fit2d.C:10
 fit2d.C:11
 fit2d.C:12
 fit2d.C:13
 fit2d.C:14
 fit2d.C:15
 fit2d.C:16
 fit2d.C:17
 fit2d.C:18
 fit2d.C:19
 fit2d.C:20
 fit2d.C:21
 fit2d.C:22
 fit2d.C:23
 fit2d.C:24
 fit2d.C:25
 fit2d.C:26
 fit2d.C:27
 fit2d.C:28
 fit2d.C:29