-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeutrinoDirectionalityPlots.cc
517 lines (420 loc) · 19.5 KB
/
NeutrinoDirectionalityPlots.cc
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
#include "DirectionalityPlots.h"
#include "Formatting.h"
#include "Plotter.h"
using std::string, std::cout, std::array;
void MakeDisplacementPlots(array<array<array<std::shared_ptr<TH1F>, DirectionSize>, SignalSize>, DatasetSize> const& histogram)
{
// Taking ownership of histograms
TH1::AddDirectory(kFALSE);
for (int dataset = Data; dataset < DatasetSize; dataset++)
{
for (int direction = X; direction < Z; direction++)
{
string plotName = DatasetToString(dataset) + " Displacement " + AxisToString(direction);
string histName = DatasetToString(dataset);
// Setting up canvas, no top margin because no title
TCanvas canvas(plotName.c_str(), plotName.c_str());
canvas.SetCanvasSize(2000, 1700);
canvas.SetTopMargin(0.05);
canvas.Update();
// Temporary histogram for x and y because we want a 3 bin plot
TH1F tempHist(histName.c_str(), histName.c_str(), 3, 0, 3);
// Setting up where to get the values from
int lowBin, highBin, mediumBin = 151;
// These come from the main analysis code
lowBin = 5;
highBin = 297;
// Grabbing values from the main histograms
tempHist.SetBinContent(1, histogram[dataset][TotalDifference][direction]->GetBinContent(lowBin));
tempHist.SetBinError(1, histogram[dataset][TotalDifference][direction]->GetBinError(lowBin));
tempHist.SetBinContent(2, histogram[dataset][TotalDifference][direction]->GetBinContent(mediumBin));
tempHist.SetBinError(2, histogram[dataset][TotalDifference][direction]->GetBinError(mediumBin));
tempHist.SetBinContent(3, histogram[dataset][TotalDifference][direction]->GetBinContent(highBin));
tempHist.SetBinError(3, histogram[dataset][TotalDifference][direction]->GetBinError(highBin));
// Setting up titles and draw styles
if (direction == X)
tempHist.GetXaxis()->SetTitle("#bf{#it{s}}_{#it{x}}: Delayed - Prompt");
else
tempHist.GetXaxis()->SetTitle("#bf{#it{s}}_{#it{y}}: Delayed - Prompt");
tempHist.GetYaxis()->SetTitle("IBD Events");
tempHist.SetLineColor(kRed);
tempHist.SetLineWidth(9);
tempHist.SetLineStyle(1);
tempHist.SetMarkerStyle(20);
tempHist.SetMarkerSize(1.3);
tempHist.SetMarkerColor(kBlack);
// Applying header function
SetTitleStyles(&tempHist);
// Custom labels and size
// For some reason the label size that's normal on other plots is tiny for the X labels here
tempHist.GetXaxis()->SetBinLabel(1, "-D");
tempHist.GetXaxis()->SetBinLabel(2, "0");
tempHist.GetXaxis()->SetBinLabel(3, "D");
tempHist.GetXaxis()->SetLabelSize(0.07);
tempHist.Draw("HISTS ][");
tempHist.GetXaxis()->SetTitleSize(0.062);
tempHist.GetYaxis()->SetTitleSize(0.062);
string fullPath = plotDirectory + "/" + plotName + ".png";
canvas.SaveAs(fullPath.c_str());
}
// Different plot style for Z
string plotName = DatasetToString(dataset) + " Displacement Z";
string histName = DatasetToString(dataset);
// Setting up canvas, no top margin because no title
TCanvas canvas(plotName.c_str(), plotName.c_str(), 2000, 1700);
canvas.SetCanvasSize(2000, 1700);
canvas.SetTopMargin(0.025);
auto tempHist = std::unique_ptr<TH1F>(static_cast<TH1F*>(histogram[dataset][TotalDifference][Z]->Clone()));
// Setting up titles and draw styles
tempHist->GetXaxis()->SetTitle("#bf{#it{s}}_{#it{z}}: Delayed - Prompt (mm)");
tempHist->GetYaxis()->SetTitle("IBD Events");
tempHist->SetLineColor(kRed);
tempHist->SetLineWidth(4);
tempHist->SetLineStyle(1);
tempHist->SetMarkerStyle(20);
tempHist->SetMarkerSize(1);
tempHist->SetMarkerColor(kRed);
// Applying header function
SetTitleStyles(tempHist.get());
// Setting up fit
TF1 gaussian("Fit", "gaus", -140, 140);
gaussian.SetLineColor(kBlue);
gaussian.SetLineWidth(4);
gaussian.SetLineStyle(1);
tempHist->Fit("Fit", "RQ");
string zMean = Form("%.2f", gaussian.GetParameter(1));
string zError = Form("%.2f", gaussian.GetParError(1));
string zSigma = Form("%.2f", gaussian.GetParameter(2));
string zSigmaError = Form("%.2f", gaussian.GetParError(2));
int zChiSquare = round(gaussian.GetChisquare());
int zNDF = gaussian.GetNDF();
string zChi2 = Form("%i", zChiSquare);
string zNDFText = Form("%i", zNDF);
string zChi2NDF = "#frac{" + zChi2 + "}{" + zNDFText + "}";
tempHist->Draw("P E1 X0");
tempHist->GetXaxis()->SetTitleSize(0.062);
tempHist->GetYaxis()->SetTitleSize(0.062);
tempHist->GetYaxis()->SetRangeUser(0, 450);
// Setting up legend
float x_legend = 0.6;
float y_legend = 0.7;
TLegend legend(0.30, 0.9, 0.95, 0.975);
legend.SetFillColor(0);
legend.SetFillStyle(0);
// legend.SetTextFont(82);
legend.SetTextSize(0.04);
// legend->SetHeader("Fit Parameters", "C");
string meanText = "Gaussian fit, #it{#mu} = " + zMean + " #pm " + zError + " mm";
legend.AddEntry(&gaussian, meanText.c_str(), "l");
/* string sigmaText = "#sigma: " + zSigma;
legend.AddEntry(&gaussian, sigmaText.c_str(), "l");
string chiSquareText = "#frac{#chi^{2}}{ndf}: " + zChi2NDF;
legend.AddEntry(&gaussian, chiSquareText.c_str(), "l"); */
legend.Draw();
string fullPath = plotDirectory + "/" + plotName + ".png";
canvas.SaveAs(fullPath.c_str());
cout << "Z Mean for " << boldOn << DatasetToString(dataset) << " = " << zMean << " ± " << zError << resetFormats << '\n';
cout << "Z Sigma for " << boldOn << DatasetToString(dataset) << " = " << zSigma << " ± " << zSigmaError << resetFormats
<< '\n';
}
}
void MakeSimulationPlot(FinalValues const& finalValues)
{
// Setting up canvas, no top margin because no title
TCanvas canvas("Angles", "Angles");
canvas.SetCanvasSize(1600, 1550);
canvas.SetTopMargin(0.05);
canvas.SetBottomMargin(0.125);
// Need to draw a frame to set bounds
auto frame = canvas.DrawFrame(93, 34.8, 105, 47.8);
// Setting up axis labels
frame->GetXaxis()->SetTitle("#theta (deg)");
frame->GetYaxis()->SetTitle("#phi (deg)");
frame->GetXaxis()->CenterTitle(kTRUE);
frame->GetYaxis()->CenterTitle(kTRUE);
// Making sure the font is legible
frame->GetXaxis()->SetTitleSize(0.05);
frame->GetYaxis()->SetTitleSize(0.05);
frame->GetXaxis()->SetLabelSize(0.04);
frame->GetYaxis()->SetLabelSize(0.04);
// Error ellipses for each data point
TEllipse Simulation(finalValues.theta[SimUnbiased],
finalValues.phi[SimUnbiased],
finalValues.thetaError[SimUnbiased],
finalValues.phiError[SimUnbiased],
0,
360,
finalValues.tilt[SimUnbiased]);
Simulation.SetFillColor(kRed + 2);
Simulation.SetFillStyle(3001);
Simulation.Draw();
TEllipse SimulationUncorrected(finalValues.theta[Sim],
finalValues.phi[Sim],
finalValues.thetaError[Sim],
finalValues.phiError[Sim],
0,
360,
finalValues.tilt[Sim]);
SimulationUncorrected.SetFillColor(kMagenta + 3);
SimulationUncorrected.SetFillStyle(3001);
SimulationUncorrected.Draw();
/* TEllipse PerfectSimulation(finalValues.theta[PerfSimUnbiased],
finalValues.phi[PerfSimUnbiased],
finalValues.thetaError[PerfSimUnbiased],
finalValues.phiError[PerfSimUnbiased],
0,
360,
finalValues.tilt[PerfSimUnbiased]);
PerfectSimulation.SetFillColor(kAzure + 7);
PerfectSimulation.SetFillStyle(3001);
PerfectSimulation.Draw();
TEllipse PerfectSimulationUncorrected(finalValues.theta[PerfSim],
finalValues.phi[PerfSim],
finalValues.thetaError[PerfSim],
finalValues.phiError[PerfSim],
0,
360,
finalValues.tilt[PerfSim]);
PerfectSimulationUncorrected.SetFillColor(kPink + 2);
PerfectSimulationUncorrected.SetFillStyle(3001);
PerfectSimulationUncorrected.Draw(); */
TEllipse DataStatistics(finalValues.theta[SimUnbiased],
finalValues.phi[SimUnbiased],
finalValues.thetaError[DataUnbiased],
finalValues.phiError[DataUnbiased],
0,
360,
finalValues.tilt[DataUnbiased]);
DataStatistics.SetLineColor(kAzure + 3);
DataStatistics.SetLineStyle(7);
DataStatistics.SetLineWidth(4);
DataStatistics.SetFillStyle(0);
DataStatistics.Draw();
/* TEllipse True(finalValues.thetaTrue, finalValues.phiTrue, finalValues.thetaTrueError, finalValues.phiTrueError);
True.SetFillColor(kGreen + 2);
True.SetFillStyle(3001);
True.Draw(); */
// Setting up data markers
TMarker simPoint(finalValues.theta[SimUnbiased], finalValues.phi[SimUnbiased], 29);
simPoint.SetMarkerSize(4.5);
simPoint.SetMarkerColor(kRed + 2.25);
simPoint.Draw();
TMarker simUncorrectedPoint(finalValues.theta[Sim], finalValues.phi[Sim], 43);
simUncorrectedPoint.SetMarkerSize(4.5);
simUncorrectedPoint.SetMarkerColor(kMagenta + 3.25);
simUncorrectedPoint.Draw();
/* TMarker perfSimPoint(finalValues.theta[PerfSimUnbiased], finalValues.phi[PerfSimUnbiased], 29);
perfSimPoint.SetMarkerSize(4.5);
perfSimPoint.SetMarkerColor(kAzure + 7.25);
perfSimPoint.Draw();
TMarker perfSimUncorrectedPoint(finalValues.theta[PerfSim], finalValues.phi[PerfSim], 43);
perfSimUncorrectedPoint.SetMarkerSize(4.5);
perfSimUncorrectedPoint.SetMarkerColor(kPink + 2.25);
perfSimUncorrectedPoint.Draw(); */
TMarker truePoint(finalValues.thetaTrue, finalValues.phiTrue, 33);
truePoint.SetMarkerSize(5);
truePoint.SetMarkerColor(kGreen + 2.25);
truePoint.Draw();
// Setting up line just for legend purposes
TLine statsLine(0.2, 0.2, 0.4, 0.4);
statsLine.SetLineColor(kAzure + 3);
statsLine.SetLineStyle(7);
statsLine.SetLineWidth(4);
TLegend legend(0.54, 0.75, 0.95, 0.95);
legend.SetTextFont(62);
legend.SetTextSize(0.03);
legend.AddEntry(&simPoint, "Reconstruction", "p");
legend.AddEntry(&simUncorrectedPoint, "Biased Reconstruction", "p");
/* legend.AddEntry(&perfSimPoint, "Perf Sim", "p");
legend.AddEntry(&perfSimUncorrectedPoint, "Biased Perf Sim", "p"); */
legend.AddEntry(&statsLine, "Data 1#sigma Statistics", "l");
legend.AddEntry(&truePoint, "True Neutrino Direction", "p");
legend.Draw();
TText simText(0.18, 0.85, "SIMULATION");
simText.SetNDC();
simText.SetTextAlign(12);
simText.SetTextFont(82);
simText.SetTextColor(kBlack);
simText.SetTextSize(0.06);
simText.Draw();
canvas.Update();
string fullPath = plotDirectory + "/SimulationPlot.png";
canvas.SaveAs(fullPath.c_str());
}
void MakeFinalPlot(FinalValues const& finalValues)
{
// Setting up canvas, no top margin because no title
TCanvas canvas("Angles", "Angles");
canvas.SetCanvasSize(1600, 1550);
canvas.SetTopMargin(0.05);
canvas.SetBottomMargin(0.125);
// Need to draw a frame to set bounds
auto frame = canvas.DrawFrame(93, 34.8, 105, 47.8);
// Setting up axis labels
frame->GetXaxis()->SetTitle("#theta (deg)");
frame->GetYaxis()->SetTitle("#phi (deg)");
frame->GetXaxis()->CenterTitle(kTRUE);
frame->GetYaxis()->CenterTitle(kTRUE);
// Making sure the font is legible
frame->GetXaxis()->SetTitleSize(0.05);
frame->GetYaxis()->SetTitleSize(0.05);
frame->GetXaxis()->SetLabelSize(0.04);
frame->GetYaxis()->SetLabelSize(0.04);
// Error ellipses for each data point
TEllipse Data(finalValues.theta[DataUnbiased],
finalValues.phi[DataUnbiased],
finalValues.thetaErrorSystematics[DataUnbiased],
finalValues.phiErrorSystematics[DataUnbiased],
0,
360,
finalValues.tiltSystematics[DataUnbiased]);
Data.SetLineColor(kAzure - 3);
Data.SetLineStyle(1);
Data.SetLineWidth(4);
Data.SetFillStyle(0);
Data.Draw();
TEllipse DataStatistics(finalValues.theta[DataUnbiased],
finalValues.phi[DataUnbiased],
finalValues.thetaError[DataUnbiased],
finalValues.phiError[DataUnbiased],
0,
360,
finalValues.tilt[DataUnbiased]);
DataStatistics.SetLineColor(kAzure + 3);
DataStatistics.SetLineStyle(7);
DataStatistics.SetLineWidth(4);
DataStatistics.SetFillStyle(0);
DataStatistics.Draw();
/* TEllipse Simulation(finalValues.theta[SimUnbiased],
finalValues.phi[SimUnbiased],
finalValues.thetaError[SimUnbiased],
finalValues.phiError[SimUnbiased],
0,
360,
finalValues.tilt[SimUnbiased]);
Simulation.SetFillColor(kRed + 2);
Simulation.SetFillStyle(3001);
Simulation.Draw(); */
TEllipse True(finalValues.thetaTrue, finalValues.phiTrue, finalValues.thetaTrueError, finalValues.phiTrueError);
True.SetFillColor(kGreen + 2);
True.SetFillStyle(3001);
True.Draw();
// Setting up data markers
TMarker dataPoint(finalValues.theta[DataUnbiased], finalValues.phi[DataUnbiased], 43);
dataPoint.SetMarkerSize(5.5);
dataPoint.SetMarkerColor(kAzure - 2.25);
dataPoint.Draw();
TMarker dataStatisticsPoint(finalValues.theta[DataUnbiased], finalValues.phi[DataUnbiased], 43);
dataStatisticsPoint.SetMarkerSize(5.5);
dataStatisticsPoint.SetMarkerColor(kAzure + 3);
/* TMarker simPoint(finalValues.theta[SimUnbiased], finalValues.phi[SimUnbiased], 29);
simPoint.SetMarkerSize(4.5);
simPoint.SetMarkerColor(kRed + 2.25);
simPoint.Draw();*/
TMarker truePoint(finalValues.thetaTrue, finalValues.phiTrue, 33);
truePoint.SetMarkerSize(5);
truePoint.SetMarkerColor(kGreen + 2.25);
truePoint.Draw();
// Setting up line just for legend purposes
TLine statsLine(0.2, 0.2, 0.4, 0.4);
statsLine.SetLineColor(kAzure + 3);
statsLine.SetLineStyle(7);
statsLine.SetLineWidth(4);
TLine dataLine(0.2, 0.2, 0.4, 0.4);
dataLine.SetLineColor(kAzure - 3);
dataLine.SetLineStyle(1);
dataLine.SetLineWidth(4);
TLegend legend(0.38, 0.75, 0.95, 0.95);
legend.SetTextFont(62);
legend.SetTextSize(0.03);
legend.AddEntry(&dataPoint, "Mean Reconstructed #bar{#nu}_{e} Direction", "p");
legend.AddEntry(&dataLine, "1#sigma", "l");
legend.AddEntry(&statsLine, "1#sigma Statistics Only", "l");
// legend.AddEntry(&simPoint, "Simulation", "p");
legend.AddEntry(&truePoint, "Reactor to Detector Direction", "p");
legend.Draw();
TText dataText(0.22, 0.85, "DATA");
dataText.SetNDC();
dataText.SetTextAlign(12);
dataText.SetTextFont(82);
dataText.SetTextColor(kBlack);
dataText.SetTextSize(0.06);
dataText.Draw();
string fullPath = plotDirectory + "/FinalPlot.png";
canvas.SaveAs(fullPath.c_str());
}
int NeutrinoDirectionalityPlots()
{
// Taking ownership of TH1 pointers
TH1::AddDirectory(kFALSE);
// Don't open the canvases and then destroy them
gROOT->SetBatch(kTRUE);
// Setting up some basic padding and removing statistics boxes
SetBasicPlotStyle();
// Where we want our plots saved
plotDirectory = "DirectionalityPlots";
// Checking if the directory already exists, making it if not
SetPlotDirectory(plotDirectory);
// Setting up what we need to plot
array<array<array<std::shared_ptr<TH1F>, DirectionSize>, SignalSize>, DatasetSize> histogram;
FinalValues finalValues;
// Opening the root file
auto rootFile = std::make_unique<TFile>("Directionality.root", "read");
// Grabbing angles and errors
for (int dataset = Data; dataset < DatasetSize; dataset++)
{
// Grabbing phi
string vectorName = DatasetToString(dataset) + " Phi";
string ellipseName = vectorName + " Ellipse";
TVector3* input = (TVector3*)rootFile->Get(vectorName.c_str());
finalValues.phi[dataset] = input->X();
TVector2* inputErrors = (TVector2*)rootFile->Get(ellipseName.c_str());
finalValues.phiError[dataset] = inputErrors->X();
finalValues.phiErrorSystematics[dataset] = inputErrors->Y();
// Grabbing theta
vectorName = DatasetToString(dataset) + " Theta";
ellipseName = vectorName + " Ellipse";
input = (TVector3*)rootFile->Get(vectorName.c_str());
finalValues.theta[dataset] = input->X();
inputErrors = (TVector2*)rootFile->Get(ellipseName.c_str());
finalValues.thetaError[dataset] = inputErrors->X();
finalValues.thetaErrorSystematics[dataset] = inputErrors->Y();
// Grabbing tilt
vectorName = DatasetToString(dataset) + " Tilt Ellipse";
input = (TVector3*)rootFile->Get(vectorName.c_str());
finalValues.tilt[dataset] = input->X();
finalValues.tiltSystematics[dataset] = input->Y();
}
// Grabbing true angles
TVector2* input = (TVector2*)rootFile->Get("True Phi");
finalValues.phiTrue = input->X();
finalValues.phiTrueError = input->Y();
input = (TVector2*)rootFile->Get("True Theta");
finalValues.thetaTrue = input->X();
finalValues.thetaTrueError = input->Y();
// Shifting final values for Data Unbiased
finalValues.phi[DataUnbiased] -= 0.95;
finalValues.theta[DataUnbiased] += 0.11;
finalValues.phiErrorSystematics[DataUnbiased] = sqrt(pow(finalValues.phiErrorSystematics[DataUnbiased], 2) + pow(0.95, 2));
finalValues.thetaErrorSystematics[DataUnbiased]
= sqrt(pow(finalValues.thetaErrorSystematics[DataUnbiased], 2) + pow(0.11, 2));
// Grabbing histograms
for (int dataset = Data; dataset < DatasetSize; dataset++)
{
for (int signalSet = CorrelatedReactorOn; signalSet < SignalSize; signalSet++)
{
for (int direction = X; direction < DirectionSize; direction++)
{
// Get histogram and static cast to shared pointer for safety
string histogramName = DatasetToString(dataset) + " " + SignalToString(signalSet) + " " + AxisToString(direction);
histogram[dataset][signalSet][direction]
= std::shared_ptr<TH1F>(static_cast<TH1F*>(rootFile->Get(histogramName.c_str())));
}
}
}
rootFile->Close();
MakeDisplacementPlots(histogram);
MakeSimulationPlot(finalValues);
MakeFinalPlot(finalValues);
return 0;
}