-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotting_Header.h
400 lines (361 loc) · 12.9 KB
/
Plotting_Header.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#include "TH1.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "TLatex.h"
#include "TLine.h"
#include "TString.h"
#include "TH2.h"
#include "TF1.h"
#include "TLegend.h"
#include "TColor.h"
#include "TFile.h"
#include <TROOT.h>
#include <TStyle.h>
#include <iostream>
#include <string>
//__________________________________________________________________________________________________________
void SetPlotStyle() {
const Int_t nRGBs = 5;
const Int_t nCont = 255;
Double_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
Double_t red[nRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
Double_t green[nRGBs] = { 0.31, 0.81, 1.00, 0.20, 0.00 };
Double_t blue[nRGBs] = { 0.51, 1., 0.12, 0.00, 0.00};
TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, nCont);
gStyle->SetNumberContours(nCont);
}
void StyleSettingsPaper( TString format = ""){
//gStyle->SetOptTitle(kFALSE);
gStyle->SetOptDate(0); //show day and time
gStyle->SetOptStat(0); //show statistic
gStyle->SetPalette(1,0);
gStyle->SetFrameBorderMode(0);
gStyle->SetFrameFillColor(0);
gStyle->SetTitleFillColor(0);
gStyle->SetTextSize(0.5);
gStyle->SetLabelSize(0.03,"xyz");
gStyle->SetLabelOffset(0.002,"xyz");
gStyle->SetTitleFontSize(0.04);
gStyle->SetTitleOffset(1,"y");
gStyle->SetTitleOffset(0.7,"x");
gStyle->SetCanvasColor(0);
gStyle->SetPadTickX(1);
gStyle->SetPadTickY(1);
gStyle->SetLineWidth(1);
gStyle->SetPadTopMargin(0.03);
gStyle->SetPadBottomMargin(0.09);
gStyle->SetPadRightMargin(0.03);
gStyle->SetPadLeftMargin(0.13);
TGaxis::SetMaxDigits(3);
gErrorIgnoreLevel=kError;
if (format.CompareTo("eps") == 0 ||format.CompareTo("pdf") == 0 ) gStyle->SetLineScalePS(1);
SetPlotStyle();
}
//
// TCanvas *canvasExample = new TCanvas("canvasExample","",0,0,1300,850);
// Example: DrawPaperCanvasSettings( canvasExample, 0.085, 0.01, 0.01, 0.105);
//__________________________________________________________________________________________________________
void DrawPaperCanvasSettings(
TCanvas* c1,
Double_t leftMargin,
Double_t rightMargin,
Double_t topMargin,
Double_t bottomMargin
){
c1->SetTickx();
c1->SetTicky();
c1->SetGridx(0);
c1->SetGridy(0);
c1->SetLogy(0);
c1->SetLeftMargin(leftMargin);
c1->SetRightMargin(rightMargin);
c1->SetTopMargin(topMargin);
c1->SetBottomMargin(bottomMargin);
c1->SetFillColor(0);
}
//
// Example
// Double_t minY = 0.91;
// Double_t maxY = 1.039;
// Double_t minX = 0.27;
// Double_t maxX = 2.99e2;
// Double_t textSizeSinglePad = 0.05;
// Double_t textSizeLabelsPixel = 35;
// Double_t textSizeLabelsRel = 35./canvasheight;
//
// it is often best to use a dummy histogram for the style settings
// TH2F * histExampleDummy = new TH2F("histExampleDummy","histExampleDummy",1000,minX, maxX,1000,minY, maxY);
// set the style of the dummy (dummy, x title, y title, x label size, x title size, y label size, y title size, x title offset, y title offset, ndivisions x, ndivisions y)
// SetStyleHistoTH2ForGraphs(histExampleDummy, "#it{E}_{rec} (GeV)","#it{E}_{rec}/#it{E}_{in}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 0.9,0.81, 510, 510);
//
// histExampleDummy->GetXaxis()->SetNoExponent(); // when SetLogx() is used, one can think about adding more labels
// histExampleDummy->GetXaxis()->SetMoreLogLabels(kTRUE);
// histExampleDummy->DrawCopy();
//
//__________________________________________________________________________________________________________
void SetStyleHistoTH2ForGraphs(
TH2* histo,
TString XTitle,
TString YTitle,
Size_t xLableSize,
Size_t xTitleSize,
Size_t yLableSize,
Size_t yTitleSize,
Float_t xTitleOffset = 1,
Float_t yTitleOffset = 1,
Int_t xNDivisions = 510,
Int_t yNDivisions = 510,
Font_t textFontLabel = 42,
Font_t textFontTitle = 62
){
histo->SetXTitle(XTitle);
histo->SetYTitle(YTitle);
histo->SetTitle("");
histo->GetXaxis()->SetLabelFont(textFontLabel);
histo->GetYaxis()->SetLabelFont(textFontLabel);
histo->GetXaxis()->SetTitleFont(textFontTitle);
histo->GetYaxis()->SetTitleFont(textFontTitle);
histo->GetXaxis()->SetLabelSize(xLableSize);
histo->GetXaxis()->SetTitleSize(xTitleSize);
histo->GetXaxis()->SetTitleOffset(xTitleOffset);
histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
histo->GetYaxis()->SetDecimals();
histo->GetYaxis()->SetLabelSize(yLableSize);
histo->GetYaxis()->SetTitleSize(yTitleSize);
histo->GetYaxis()->SetTitleOffset(yTitleOffset);
histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
}
//
// draw a line to guide the eye (good for some comparisons)
// min x, max x, min y, max y, line width, line color, line style)
// DrawLines(minX, maxX, 1., 1., 1, kGray+2, 7);
//
//__________________________________________________________________________________________________________
void DrawLines(
Float_t startX, Float_t endX,
Float_t startY, Float_t endY,
Float_t linew, Float_t lineColor = 4, Style_t lineStyle = 1
){
TLine * l1 = new TLine (startX,startY,endX,endY);
l1->SetLineColor(lineColor);
l1->SetLineWidth(linew);
l1->SetLineStyle(lineStyle);
l1->Draw("same");
}
// function to set the plotting style (takes graph, markerstyle, markersize, and two times the color (for marker and lines))
// Example
//
// Color_t colorData = kBlack;
// Style_t markerStyleData = 20; // do not use asymmetric markers (like triangles [numbers 23, 26, 32 are forbidden!])
// Size_t markerSize = 1.5; //1.5 or 2 make reasonable sizes on most paper plots
// DrawSetMarker( histoData, 30, markerSize, kOrange-8, kOrange-8);
//
//__________________________________________________________________________________________________________
void DrawSetMarker(
TH1* histo1,
Style_t markerStyle,
Size_t markerSize,
Color_t markerColor,
Color_t lineColor
) {
histo1->SetMarkerStyle(markerStyle);
histo1->SetMarkerSize(markerSize);
histo1->SetLineWidth(markerSize);
histo1->SetMarkerColor(markerColor);
histo1->SetLineColor(lineColor);
if(markerStyle < 10)histo1->SetLineStyle(markerStyle);
histo1->GetYaxis()->SetLabelFont(42);
histo1->GetXaxis()->SetLabelFont(42);
histo1->GetYaxis()->SetTitleFont(62);
histo1->GetXaxis()->SetTitleFont(62);
}
//
// function to set the plotting style (takes graph, markerstyle, markersize, and two times the color (for marker and lines))
// Color_t colorData = kBlack;
// Style_t markerStyleData = 20; // do not use asymmetric markers (like triangles [numbers 23, 26, 32 are forbidden!])
// Size_t markerSize = 1.5; //1.5 or 2 make reasonable sizes on most paper plots
//
// DrawSetMarkerTGraphErr(graphData, markerStyleData, markerSize, colorData, colorData);
//
//__________________________________________________________________________________________________________
void DrawSetMarkerTGraphErr(
TGraphErrors* graph,
Style_t markerStyle,
Size_t markerSize,
Color_t markerColor,
Color_t lineColor,
Width_t lineWidth = 1,
Bool_t boxes = kFALSE,
Color_t fillColor = 0,
Bool_t isHollow = kFALSE
) {
graph->SetMarkerStyle(markerStyle);
graph->SetMarkerSize(markerSize);
graph->SetMarkerColor(markerColor);
graph->SetLineColor(lineColor);
graph->SetLineWidth(lineWidth);
if (boxes){
graph->SetFillColor(fillColor);
if (fillColor!=0){
if (!isHollow){
graph->SetFillStyle(1001);
} else {
graph->SetFillStyle(0);
}
} else {
graph->SetFillStyle(0);
}
}
}
//__________________________________________________________________________________________________________
void DrawSetMarkerTGraph(
TGraph* graph,
Style_t markerStyle,
Size_t markerSize,
Color_t markerColor,
Color_t lineColor,
Width_t lineWidth = 1,
Bool_t boxes = kFALSE,
Color_t fillColor = 0,
Bool_t isHollow = kFALSE
) {
graph->SetMarkerStyle(markerStyle);
graph->SetMarkerSize(markerSize);
graph->SetMarkerColor(markerColor);
graph->SetLineColor(lineColor);
graph->SetLineWidth(lineWidth);
if (boxes){
graph->SetFillColor(fillColor);
if (fillColor!=0){
if (!isHollow){
graph->SetFillStyle(1001);
} else {
graph->SetFillStyle(0);
}
} else {
graph->SetFillStyle(0);
}
}
}
//__________________________________________________________________________________________________________
void DrawSetMarkerTGraphAsym(
TGraphAsymmErrors* graph,
Style_t markerStyle,
Size_t markerSize,
Color_t markerColor,
Color_t lineColor,
Width_t lineWidth =1,
Bool_t boxes = kFALSE,
Color_t fillColor = 0,
Bool_t isHollow = kFALSE
) {
graph->SetMarkerStyle(markerStyle);
graph->SetMarkerSize(markerSize);
graph->SetMarkerColor(markerColor);
graph->SetLineColor(lineColor);
graph->SetLineWidth(lineWidth);
if (boxes){
graph->SetFillColor(fillColor);
if (fillColor!=0){
if (!isHollow){
graph->SetFillStyle(1001);
} else {
graph->SetFillStyle(0);
}
} else {
graph->SetFillStyle(0);
}
}
}
//__________________________________________________________________________________________________________
void SetStyleTLatex(
TLatex* text,
Size_t textSize,
Width_t lineWidth,
Color_t textColor = 1,
Font_t textFont = 42,
Bool_t kNDC = kTRUE,
Short_t align = 11
){
if (kNDC) {text->SetNDC();}
text->SetTextFont(textFont);
text->SetTextColor(textColor);
text->SetTextSize(textSize);
text->SetLineWidth(lineWidth);
text->SetTextAlign(align);
}
//
// Example
// Double_t textSizeLabelsRel = 35./canvasheight;
// drawLatexAdd("ALICE Performance",0.15,0.92,textSizeLabelsRel,kFALSE);
// drawLatexAdd("Xe-Xe, #sqrt{#it{s}_{NN}} = 90 TeV",0.15,0.92-textSizeLabelsRel,textSizeLabelsRel,kFALSE);
// drawLatexAdd("e^{#pm} rec. with EMCal",0.15,0.92-2*textSizeLabelsRel,textSizeLabelsRel,kFALSE);
//
//__________________________________________________________________________________________________________
void drawLatexAdd(TString latextext, Double_t textcolumn, Double_t textrow, Double_t textSizePixel,Bool_t setFont = kFALSE, Bool_t setFont2 = kFALSE, Bool_t alignRight = kFALSE, Color_t textcolor = kBlack){
TLatex *latexDummy = new TLatex(textcolumn ,textrow,latextext);
SetStyleTLatex( latexDummy, textSizePixel,4);
if(setFont)
latexDummy->SetTextFont(62);
if(setFont2)
latexDummy->SetTextFont(43);
if(alignRight)
latexDummy->SetTextAlign(31);
latexDummy->SetTextColor(textcolor);
latexDummy->Draw();
}
//__________________________________________________________________________________________________________
void DrawGammaSetMarkerTF1(
TF1* fit1,
Style_t lineStyle,
Size_t lineWidth,
Color_t lineColor
) {
fit1->SetLineColor(lineColor);
fit1->SetLineStyle(lineStyle);
fit1->SetLineWidth(lineWidth);
}
//__________________________________________________________________________________________________________
TLegend *GetAndSetLegend2(
Double_t positionX,
Double_t positionY,
Double_t positionXRight,
Double_t positionYUp,
Size_t textSize,
Int_t columns = 1,
TString header = "",
Font_t textFont = 43,
Double_t margin = 0
){
TLegend *legend = new TLegend(positionX,positionY,positionXRight,positionYUp);
legend->SetNColumns(columns);
legend->SetLineColor(0);
legend->SetLineWidth(0);
legend->SetFillColor(0);
legend->SetFillStyle(0);
legend->SetLineStyle(0);
legend->SetBorderSize(0);
legend->SetTextFont(textFont);
legend->SetTextSize(textSize);
if (margin != 0) legend->SetMargin(margin);
if (header.CompareTo("")!= 0) legend->SetHeader(header);
return legend;
}
struct LegLeft{
LegLeft(double xmin, double ymin, double xmax, double ymax, Size_t size){
leg = GetAndSetLegend2(xmin, ymin, xmax, ymax, size);
leg->SetNColumns(2);
leg->SetTextAlign(32);
}
TLegend* Leg() {return leg;};
void AddEntry(TObject* h, TString s = "", TString p = ""){
leg->AddEntry((TObject*)0,s,"");
leg->AddEntry(h,"#color[0]{i}",p);
}
void Draw(TString s = ""){
leg->Draw(s);
}
TLegend *leg = nullptr;
};