CombineHarvester
Plotting_Style.h
Go to the documentation of this file.
1 #ifndef Core_Plotting_Style_h
2 #define Core_Plotting_Style_h
3 
4 #include "TStyle.h"
5 #include "TROOT.h"
6 
16 void SetTDRStyle();
17 
26 void ModTDRStyle(int width, int height, double t, double b, double l, double r);
27 
32 void ModTDRStyle();
33 
37 void TdrGrid(bool grid_on);
38 
39 //----------------------------------------------------------------------------
40 // Implementation
41 //----------------------------------------------------------------------------
42 void SetTDRStyle() {
43  // For the canvas:
44  gStyle->SetCanvasBorderMode(0);
45  gStyle->SetCanvasColor(kWhite);
46  gStyle->SetCanvasDefH(600); // Height of canvas
47  gStyle->SetCanvasDefW(600); // Width of canvas
48  gStyle->SetCanvasDefX(0); // POsition on screen
49  gStyle->SetCanvasDefY(0);
50 
51  // For the Pad:
52  gStyle->SetPadBorderMode(0);
53  // gStyle->SetPadBorderSize(Width_t size = 1);
54  gStyle->SetPadColor(kWhite);
55  gStyle->SetPadGridX(false);
56  gStyle->SetPadGridY(false);
57  gStyle->SetGridColor(0);
58  gStyle->SetGridStyle(3);
59  gStyle->SetGridWidth(1);
60 
61  // For the frame:
62  gStyle->SetFrameBorderMode(0);
63  gStyle->SetFrameBorderSize(1);
64  gStyle->SetFrameFillColor(0);
65  gStyle->SetFrameFillStyle(0);
66  gStyle->SetFrameLineColor(1);
67  gStyle->SetFrameLineStyle(1);
68  gStyle->SetFrameLineWidth(1);
69 
70  // For the histo:
71  // gStyle->SetHistFillColor(1);
72  // gStyle->SetHistFillStyle(0);
73  gStyle->SetHistLineColor(1);
74  gStyle->SetHistLineStyle(0);
75  gStyle->SetHistLineWidth(1);
76  // gStyle->SetLegoInnerR(Float_t rad = 0.5);
77  // gStyle->SetNumberContours(Int_t number = 20);
78 
79  gStyle->SetEndErrorSize(2);
80  // gStyle->SetErrorMarker(20);
81  // gStyle->SetErrorX(0.);
82 
83  gStyle->SetMarkerStyle(20);
84 
85  // For the fit/function:
86  gStyle->SetOptFit(1);
87  gStyle->SetFitFormat("5.4g");
88  gStyle->SetFuncColor(2);
89  gStyle->SetFuncStyle(1);
90  gStyle->SetFuncWidth(1);
91 
92  // For the date:
93  gStyle->SetOptDate(0);
94  // gStyle->SetDateX(Float_t x = 0.01);
95  // gStyle->SetDateY(Float_t y = 0.01);
96 
97  // For the statistics box:
98  gStyle->SetOptFile(0);
99  gStyle->SetOptStat(0); // To display the mean and RMS: SetOptStat("mr");
100  gStyle->SetStatColor(kWhite);
101  gStyle->SetStatFont(42);
102  gStyle->SetStatFontSize(0.025);
103  gStyle->SetStatTextColor(1);
104  gStyle->SetStatFormat("6.4g");
105  gStyle->SetStatBorderSize(1);
106  gStyle->SetStatH(0.1);
107  gStyle->SetStatW(0.15);
108  // gStyle->SetStatStyle(Style_t style = 1001);
109  // gStyle->SetStatX(Float_t x = 0);
110  // gStyle->SetStatY(Float_t y = 0);
111 
112  // Margins:
113  gStyle->SetPadTopMargin(0.05);
114  gStyle->SetPadBottomMargin(0.13);
115  gStyle->SetPadLeftMargin(0.16);
116  gStyle->SetPadRightMargin(0.02);
117 
118  // For the Global title:
119  gStyle->SetOptTitle(0);
120  gStyle->SetTitleFont(42);
121  gStyle->SetTitleColor(1);
122  gStyle->SetTitleTextColor(1);
123  gStyle->SetTitleFillColor(10);
124  gStyle->SetTitleFontSize(0.05);
125  // gStyle->SetTitleH(0); // Set the height of the title box
126  // gStyle->SetTitleW(0); // Set the width of the title box
127  // gStyle->SetTitleX(0); // Set the position of the title box
128  // gStyle->SetTitleY(0.985); // Set the position of the title box
129  // gStyle->SetTitleStyle(Style_t style = 1001);
130  // gStyle->SetTitleBorderSize(2);
131 
132  // For the axis titles:
133  gStyle->SetTitleColor(1, "XYZ");
134  gStyle->SetTitleFont(42, "XYZ");
135  gStyle->SetTitleSize(0.06, "XYZ");
136  // Another way to set the size?
137  // gStyle->SetTitleXSize(Float_t size = 0.02);
138  // gStyle->SetTitleYSize(Float_t size = 0.02);
139  gStyle->SetTitleXOffset(0.9);
140  gStyle->SetTitleYOffset(1.25);
141  // gStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
142 
143  // For the axis labels:
144 
145  gStyle->SetLabelColor(1, "XYZ");
146  gStyle->SetLabelFont(42, "XYZ");
147  gStyle->SetLabelOffset(0.007, "XYZ");
148  gStyle->SetLabelSize(0.05, "XYZ");
149 
150  // For the axis:
151 
152  gStyle->SetAxisColor(1, "XYZ");
153  gStyle->SetStripDecimals(kTRUE);
154  gStyle->SetTickLength(0.03, "XYZ");
155  gStyle->SetNdivisions(510, "XYZ");
156  gStyle->SetPadTickX(1);
157  gStyle->SetPadTickY(1);
158 
159  // Change for log plots:
160  gStyle->SetOptLogx(0);
161  gStyle->SetOptLogy(0);
162  gStyle->SetOptLogz(0);
163 
164  // Postscript options:
165  gStyle->SetPaperSize(20., 20.);
166  // gStyle->SetLineScalePS(Float_t scale = 3);
167  // gStyle->SetLineStyleString(Int_t i, const char* text);
168  // gStyle->SetHeaderPS(const char* header);
169  // gStyle->SetTitlePS(const char* pstitle);
170 
171  // gStyle->SetBarOffset(Float_t baroff = 0.5);
172  // gStyle->SetBarWidth(Float_t barwidth = 0.5);
173  // gStyle->SetPaintTextFormat(const char* format = "g");
174  // gStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
175  // gStyle->SetTimeOffset(Double_t toffset);
176  // gStyle->SetHistMinimumZero(kTRUE);
177 
178  gStyle->SetHatchesLineWidth(5);
179  gStyle->SetHatchesSpacing(0.05);
180 }
181 
182 void ModTDRStyle(int width, int height, double t, double b, double l,
183  double r) {
184  SetTDRStyle();
185 
186  // Set the default canvas width and height in pixels
187  gStyle->SetCanvasDefW(width);
188  gStyle->SetCanvasDefH(height);
189 
190  // Set the default margins.
191  // These are given as fractions of the pad height for `Top` and `Bottom` and
192  // the pad width for `Left` and `Right`. But we want to specify all of these
193  // as fractions of the shortest length.
194  double def_w = static_cast<double>(gStyle->GetCanvasDefW());
195  double def_h = static_cast<double>(gStyle->GetCanvasDefH());
196 
197  double scale_h = (def_h > def_w) ? def_w / def_h : 1.;
198  double scale_w = (def_w > def_h) ? def_h / def_w : 1.;
199 
200  double def_min = def_h < def_w ? def_h : def_w;
201 
202  gStyle->SetPadTopMargin(t * scale_h); // default 0.05
203  gStyle->SetPadBottomMargin(b * scale_h); // default 0.13
204  gStyle->SetPadLeftMargin(l * scale_w); // default 0.16
205  gStyle->SetPadRightMargin(r * scale_w); // default 0.02
206  // But note the new CMS style sets these:
207  // 0.08, 0.12, 0.12, 0.04
208 
209  // Set number of axis tick divisions
210  gStyle->SetNdivisions(506, "XYZ"); // default 510
211 
212  // Some marker properties not set in the default tdr style
213  gStyle->SetMarkerColor(kBlack);
214  gStyle->SetMarkerSize(1.0);
215 
216 
217  gStyle->SetLabelOffset(0.007, "YZ");
218  // This is an adhoc adjustment to scale the x-axis label
219  // offset when we strect plot vertically
220  // Will also need to increase if first x-axis label has more than one digit
221  gStyle->SetLabelOffset(0.005 * (3. - 2. / scale_h), "X");
222 
223  // In this next part we do a slightly involved calculation to set the axis
224  // title offsets, depending on the values of the TPad dimensions and margins.
225  // This is to try and ensure that regardless of how these pad values are set,
226  // the axis titles will be located towards the edges of the canvas and not get
227  // pushed off the edge - which can often happen if a fixed value is used.
228  double title_size = 0.05;
229  double title_px = title_size * def_min;
230  double label_size = 0.04;
231  gStyle->SetTitleSize(title_size, "XYZ");
232  gStyle->SetLabelSize(label_size, "XYZ");
233 
234  gStyle->SetTitleXOffset(0.5 * scale_h *
235  (1.2 * (def_h * b * scale_h - 0.6 * title_px)) /
236  title_px);
237  gStyle->SetTitleYOffset(0.5 * scale_w *
238  (1.2 * (def_w * l * scale_w - 0.6 * title_px)) /
239  title_px);
240 
241  // Only draw ticks where we have an axis
242  gStyle->SetPadTickX(0);
243  gStyle->SetPadTickY(0);
244  gStyle->SetTickLength(0.02, "XYZ");
245 
246  gStyle->SetLegendBorderSize(0);
247  gStyle->SetLegendFont(42);
248  gStyle->SetLegendFillColor(0);
249  gStyle->SetFillColor(0);
250 
251  gROOT->ForceStyle();
252 }
253 
254 void ModTDRStyle() { ModTDRStyle(600, 600, 0.06, 0.12, 0.16, 0.04); }
255 
256 void TdrGrid(bool grid_on) {
257  gStyle->SetPadGridX(grid_on);
258  gStyle->SetPadGridY(grid_on);
259 }
260 
261 #endif
void TdrGrid(bool grid_on)
Modify the global style to enable/disable the drawing of axis gridlines.
void SetTDRStyle()
Sets the semi-official CMS plotting global style.
void ModTDRStyle(int width, int height, double t, double b, double l, double r)
Sets an improved plotting style, using the CMS default as a base.