1
|
#include "apply_plot_style.h"
|
2
|
|
3
|
|
4
|
void ApplyPlotStyle::test(){
|
5
|
|
6
|
string datafile = "~/Documents/Work/MICE Data/Data run 7469/MAUS 3pt0/data.root";
|
7
|
TFile* data = new TFile(datafile.c_str());
|
8
|
TTree* T = (TTree*)data->Get("T");
|
9
|
|
10
|
TH1F* x = new TH1F("x", ";x (mm)", 150, -150.0, 150.0);
|
11
|
TH1F* y = new TH1F("y", ";y", 150, -150.0, 150.0);
|
12
|
|
13
|
TH2F* xy_all = new TH2F("xy_all", ";x (mm); y(mm)", 150, -150.0, 150.0, 150, -150.0, 150.0);
|
14
|
TH2F* xy_some = new TH2F("xy_some", ";x (mm); y(mm)", 150, -150.0, 150.0, 150, -150.0, 150.0);
|
15
|
|
16
|
TRandom3 random;
|
17
|
|
18
|
double a, b;
|
19
|
T->SetBranchAddress("TKU_s1_x", &a);
|
20
|
T->SetBranchAddress("TKU_s1_y", &b);
|
21
|
|
22
|
double cut_x_min = -50.0;
|
23
|
double cut_x_max = 50.0;
|
24
|
|
25
|
double cut_y_min = -50.0;
|
26
|
double cut_y_max = 50.0;
|
27
|
|
28
|
for(int i = 0; i < T->GetEntries(); i++){
|
29
|
T->GetEntry(i);
|
30
|
|
31
|
if(b > cut_y_min && b < cut_y_max){
|
32
|
if(a > cut_x_min && b < cut_x_max){
|
33
|
|
34
|
x->Fill(a);
|
35
|
y->Fill(b);
|
36
|
|
37
|
xy_all->Fill(a, b);
|
38
|
|
39
|
if(random.Uniform() < 0.7){
|
40
|
xy_some->Fill(a, b);
|
41
|
}
|
42
|
|
43
|
}
|
44
|
}
|
45
|
}
|
46
|
|
47
|
Hist1D(x, y, "style_test.pdf", -50.0, 50.0);
|
48
|
|
49
|
Hist2D(xy_all, xy_some, "style_test_2d.pdf", -50.0, 50.0, -50.0, 50.0, 0);
|
50
|
|
51
|
|
52
|
|
53
|
}
|
54
|
|
55
|
|
56
|
|
57
|
|
58
|
ApplyPlotStyle::ApplyPlotStyle(){
|
59
|
std::cout << "Plot style object created.\n";
|
60
|
}
|
61
|
|
62
|
|
63
|
|
64
|
|
65
|
void ApplyPlotStyle::Hist1D(TH1F* hist1, TH1F* hist2, string saveAs, double cut_lower, double cut_upper, bool normalise, string legend1, string legend2){
|
66
|
|
67
|
/*
|
68
|
* Stack data and MC hists together onto one plot:
|
69
|
* - Normalise to 1
|
70
|
* - Set plot style
|
71
|
* - Stack
|
72
|
*/
|
73
|
|
74
|
hist1->Sumw2(); // makes statistical error bars
|
75
|
double norm_hist1 = hist1->Integral();
|
76
|
if(normalise == true)
|
77
|
hist1->Scale(1.0/norm_hist1);
|
78
|
|
79
|
double norm_hist2 = hist2->Integral();
|
80
|
if(normalise == true)
|
81
|
hist2->Scale(1.0/norm_hist2);
|
82
|
|
83
|
|
84
|
std::cout << "Hist 1 entries: " << norm_hist1 << ", Hist 2 entries: "<< norm_hist2 << "\n";
|
85
|
|
86
|
hist1->SetMarkerStyle(20);
|
87
|
hist1->SetMarkerSize(0.5);
|
88
|
hist1->SetMarkerColor(kBlack);
|
89
|
hist1->SetLineColor(kBlack);
|
90
|
|
91
|
hist2->SetLineStyle(1);
|
92
|
hist2->SetLineWidth(1);
|
93
|
hist2->SetLineColor(kBlack);
|
94
|
hist2->SetFillColor(kOrange-2);
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
THStack* hist_stack = new THStack("hist_stack", "some_title");
|
100
|
|
101
|
hist_stack->Add(hist2, "hist");
|
102
|
hist_stack->Add(hist1, "e1");
|
103
|
|
104
|
|
105
|
string axis_title = ";" + string(hist1->GetXaxis()->GetTitle());
|
106
|
|
107
|
hist_stack->SetTitle(axis_title.c_str());
|
108
|
|
109
|
|
110
|
TLegend legend(0.65, 0.75, 0.89, 0.89);
|
111
|
legend.AddEntry(hist1, legend1.c_str(), "ELP");
|
112
|
legend.AddEntry(hist2, legend2.c_str(), "LF");
|
113
|
|
114
|
|
115
|
|
116
|
TCanvas c("c", "c");
|
117
|
c.SetBorderSize(0);
|
118
|
|
119
|
hist_stack->Draw("nostack");
|
120
|
|
121
|
hist_stack->GetXaxis()->SetTitleSize(.05);
|
122
|
hist_stack->GetXaxis()->SetLabelSize(.05);
|
123
|
hist_stack->GetYaxis()->SetLabelSize(.05);
|
124
|
c.Update();
|
125
|
|
126
|
double y_min = c.GetUymin();
|
127
|
double y_max = c.GetUymax();
|
128
|
|
129
|
|
130
|
// Now sort out any cut-indicators:
|
131
|
// if(cut_lower != TMath::Infinity()){
|
132
|
// make a lower-boundary line
|
133
|
TLine lower_line(cut_lower, y_min, cut_lower, y_max);
|
134
|
lower_line.SetLineColor(kBlack);
|
135
|
lower_line.SetLineWidth(3);
|
136
|
lower_line.Draw();
|
137
|
// }
|
138
|
|
139
|
|
140
|
// if(cut_upper != TMath::Infinity()){
|
141
|
// make a lower-boundary line
|
142
|
TLine upper_line(cut_upper, y_min, cut_upper, y_max);
|
143
|
upper_line.SetLineColor(kBlack);
|
144
|
upper_line.SetLineWidth(3);
|
145
|
upper_line.Draw();
|
146
|
|
147
|
|
148
|
|
149
|
// }
|
150
|
|
151
|
// c.Update();
|
152
|
legend.SetTextSize(.05);
|
153
|
legend.Draw();
|
154
|
|
155
|
|
156
|
|
157
|
c.Print(saveAs.c_str());
|
158
|
|
159
|
}
|
160
|
|
161
|
|
162
|
|
163
|
|
164
|
|
165
|
void ApplyPlotStyle::Hist1D_single(TH1F* hist, string saveAs="output.pdf", double cut_lower=TMath::Infinity(), double cut_upper=TMath::Infinity(), string legend1="Data", bool isData=true){
|
166
|
|
167
|
|
168
|
hist->Sumw2(); // makes statistical error bars
|
169
|
|
170
|
if(isData == true){
|
171
|
hist->SetMarkerStyle(20);
|
172
|
hist->SetMarkerSize(0.5);
|
173
|
hist->SetMarkerColor(kBlack);
|
174
|
hist->SetLineColor(kBlack);
|
175
|
}
|
176
|
else{
|
177
|
hist->SetLineStyle(1);
|
178
|
hist->SetLineWidth(1);
|
179
|
hist->SetLineColor(kBlack);
|
180
|
hist->SetFillColor(kOrange-2);
|
181
|
}
|
182
|
|
183
|
|
184
|
|
185
|
TLegend legend(0.65, 0.75, 0.89, 0.89);
|
186
|
legend.AddEntry(hist, legend1.c_str(), "ELP");
|
187
|
|
188
|
TCanvas c("c", "c");
|
189
|
c.SetBorderSize(0);
|
190
|
|
191
|
hist->Draw("hist");
|
192
|
|
193
|
hist->GetXaxis()->SetTitleSize(.05);
|
194
|
hist->GetXaxis()->SetLabelSize(.05);
|
195
|
hist->GetYaxis()->SetLabelSize(.05);
|
196
|
c.Update();
|
197
|
|
198
|
double y_min = c.GetUymin();
|
199
|
double y_max = c.GetUymax();
|
200
|
|
201
|
// Now sort out any cut-indicators:
|
202
|
// if(cut_lower != TMath::Infinity()){
|
203
|
// make a lower-boundary line
|
204
|
TLine lower_line(cut_lower, y_min, cut_lower, y_max);
|
205
|
lower_line.SetLineColor(kBlack);
|
206
|
lower_line.SetLineWidth(3);
|
207
|
lower_line.Draw();
|
208
|
// }
|
209
|
|
210
|
|
211
|
// if(cut_upper != TMath::Infinity()){
|
212
|
// make a lower-boundary line
|
213
|
TLine upper_line(cut_upper, y_min, cut_upper, y_max);
|
214
|
upper_line.SetLineColor(kBlack);
|
215
|
upper_line.SetLineWidth(3);
|
216
|
upper_line.Draw();
|
217
|
|
218
|
|
219
|
|
220
|
// }
|
221
|
|
222
|
// c.Update();
|
223
|
legend.SetTextSize(.05);
|
224
|
legend.Draw();
|
225
|
|
226
|
|
227
|
|
228
|
c.Print(saveAs.c_str());
|
229
|
|
230
|
}
|
231
|
|
232
|
|
233
|
|
234
|
|
235
|
void ApplyPlotStyle::Hist2D(TH2F* data_hist, TH2F* mc_hist, string saveAs, double cut_a_lower, double cut_a_upper, double cut_b_lower, double cut_b_upper, int legend_location, bool normalise, string legend1, string legend2){
|
236
|
|
237
|
/*
|
238
|
* Stack data and MC hists together onto one plot:
|
239
|
* - Normalise to 1
|
240
|
* - Set plot style
|
241
|
* - Stack
|
242
|
|
243
|
* Legend (stats box) location:
|
244
|
* 0: no legend
|
245
|
* 1: top left
|
246
|
* 2: top right
|
247
|
* 3: bottom left
|
248
|
* 4: bottom right
|
249
|
*/
|
250
|
|
251
|
|
252
|
double norm_data = data_hist->GetMaximum();
|
253
|
std::cout << "Max in data hist = " << norm_data << "\n";
|
254
|
|
255
|
double norm_mc = mc_hist->GetMaximum();
|
256
|
std::cout << "Max in mc hist = " << norm_mc << "\n";
|
257
|
|
258
|
if(normalise == true){
|
259
|
|
260
|
if(norm_data > norm_mc){
|
261
|
data_hist->SetMinimum(0.0);
|
262
|
data_hist->SetMaximum(norm_data);
|
263
|
|
264
|
mc_hist->SetMinimum(0.0);
|
265
|
mc_hist->SetMaximum(norm_data);
|
266
|
}
|
267
|
else{
|
268
|
data_hist->SetMinimum(0.0);
|
269
|
data_hist->SetMaximum(norm_mc);
|
270
|
|
271
|
mc_hist->SetMinimum(0.0);
|
272
|
mc_hist->SetMaximum(norm_mc);
|
273
|
}
|
274
|
}
|
275
|
|
276
|
data_hist->GetYaxis()->SetTitleOffset(1.5);
|
277
|
mc_hist->GetYaxis()->SetTitleOffset(1.5);
|
278
|
data_hist->GetXaxis()->SetTitleSize(.05);
|
279
|
data_hist->GetYaxis()->SetTitleSize(.05);
|
280
|
data_hist->GetXaxis()->SetLabelSize(.05);
|
281
|
data_hist->GetYaxis()->SetLabelSize(.05);
|
282
|
data_hist->GetZaxis()->SetLabelSize(.05);
|
283
|
|
284
|
mc_hist->GetXaxis()->SetTitleSize(.05);
|
285
|
mc_hist->GetYaxis()->SetTitleSize(.05);
|
286
|
mc_hist->GetXaxis()->SetLabelSize(.05);
|
287
|
mc_hist->GetYaxis()->SetLabelSize(.05);
|
288
|
mc_hist->GetZaxis()->SetLabelSize(.05);
|
289
|
|
290
|
data_hist->SetTitle(legend1.c_str());
|
291
|
mc_hist->SetTitle(legend2.c_str());
|
292
|
|
293
|
|
294
|
|
295
|
TCanvas c("c", "c", 800, 400);
|
296
|
c.Divide(2, 1);
|
297
|
|
298
|
c.SetFillColor(0);
|
299
|
c.SetFrameFillStyle(0);
|
300
|
|
301
|
c.cd(1);
|
302
|
data_hist->Draw("colz");
|
303
|
|
304
|
c.cd(2);
|
305
|
mc_hist->Draw("colz");
|
306
|
|
307
|
|
308
|
if(legend_location == 1){
|
309
|
gStyle->SetStatX(0.33);
|
310
|
gStyle->SetStatY(0.88);
|
311
|
gStyle->SetOptStat("emr");
|
312
|
}
|
313
|
else if(legend_location == 2){
|
314
|
gStyle->SetStatX(0.88);
|
315
|
gStyle->SetStatY(0.88);
|
316
|
gStyle->SetOptStat("emr");
|
317
|
}
|
318
|
else if(legend_location == 3){
|
319
|
gStyle->SetStatX(0.33);
|
320
|
gStyle->SetStatY(0.38);
|
321
|
gStyle->SetOptStat("emr");
|
322
|
}
|
323
|
else if(legend_location == 4){
|
324
|
gStyle->SetStatX(0.88);
|
325
|
gStyle->SetStatY(0.38);
|
326
|
gStyle->SetOptStat("emr");
|
327
|
}
|
328
|
else{
|
329
|
gStyle->SetOptStat(0);
|
330
|
}
|
331
|
|
332
|
|
333
|
c.cd(1);
|
334
|
gPad->Update();
|
335
|
/*
|
336
|
TPaletteAxis *palette = (TPaletteAxis*)data_hist->GetListOfFunctions()->FindObject("palette");
|
337
|
// the following lines moe the paletter. Choose the values you need for the position.
|
338
|
palette->SetX1NDC(0.9);
|
339
|
palette->SetX2NDC(0.92);
|
340
|
palette->SetY1NDC(0.1);
|
341
|
palette->SetY2NDC(0.9);
|
342
|
gPad->Modified();
|
343
|
gPad->Update();
|
344
|
*/
|
345
|
|
346
|
double x_min = gPad->GetUxmin();
|
347
|
double x_max = gPad->GetUxmax();
|
348
|
|
349
|
double y_min = gPad->GetUymin();
|
350
|
double y_max = gPad->GetUymax();
|
351
|
|
352
|
// Now sort out any cut-indicators:
|
353
|
// if(cut_a_lower != TMath::Infinity()){
|
354
|
// make a lower-boundary line
|
355
|
TLine lower_a_line(cut_a_lower, y_min, cut_a_lower, y_max);
|
356
|
lower_a_line.SetLineColor(kBlack);
|
357
|
lower_a_line.SetLineWidth(3);
|
358
|
lower_a_line.Draw();
|
359
|
// }
|
360
|
|
361
|
|
362
|
// if(cut_a_upper != TMath::Infinity()){
|
363
|
// make a lower-boundary line
|
364
|
TLine upper_a_line(cut_a_upper, y_min, cut_a_upper, y_max);
|
365
|
upper_a_line.SetLineColor(kBlack);
|
366
|
upper_a_line.SetLineWidth(3);
|
367
|
upper_a_line.Draw();
|
368
|
// }
|
369
|
|
370
|
// if(cut_b_lower != TMath::Infinity()){
|
371
|
// make a lower-boundary line
|
372
|
TLine lower_b_line(x_min, cut_b_lower, x_max, cut_b_lower);
|
373
|
lower_b_line.SetLineColor(kBlack);
|
374
|
lower_b_line.SetLineWidth(3);
|
375
|
lower_b_line.Draw();
|
376
|
// }
|
377
|
|
378
|
|
379
|
// if(cut_b_upper != TMath::Infinity()){
|
380
|
// make a lower-boundary line
|
381
|
TLine upper_b_line(x_min, cut_b_upper, x_max, cut_b_upper);
|
382
|
upper_b_line.SetLineColor(kBlack);
|
383
|
upper_b_line.SetLineWidth(3);
|
384
|
upper_b_line.Draw();
|
385
|
// }
|
386
|
|
387
|
|
388
|
c.cd(2);
|
389
|
gPad->Update();
|
390
|
|
391
|
x_min = gPad->GetUxmin();
|
392
|
x_max = gPad->GetUxmax();
|
393
|
|
394
|
y_min = gPad->GetUymin();
|
395
|
y_max = gPad->GetUymax();
|
396
|
|
397
|
// Now sort out any cut-indicators:
|
398
|
// if(cut_a_lower != TMath::Infinity()){
|
399
|
// make a lower-boundary line
|
400
|
TLine mc_lower_a_line(cut_a_lower, y_min, cut_a_lower, y_max);
|
401
|
mc_lower_a_line.SetLineColor(kBlack);
|
402
|
mc_lower_a_line.SetLineWidth(3);
|
403
|
mc_lower_a_line.Draw();
|
404
|
// }
|
405
|
|
406
|
|
407
|
// if(cut_a_upper != TMath::Infinity()){
|
408
|
// make a lower-boundary line
|
409
|
TLine mc_upper_a_line(cut_a_upper, y_min, cut_a_upper, y_max);
|
410
|
mc_upper_a_line.SetLineColor(kBlack);
|
411
|
mc_upper_a_line.SetLineWidth(3);
|
412
|
mc_upper_a_line.Draw();
|
413
|
// }
|
414
|
|
415
|
// if(cut_b_lower != TMath::Infinity()){
|
416
|
// make a lower-boundary line
|
417
|
TLine mc_lower_b_line(x_min, cut_b_lower, x_max, cut_b_lower);
|
418
|
mc_lower_b_line.SetLineColor(kBlack);
|
419
|
mc_lower_b_line.SetLineWidth(3);
|
420
|
mc_lower_b_line.Draw();
|
421
|
// }
|
422
|
|
423
|
|
424
|
// if(cut_b_upper != TMath::Infinity()){
|
425
|
// make a lower-boundary line
|
426
|
TLine mc_upper_b_line(x_min, cut_b_upper, x_max, cut_b_upper);
|
427
|
mc_upper_b_line.SetLineColor(kBlack);
|
428
|
mc_upper_b_line.SetLineWidth(3);
|
429
|
mc_upper_b_line.Draw();
|
430
|
// }
|
431
|
|
432
|
c.Print(saveAs.c_str());
|
433
|
|
434
|
|
435
|
|
436
|
}
|
437
|
|
438
|
|
439
|
|
440
|
|
441
|
|
442
|
void ApplyPlotStyle::Hist_TOFvTKU(TH2F* data_hist, TH2F* mc_hist, string saveAs, double mean_dP, double min_dP, double max_dP, int legend_location, bool normalise, string legend1, string legend2){
|
443
|
|
444
|
/*
|
445
|
* Stack data and MC hists together onto one plot:
|
446
|
* - Normalise to 1
|
447
|
* - Set plot style
|
448
|
* - Stack
|
449
|
|
450
|
* Legend (stats box) location:
|
451
|
* 0: no legend
|
452
|
* 1: top left
|
453
|
* 2: top right
|
454
|
* 3: bottom left
|
455
|
* 4: bottom right
|
456
|
*/
|
457
|
|
458
|
|
459
|
double norm_data = data_hist->GetMaximum();
|
460
|
std::cout << "Max in data hist = " << norm_data << "\n";
|
461
|
|
462
|
double norm_mc = mc_hist->GetMaximum();
|
463
|
std::cout << "Max in mc hist = " << norm_mc << "\n";
|
464
|
|
465
|
if(normalise == true){
|
466
|
|
467
|
// if(norm_data > norm_mc){
|
468
|
data_hist->SetMinimum(0.0);
|
469
|
data_hist->SetMaximum(norm_data);
|
470
|
|
471
|
mc_hist->SetMinimum(0.0);
|
472
|
mc_hist->SetMaximum(norm_data);
|
473
|
// }
|
474
|
/* else{
|
475
|
data_hist->SetMinimum(0.0);
|
476
|
data_hist->SetMaximum(norm_mc);
|
477
|
|
478
|
mc_hist->SetMinimum(0.0);
|
479
|
mc_hist->SetMaximum(norm_mc);
|
480
|
}
|
481
|
*/
|
482
|
}
|
483
|
|
484
|
data_hist->GetYaxis()->SetTitleOffset(1.5);
|
485
|
mc_hist->GetYaxis()->SetTitleOffset(1.5);
|
486
|
|
487
|
data_hist->SetTitle(legend1.c_str());
|
488
|
mc_hist->SetTitle(legend2.c_str());
|
489
|
|
490
|
data_hist->GetXaxis()->SetTitleSize(.05);
|
491
|
data_hist->GetYaxis()->SetTitleSize(.05);
|
492
|
data_hist->GetXaxis()->SetLabelSize(.05);
|
493
|
data_hist->GetYaxis()->SetLabelSize(.05);
|
494
|
data_hist->GetZaxis()->SetLabelSize(.05);
|
495
|
|
496
|
mc_hist->GetXaxis()->SetTitleSize(.05);
|
497
|
mc_hist->GetYaxis()->SetTitleSize(.05);
|
498
|
mc_hist->GetXaxis()->SetLabelSize(.05);
|
499
|
mc_hist->GetYaxis()->SetLabelSize(.05);
|
500
|
mc_hist->GetZaxis()->SetLabelSize(.05);
|
501
|
|
502
|
TCanvas c("c", "c", 800, 400);
|
503
|
c.Divide(2, 1);
|
504
|
|
505
|
c.SetFillColor(0);
|
506
|
c.SetFrameFillStyle(0);
|
507
|
|
508
|
c.cd(1);
|
509
|
data_hist->Draw("colz");
|
510
|
|
511
|
c.cd(2);
|
512
|
mc_hist->Draw("colz");
|
513
|
|
514
|
|
515
|
if(legend_location == 1){
|
516
|
gStyle->SetStatX(0.33);
|
517
|
gStyle->SetStatY(0.88);
|
518
|
gStyle->SetOptStat("emr");
|
519
|
}
|
520
|
else if(legend_location == 2){
|
521
|
gStyle->SetStatX(0.88);
|
522
|
gStyle->SetStatY(0.88);
|
523
|
gStyle->SetOptStat("emr");
|
524
|
}
|
525
|
else if(legend_location == 3){
|
526
|
gStyle->SetStatX(0.33);
|
527
|
gStyle->SetStatY(0.38);
|
528
|
gStyle->SetOptStat("emr");
|
529
|
}
|
530
|
else if(legend_location == 4){
|
531
|
gStyle->SetStatX(0.88);
|
532
|
gStyle->SetStatY(0.38);
|
533
|
gStyle->SetOptStat("emr");
|
534
|
}
|
535
|
else{
|
536
|
gStyle->SetOptStat(0);
|
537
|
}
|
538
|
|
539
|
|
540
|
c.cd(1);
|
541
|
|
542
|
|
543
|
|
544
|
TF1 *f1 = new TF1("testfunc", tofFunc, -1.0, 351.0, 2);
|
545
|
f1->SetParameter(0, 105.668);
|
546
|
f1->SetParameter(1, mean_dP);
|
547
|
|
548
|
TF1 *f2 = new TF1("testfunc", tofFunc, -1.0, 351.0, 2);
|
549
|
f2->SetParameter(0, 105.668);
|
550
|
f2->SetParameter(1, min_dP);
|
551
|
|
552
|
TF1 *f3 = new TF1("testfunc", tofFunc, -1.0, 351.0, 2);
|
553
|
f3->SetParameter(0, 105.668);
|
554
|
f3->SetParameter(1, max_dP);
|
555
|
|
556
|
f1->SetLineStyle(3);
|
557
|
f1->SetLineColor(kWhite);
|
558
|
f1->Draw("same,APL");
|
559
|
|
560
|
f2->SetLineColor(kBlack);
|
561
|
f2->SetLineWidth(3);
|
562
|
f2->Draw("same,APL");
|
563
|
|
564
|
f3->SetLineColor(kBlack);
|
565
|
f3->SetLineWidth(3);
|
566
|
f3->Draw("same,APL");
|
567
|
|
568
|
|
569
|
|
570
|
|
571
|
|
572
|
gPad->Update();
|
573
|
/*
|
574
|
TPaletteAxis *palette = (TPaletteAxis*)data_hist->GetListOfFunctions()->FindObject("palette");
|
575
|
// the following lines moe the paletter. Choose the values you need for the position.
|
576
|
palette->SetX1NDC(0.9);
|
577
|
palette->SetX2NDC(0.92);
|
578
|
palette->SetY1NDC(0.1);
|
579
|
palette->SetY2NDC(0.9);
|
580
|
gPad->Modified();
|
581
|
gPad->Update();
|
582
|
*/
|
583
|
|
584
|
|
585
|
|
586
|
c.cd(2);
|
587
|
|
588
|
f1->Draw("same,APL");
|
589
|
f2->Draw("same,APL");
|
590
|
f3->Draw("same,APL");
|
591
|
gPad->Update();
|
592
|
|
593
|
|
594
|
|
595
|
|
596
|
c.Print(saveAs.c_str());
|
597
|
|
598
|
|
599
|
|
600
|
}
|
601
|
|
602
|
|
603
|
|
604
|
Double_t ApplyPlotStyle::tofFunc(Double_t *x, Double_t *par){
|
605
|
Double_t m = par[0];
|
606
|
Double_t dP = par[1];
|
607
|
|
608
|
double tof1_z = 12929.4396e-3; // m
|
609
|
double tof0_z = 5285.6636e-3; // m
|
610
|
double L = tof1_z - tof0_z;
|
611
|
|
612
|
Double_t p_tku = x[0];
|
613
|
|
614
|
double p = p_tku + dP;
|
615
|
|
616
|
double t = L * TMath::Sqrt(m*m + p*p) / (TMath::C()*p);
|
617
|
|
618
|
return t/1.0e-9;
|
619
|
}
|
620
|
|
621
|
|
622
|
|
623
|
|
624
|
|
625
|
void ApplyPlotStyle::Hist2D_single(TH2F* data_hist, string saveAs="output.pdf", double cut_a_lower=TMath::Infinity(), double cut_a_upper=TMath::Infinity(), double cut_b_lower=TMath::Infinity(), double cut_b_upper=TMath::Infinity(), int legend_location=0,bool normalise=true, string legend1="Data"){
|
626
|
|
627
|
/*
|
628
|
* Stack data and MC hists together onto one plot:
|
629
|
* - Normalise to 1
|
630
|
* - Set plot style
|
631
|
* - Stack
|
632
|
|
633
|
* Legend (stats box) location:
|
634
|
* 0: no legend
|
635
|
* 1: top left
|
636
|
* 2: top right
|
637
|
* 3: bottom left
|
638
|
* 4: bottom right
|
639
|
*/
|
640
|
|
641
|
// data_hist->GetYaxis()->SetTitleOffset(1.5);
|
642
|
data_hist->GetXaxis()->SetTitleSize(.05);
|
643
|
data_hist->GetYaxis()->SetTitleSize(.05);
|
644
|
data_hist->GetXaxis()->SetLabelSize(.05);
|
645
|
data_hist->GetYaxis()->SetLabelSize(.05);
|
646
|
data_hist->GetZaxis()->SetLabelSize(.05);
|
647
|
|
648
|
|
649
|
data_hist->SetTitle(legend1.c_str());
|
650
|
|
651
|
|
652
|
|
653
|
|
654
|
TCanvas c("c", "c", 800, 800);
|
655
|
data_hist->Draw("colz");
|
656
|
|
657
|
if(legend_location == 1){
|
658
|
gStyle->SetStatX(0.33);
|
659
|
gStyle->SetStatY(0.88);
|
660
|
gStyle->SetOptStat("emr");
|
661
|
}
|
662
|
else if(legend_location == 2){
|
663
|
gStyle->SetStatX(0.88);
|
664
|
gStyle->SetStatY(0.88);
|
665
|
gStyle->SetOptStat("emr");
|
666
|
}
|
667
|
else if(legend_location == 3){
|
668
|
gStyle->SetStatX(0.33);
|
669
|
gStyle->SetStatY(0.38);
|
670
|
gStyle->SetOptStat("emr");
|
671
|
}
|
672
|
else if(legend_location == 4){
|
673
|
gStyle->SetStatX(0.88);
|
674
|
gStyle->SetStatY(0.38);
|
675
|
gStyle->SetOptStat("emr");
|
676
|
}
|
677
|
else{
|
678
|
gStyle->SetOptStat(0);
|
679
|
}
|
680
|
|
681
|
gPad->Update();
|
682
|
|
683
|
double x_min = gPad->GetUxmin();
|
684
|
double x_max = gPad->GetUxmax();
|
685
|
|
686
|
double y_min = gPad->GetUymin();
|
687
|
double y_max = gPad->GetUymax();
|
688
|
|
689
|
// Now sort out any cut-indicators:
|
690
|
if(cut_a_lower != TMath::Infinity()){
|
691
|
// make a lower-boundary line
|
692
|
TLine lower_a_line(cut_a_lower, y_min, cut_a_lower, y_max);
|
693
|
lower_a_line.SetLineColor(kBlack);
|
694
|
lower_a_line.SetLineWidth(3);
|
695
|
lower_a_line.Draw();
|
696
|
}
|
697
|
|
698
|
|
699
|
if(cut_a_upper != TMath::Infinity()){
|
700
|
// make a lower-boundary line
|
701
|
TLine upper_a_line(cut_a_upper, y_min, cut_a_upper, y_max);
|
702
|
upper_a_line.SetLineColor(kBlack);
|
703
|
upper_a_line.SetLineWidth(3);
|
704
|
upper_a_line.Draw();
|
705
|
}
|
706
|
|
707
|
if(cut_b_lower != TMath::Infinity()){
|
708
|
// make a lower-boundary line
|
709
|
TLine lower_b_line(x_min, cut_b_lower, x_max, cut_b_lower);
|
710
|
lower_b_line.SetLineColor(kBlack);
|
711
|
lower_b_line.SetLineWidth(3);
|
712
|
lower_b_line.Draw();
|
713
|
}
|
714
|
|
715
|
|
716
|
if(cut_b_upper != TMath::Infinity()){
|
717
|
// make a lower-boundary line
|
718
|
TLine upper_b_line(x_min, cut_b_upper, x_max, cut_b_upper);
|
719
|
upper_b_line.SetLineColor(kBlack);
|
720
|
upper_b_line.SetLineWidth(3);
|
721
|
upper_b_line.Draw();
|
722
|
}
|
723
|
|
724
|
|
725
|
|
726
|
c.Print(saveAs.c_str());
|
727
|
}
|