fit2d.C

Go to the documentation of this file.
00001 void fit2d()
00002 {
00003    //example illustrating how to fit a 2-d histogram of type y=f(x)
00004    //Author: Rene Brun
00005    
00006    // generate a 2-d histogram using a TCutG
00007    const Int_t n = 6;
00008    Float_t x[n] = {0.092,0.83,0.94,0.81,0.12,0.1};
00009    Float_t y[n] = {0.71,9.4,9,8,0.3,0.71};
00010    TCutG *cut = new TCutG("cut",n,x,y);
00011    TH2F *h2 = new TH2F("h2","h2",40,0,1,40,0,10);
00012    Float_t u,v;
00013    for (Int_t i=0;i<100000;i++) {
00014       u = gRandom->Rndm();
00015       v = 10*gRandom->Rndm();
00016       if (cut->IsInside(u,v)) h2->Fill(u,v);
00017    }
00018    TCanvas *c1 = new TCanvas("c1","show profile",600,900);
00019    c1->Divide(1,2);
00020    c1->cd(1);
00021    h2->Draw();
00022    c1->cd(2);
00023    
00024    //use a TProfile to convert the 2-d to 1-d problem
00025    TProfile *prof = h2->ProfileX();
00026    prof->Fit("pol1");
00027 }
00028    

Generated on Tue Jul 5 15:44:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1