Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
hlquantiles.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// Demo for quantiles (with highlight mode)
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \authors Rene Brun, Eddy Offermann, Jan Musinsky
9 
10 TList *lq = 0;
11 TGraph *gr = 0;
12 
13 void hlquantiles() {
14  const Int_t nq = 100;
15  const Int_t nshots = 10;
16  Double_t xq[nq]; // position where to compute the quantiles in [0,1]
17  Double_t yq[nq]; // array to contain the quantiles
18  for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq;
19 
20  TGraph *gr70 = new TGraph(nshots);
21  TGraph *gr90 = new TGraph(nshots);
22  TGraph *gr98 = new TGraph(nshots);
23  TGraph *grq[nq];
24  for (Int_t ig = 0; ig < nq; ig++) grq[ig] = new TGraph(nshots);
25  TH1F *h = new TH1F("h","demo quantiles",50,-3,3);
26 
27  for (Int_t shot=0;shot<nshots;shot++) {
28  h->FillRandom("gaus",50);
29  h->GetQuantiles(nq,yq,xq);
30  gr70->SetPoint(shot,shot+1,yq[70]);
31  gr90->SetPoint(shot,shot+1,yq[90]);
32  gr98->SetPoint(shot,shot+1,yq[98]);
33  for (Int_t ig = 0; ig < nq; ig++)
34  grq[ig]->SetPoint(shot,shot+1,yq[ig]);
35  }
36 
37  //show the original histogram in the top pad
38  TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900);
39  c1->SetFillColor(41);
40  c1->Divide(1,3);
41  c1->cd(1);
42  h->SetFillColor(38);
43  h->Draw();
44 
45  // show the final quantiles in the middle pad
46  c1->cd(2);
47  gPad->SetFrameFillColor(33);
48  gPad->SetGrid();
49  gr = new TGraph(nq,xq,yq);
50  gr->SetTitle("final quantiles");
51  gr->SetMarkerStyle(21);
52  gr->SetMarkerColor(kRed);
53  gr->SetMarkerSize(0.3);
54  gr->Draw("ap");
55 
56  // prepare quantiles
57  lq = new TList();
58  for (Int_t ig = 0; ig < nq; ig++) {
59  grq[ig]->SetMinimum(gr->GetYaxis()->GetXmin());
60  grq[ig]->SetMaximum(gr->GetYaxis()->GetXmax());
61  grq[ig]->SetMarkerStyle(23);
62  grq[ig]->SetMarkerColor(ig%100);
63  grq[ig]->SetTitle(TString::Format("q%02d", ig));
64  lq->Add(grq[ig]);
65  }
66 
67  TText *info = new TText(0.1, 2.4, "please move the mouse over the graph");
68  info->SetTextSize(0.08);
69  info->SetTextColor(gr->GetMarkerColor());
70  info->SetBit(kCannotPick);
71  info->Draw();
72 
73  gr->SetHighlight();
74  c1->HighlightConnect("HighlightQuantile(TVirtualPad*,TObject*,Int_t,Int_t)");
75 
76  // show the evolution of some quantiles in the bottom pad
77  c1->cd(3);
78  gPad->SetFrameFillColor(17);
79  gPad->DrawFrame(0,0,nshots+1,3.2);
80  gPad->SetGrid();
81  gr98->SetMarkerStyle(22);
82  gr98->SetMarkerColor(kRed);
83  gr98->Draw("lp");
84  gr90->SetMarkerStyle(21);
85  gr90->SetMarkerColor(kBlue);
86  gr90->Draw("lp");
87  gr70->SetMarkerStyle(20);
88  gr70->SetMarkerColor(kMagenta);
89  gr70->Draw("lp");
90  // add a legend
91  TLegend *legend = new TLegend(0.85,0.74,0.95,0.95);
92  legend->SetTextFont(72);
93  legend->SetTextSize(0.05);
94  legend->AddEntry(gr98," q98","lp");
95  legend->AddEntry(gr90," q90","lp");
96  legend->AddEntry(gr70," q70","lp");
97  legend->Draw();
98 }
99 
100 void HighlightQuantile(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
101 {
102  // show the evolution of all quantiles in the bottom pad
103  if (obj != gr) return;
104  if (ihp == -1) return;
105 
106  TVirtualPad *savepad = gPad;
107  pad->GetCanvas()->cd(3);
108  lq->At(ihp)->Draw("alp");
109  gPad->Update();
110  savepad->cd();
111 }