ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
quantiles.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// Demo for quantiles
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \authors Rene Brun, Eddy Offermann
9 
10 void quantiles() {
11  const Int_t nq = 100;
12  const Int_t nshots = 10;
13  Double_t xq[nq]; // position where to compute the quantiles in [0,1]
14  Double_t yq[nq]; // array to contain the quantiles
15  for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq;
16 
17  TGraph *gr70 = new TGraph(nshots);
18  TGraph *gr90 = new TGraph(nshots);
19  TGraph *gr98 = new TGraph(nshots);
20  TH1F *h = new TH1F("h","demo quantiles",50,-3,3);
21 
22  for (Int_t shot=0;shot<nshots;shot++) {
23  h->FillRandom("gaus",50);
24  h->GetQuantiles(nq,yq,xq);
25  gr70->SetPoint(shot,shot+1,yq[70]);
26  gr90->SetPoint(shot,shot+1,yq[90]);
27  gr98->SetPoint(shot,shot+1,yq[98]);
28  }
29 
30  //show the original histogram in the top pad
31  TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900);
32  c1->SetFillColor(41);
33  c1->Divide(1,3);
34  c1->cd(1);
35  h->SetFillColor(38);
36  h->Draw();
37 
38  // show the final quantiles in the middle pad
39  c1->cd(2);
40  gPad->SetFrameFillColor(33);
41  gPad->SetGrid();
42  TGraph *gr = new TGraph(nq,xq,yq);
43  gr->SetTitle("final quantiles");
44  gr->SetMarkerStyle(21);
45  gr->SetMarkerColor(kRed);
46  gr->SetMarkerSize(0.3);
47  gr->Draw("ap");
48 
49  // show the evolution of some quantiles in the bottom pad
50  c1->cd(3);
51  gPad->SetFrameFillColor(17);
52  gPad->DrawFrame(0,0,nshots+1,3.2);
53  gPad->SetGrid();
54  gr98->SetMarkerStyle(22);
55  gr98->SetMarkerColor(kRed);
56  gr98->Draw("lp");
57  gr90->SetMarkerStyle(21);
58  gr90->SetMarkerColor(kBlue);
59  gr90->Draw("lp");
60  gr70->SetMarkerStyle(20);
61  gr70->SetMarkerColor(kMagenta);
62  gr70->Draw("lp");
63  // add a legend
64  TLegend *legend = new TLegend(0.85,0.74,0.95,0.95);
65  legend->SetTextFont(72);
66  legend->SetTextSize(0.05);
67  legend->AddEntry(gr98," q98","lp");
68  legend->AddEntry(gr90," q90","lp");
69  legend->AddEntry(gr70," q70","lp");
70  legend->Draw();
71 }
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
float Float_t
Definition: RtypesCore.h:53
Definition: Rtypes.h:61
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0)
Compute Quantiles for this histogram Quantile x_q of a probability distribution Function F is defined...
Definition: TH1.cxx:4182
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2153
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2127
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
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
#define gPad
Definition: TVirtualPad.h:288
Definition: Rtypes.h:61
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60