Logo ROOT   6.12/07
Reference Guide
candleplotwhiskers.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Example of candle plot showing the whiskers definition.
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \author Georg Troska
11 
12 void candleplotwhiskers() {
13  TCanvas *c1 = new TCanvas("c1","Candle Presets",700,800);
14  c1->Divide(1,2);
15 
16  TRandom *randnum = new TRandom();
17  TH2I *h1 = new TH2I("h1","Gaus",100,-5,5,1,0,1);
18  TH1I *h2 = new TH1I("h2","Gaus",100,-5,5);
19 
20  h1->GetXaxis()->SetTitle("Standard deviation #sigma");
21  h2->GetXaxis()->SetTitle("Standard deviation #sigma");
22  h2->GetYaxis()->SetTitle("dN/d#sigma");
23 
24  float myRand;
25  for (int i = 0; i < 100000; i++) {
26  myRand = randnum->Gaus(0,1);
27  h1->Fill(myRand,0);
28  h2->Fill(myRand);
29  }
30 
31  Double_t *q = new Double_t[3];
32  Double_t *p = new Double_t[3];
33  q[0] = 0.; q[1] = 0.; q[2] = 0.;
34  p[0] = 0.25; p[1] = 0.5; p[2] = 0.75;
35 
36  h2->GetQuantiles(3,q,p);
37  cout << "Q1 (-25%): " << q[0] << " Median: " << q[1] << " Q3 (+25%): " << q[2] << endl;
38  double iqr = q[2]-q[0];
39  TF1 *mygaus_1_middle = new TF1("mygaus_1_middle","gaus",q[0],q[2]);
40  TF1 *mygaus_1_left = new TF1("mygaus_1_left","gaus",q[0]-1.5*iqr,q[0]);
41  mygaus_1_left->SetLineColor(kGreen);
42  TF1 *mygaus_1_right = new TF1("mygaus_1_right","gaus",q[2],q[2]+1.5*iqr);
43  mygaus_1_right->SetLineColor(kGreen);
44  c1->cd(1);
45  h1->SetLineWidth(3);
46  h1->SetFillStyle(0);
47  h1->Draw("candley2 scat");
48 
49  c1->cd(2);
50  h2->Draw("");
51  h2->Fit("mygaus_1_left","R");
52  mygaus_1_left->Draw("same");
53  TLine *l3 = new TLine(q[0]-1.5*iqr,0,q[0]-1.5*iqr,mygaus_1_left->Eval(q[0]-1.5*iqr));
54  l3->SetLineColor(kGreen); l3->SetLineWidth(2); l3->Draw("");
55  TLine *l1 = new TLine(q[0] ,0,q[0] ,mygaus_1_left->Eval(q[0]));
56  l1->SetLineWidth(2); l1->SetLineColor(kGreen); l1->Draw("");
57 
58  h2->Fit("mygaus_1_right","R","");
59  mygaus_1_right->Draw("same");
60  TLine *l4 = new TLine(q[2]+1.5*iqr,0,q[2]+1.5*iqr,mygaus_1_left->Eval(q[2]+1.5*iqr));
61  l4->SetLineColor(kGreen); l4->SetLineWidth(2); l4->Draw("");
62  TLine *l5 = new TLine(q[2] ,0,q[2] ,mygaus_1_right->Eval(q[2]));
63  l5->SetLineWidth(2); l5->SetLineColor(kGreen); l5->Draw("");
64 
65  h2->Fit("mygaus_1_middle","R");
66  mygaus_1_middle->Draw("same");
67 
68  //In principal one could calculate these values by h2->Integral() as well
69  TText *t = new TText(); t->SetTextFont(42);
70  t->DrawText(0,mygaus_1_middle->Eval(0)/2,"50%");
71  t->DrawText(-1.5,mygaus_1_middle->Eval(-1.5)/2,"24.65%");
72  t->DrawText(+1,mygaus_1_middle->Eval(+1.5)/2,"24.65%");
73  t->DrawText(q[0]-1.5*iqr,1000,Form("%.3f",q[0]-1.5*iqr))->SetTextAngle(90);
74  t->DrawText(q[2]+1.5*iqr,1000,Form("%.3f",q[2]+1.5*iqr))->SetTextAngle(90);
75  t->DrawText(q[0],1000,Form("%.3f",q[0]))->SetTextAngle(90);
76  t->DrawText(q[2],1000,Form("%.3f",q[2]))->SetTextAngle(90);
77 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3244
THist< 1, int, THistStatContent > TH1I
Definition: THist.hxx:287
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:256
return c1
Definition: legend1.C:41
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
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:4315
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1222
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
Definition: Rtypes.h:59
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
Base class for several text objects.
Definition: TText.h:23
TH1F * h1
Definition: legend1.C:5
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2969
1-D histogram with an int per channel (see TH1 documentation)}
Definition: TH1.h:526
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition: TAttText.h:42
char * Form(const char *fmt,...)
A simple line.
Definition: TLine.h:23
TAxis * GetYaxis()
Definition: TH1.h:316
The Canvas class.
Definition: TCanvas.h:31
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1334
double Double_t
Definition: RtypesCore.h:55
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:1153
1-Dim function class
Definition: TF1.h:211
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition: TText.cxx:176
THist< 2, int, THistStatContent > TH2I
Definition: THist.hxx:293
2-D histogram with an int per channel (see TH1 documentation)}
Definition: TH2.h:210
float * q
Definition: THbookFile.cxx:87
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
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:3688
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315