Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist020_TH2_draw.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Display the various 2-d drawing options
5///
6/// \macro_image
7/// \macro_code
8///
9/// \date June 2022
10/// \author Rene Brun
11
13{
17 TF2 *f2 = new TF2("f2", "xygaus + xygaus(5) + xylandau(10)", -4, 4, -4, 4);
18 Double_t params[] = {130, -1.4, 1.8, 1.5, 1, 150, 2, 0.5, -2, 0.5, 3600, -2, 0.7, -3, 0.3};
19 f2->SetParameters(params);
20 auto h2 = new TH2F("h2", "xygaus + xygaus(5) + xylandau(10)", 20, -4, 4, 20, -4, 4);
21 h2->SetFillColor(46);
22 h2->FillRandom("f2", 40000);
24
25 // basic 2-d options
26 Float_t xMin = 0.67, yMin = 0.875, xMax = 0.85, yMax = 0.95;
27 Int_t cancolor = 17;
28 auto c2h = new TCanvas("c2h", "2-d options", 10, 10, 800, 600);
29 c2h->Divide(2, 2);
30 c2h->SetFillColor(cancolor);
31 c2h->cd(1);
32 h2->Draw();
33 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "SCAT", "brNDC");
34 c2h->cd(2);
35 h2->Draw("box");
36 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "BOX", "brNDC");
37 c2h->cd(3);
38 h2->Draw("arr");
39 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "ARR", "brNDC");
40 c2h->cd(4);
41 h2->Draw("colz");
42 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "COLZ", "brNDC");
43 c2h->Update();
44
45 // text option
46 auto ctext = new TCanvas("ctext", "text option", 50, 50, 800, 600);
47 gPad->SetGrid();
48 ctext->SetFillColor(cancolor);
49 ctext->SetGrid();
50 h2->Draw("text");
51 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "TEXT", "brNDC");
52 ctext->Update();
53
54 // contour options
55 auto cont = new TCanvas("contours", "contours", 100, 100, 800, 600);
56 cont->Divide(2, 2);
57 gPad->SetGrid();
58 cont->SetFillColor(cancolor);
59 cont->cd(1);
60 h2->Draw("contz");
61 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "CONTZ", "brNDC");
62 cont->cd(2);
63 gPad->SetGrid();
64 h2->Draw("cont1");
65 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "CONT1", "brNDC");
66 cont->cd(3);
67 gPad->SetGrid();
68 h2->Draw("cont2");
69 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "CONT2", "brNDC");
70 cont->cd(4);
71 gPad->SetGrid();
72 h2->Draw("cont3");
73 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "CONT3", "brNDC");
74 cont->Update();
75
76 // lego options
77 auto lego = new TCanvas("lego", "lego options", 150, 150, 800, 600);
78 lego->Divide(2, 2);
79 lego->SetFillColor(cancolor);
80 lego->cd(1);
81 h2->Draw("lego");
82 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "LEGO", "brNDC");
83 lego->cd(2);
84 h2->Draw("lego1");
85 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "LEGO1", "brNDC");
86 lego->cd(3);
87 gPad->SetTheta(61);
88 gPad->SetPhi(-82);
89 h2->Draw("surf1pol");
90 pl.DrawPaveLabel(xMin, yMin, xMax + 0.05, yMax, "SURF1POL", "brNDC");
91 lego->cd(4);
92 gPad->SetTheta(21);
93 gPad->SetPhi(-90);
94 h2->Draw("surf1cyl");
95 pl.DrawPaveLabel(xMin, yMin, xMax + 0.05, yMax, "SURF1CYL", "brNDC");
96 lego->Update();
97
98 // surface options
99 auto surf = new TCanvas("surfopt", "surface options", 200, 200, 800, 600);
100 surf->Divide(2, 2);
101 surf->SetFillColor(cancolor);
102 surf->cd(1);
103 h2->Draw("surf1");
104 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "SURF1", "brNDC");
105 surf->cd(2);
106 h2->Draw("surf2z");
107 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "SURF2Z", "brNDC");
108 surf->cd(3);
109 h2->Draw("surf3");
110 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "SURF3", "brNDC");
111 surf->cd(4);
112 h2->Draw("surf4");
113 pl.DrawPaveLabel(xMin, yMin, xMax, yMax, "SURF4", "brNDC");
114 surf->Update();
115}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
The Canvas class.
Definition TCanvas.h:23
virtual void SetParameters(const Double_t *params)
Definition TF1.h:677
A 2-Dim function with parameters.
Definition TF2.h:29
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1642
void SetFrameFillColor(Color_t color=1)
Definition TStyle.h:376
void SetCanvasColor(Color_t color=19)
Definition TStyle.h:347
void lego()
Definition lego.C:31