ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fit2d.C
Go to the documentation of this file.
1 void fit2d()
2 {
3  //example illustrating how to fit a 2-d histogram of type y=f(x)
4  //Author: Rene Brun
5 
6  // generate a 2-d histogram using a TCutG
7  const Int_t n = 6;
8  Float_t x[n] = {0.092,0.83,0.94,0.81,0.12,0.1};
9  Float_t y[n] = {0.71,9.4,9,8,0.3,0.71};
10  TCutG *cut = new TCutG("cut",n,x,y);
11  TH2F *h2 = new TH2F("h2","h2",40,0,1,40,0,10);
12  Float_t u,v;
13  for (Int_t i=0;i<100000;i++) {
14  u = gRandom->Rndm();
15  v = 10*gRandom->Rndm();
16  if (cut->IsInside(u,v)) h2->Fill(u,v);
17  }
18  TCanvas *c1 = new TCanvas("c1","show profile",600,900);
19  c1->Divide(1,2);
20  c1->cd(1);
21  h2->Draw();
22  c1->cd(2);
23 
24  //use a TProfile to convert the 2-d to 1-d problem
25  TProfile *prof = h2->ProfileX();
26  prof->Fit("pol1");
27 }
28 
float Float_t
Definition: RtypesCore.h:53
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
TCanvas * c1
Definition: legend1.C:2
virtual Int_t IsInside(Double_t x, Double_t y) const
Return 1 if the point (x,y) is inside the polygon defined by the graph vertices 0 otherwise...
Definition: TGraph.cxx:1771
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
int Int_t
Definition: RtypesCore.h:41
Profile Historam.
Definition: TProfile.h:34
Graphical cut class.
Definition: TCutG.h:29
Double_t x[n]
Definition: legend1.C:17
TH2D * h2
Definition: fit2dHist.C:45
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
SVector< double, 2 > v
Definition: Dict.h:5
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
TProfile * ProfileX(const char *name="_pfx", Int_t firstybin=1, Int_t lastybin=-1, Option_t *option="") const
Project a 2-D histogram into a profile histogram along X.
Definition: TH2.cxx:2200
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
void fit2d()
Definition: fit2d.C:1
The Canvas class.
Definition: TCanvas.h:48
Double_t y[n]
Definition: legend1.C:17
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:287
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition: TH1.cxx:3607
const Int_t n
Definition: legend1.C:16