Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist052_Graphics_candle_plot_whiskers.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Example of candle plot showing the whiskers definition.

Q1 (-25%): -0.675525 Median: 0.00168511 Q3 (+25%): 0.676189
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 11.7941
NDf = 17
Edm = 1.90451e-06
NCalls = 131
Constant = 3728.5 +/- 182.159
Mean = -0.110704 +/- 0.0721072
Sigma = 0.959495 +/- 0.025154 (limited)
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 8.0469
NDf = 17
Edm = 1.56503e-05
NCalls = 132
Constant = 4071.09 +/- 244.49
Mean = -0.0289155 +/- 0.087166
Sigma = 1.00961 +/- 0.0288274 (limited)
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 6.93238
NDf = 11
Edm = 3.27894e-08
NCalls = 107
Constant = 3970.02 +/- 25.7596
Mean = -0.000189021 +/- 0.0118284
Sigma = 1.02465 +/- 0.0335469 (limited)
{
auto c1 = new TCanvas("c1", "Candle Presets", 700, 800);
c1->Divide(1, 2);
auto rng = new TRandom();
auto h1 = new TH2I("h1", "Gaus", 100, -5, 5, 1, 0, 1);
auto h2 = new TH1I("h2", "Gaus", 100, -5, 5);
h1->GetXaxis()->SetTitle("Standard deviation #sigma");
h2->GetXaxis()->SetTitle("Standard deviation #sigma");
h2->GetYaxis()->SetTitle("dN/d#sigma");
float myRand;
for (int i = 0; i < 100000; i++) {
myRand = rng->Gaus(0, 1);
h1->Fill(myRand, 0);
h2->Fill(myRand);
}
Double_t *q = new Double_t[3];
Double_t *p = new Double_t[3];
q[0] = 0.;
q[1] = 0.;
q[2] = 0.;
p[0] = 0.25;
p[1] = 0.5;
p[2] = 0.75;
h2->GetQuantiles(3, q, p);
cout << "Q1 (-25%): " << q[0] << " Median: " << q[1] << " Q3 (+25%): " << q[2] << endl;
double iqr = q[2] - q[0];
auto mygaus_1_middle = new TF1("mygaus_1_middle", "gaus", q[0], q[2]);
auto mygaus_1_left = new TF1("mygaus_1_left", "gaus", q[0] - 1.5 * iqr, q[0]);
mygaus_1_left->SetLineColor(kGreen);
auto mygaus_1_right = new TF1("mygaus_1_right", "gaus", q[2], q[2] + 1.5 * iqr);
mygaus_1_right->SetLineColor(kGreen);
c1->cd(1);
h1->Draw("candley2 scat");
c1->cd(2);
h2->Draw("");
h2->Fit("mygaus_1_left", "R");
mygaus_1_left->Draw("same");
auto l3 = new TLine(q[0] - 1.5 * iqr, 0, q[0] - 1.5 * iqr, mygaus_1_left->Eval(q[0] - 1.5 * iqr));
l3->SetLineColor(kGreen);
l3->SetLineWidth(2);
l3->Draw("");
auto l1 = new TLine(q[0], 0, q[0], mygaus_1_left->Eval(q[0]));
l1->SetLineWidth(2);
l1->SetLineColor(kGreen);
l1->Draw("");
h2->Fit("mygaus_1_right", "R", "");
mygaus_1_right->Draw("same");
auto l4 = new TLine(q[2] + 1.5 * iqr, 0, q[2] + 1.5 * iqr, mygaus_1_left->Eval(q[2] + 1.5 * iqr));
l4->SetLineColor(kGreen);
l4->SetLineWidth(2);
l4->Draw("");
auto l5 = new TLine(q[2], 0, q[2], mygaus_1_right->Eval(q[2]));
l5->SetLineWidth(2);
l5->SetLineColor(kGreen);
l5->Draw("");
h2->Fit("mygaus_1_middle", "R");
mygaus_1_middle->Draw("same");
// In principal one could calculate these values by h2->Integral() as well
TText t;
t.SetTextFont(42);
t.DrawText(0, mygaus_1_middle->Eval(0) / 2, "50%");
t.DrawText(-1.5, mygaus_1_middle->Eval(-1.5) / 2, "24.65%");
t.DrawText(+1, mygaus_1_middle->Eval(+1.5) / 2, "24.65%");
t.DrawText(q[0] - 1.5 * iqr, 1000, Form("%.3f", q[0] - 1.5 * iqr))->SetTextAngle(90);
t.DrawText(q[2] + 1.5 * iqr, 1000, Form("%.3f", q[2] + 1.5 * iqr))->SetTextAngle(90);
t.DrawText(q[0], 1000, Form("%.3f", q[0]))->SetTextAngle(90);
t.DrawText(q[2], 1000, Form("%.3f", q[2]))->SetTextAngle(90);
}
double Double_t
Definition RtypesCore.h:59
@ kGreen
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
float * q
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:40
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:48
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
1-D histogram with an int per channel (see TH1 documentation)
Definition TH1.h:563
TAxis * GetXaxis()
Definition TH1.h:340
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
2-D histogram with an int per channel (see TH1 documentation)
Definition TH2.h:227
Use the TLine constructor to create a simple line.
Definition TLine.h:22
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Base class for several text objects.
Definition TText.h:22
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:176
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5
Date
June 2022
Author
Georg Troska

Definition in file hist052_Graphics_candle_plot_whiskers.C.