29 #include "TPaveText.h"
34 static const UInt_t
NModes(4);
35 static const UInt_t
NRange(2);
36 static const UInt_t
NComp(7);
37 static const UInt_t
NPlot(2);
38 static const UInt_t
NPad(2);
39 static const UInt_t
NVtx(4);
40 static const UInt_t
NTxt(3);
44 static const Bool_t
DoRebin(
false);
54 cout <<
"\n Beginning percent difference script..." << endl;
57 const TString sOut(
"tuningDetEffects.testingPerDiffVsDiff_perDiffOverComp_pt15.pp200py8jet40.d27m4y2023.root");
58 const TString sRef(
"tuning_detector_effects/SphenixRecoUnscaledWithConstitHistos_output.root");
59 const TString sHistRef(
"EEC0");
60 const TString sNameRef(
"hRecoEEC_pt15");
61 const TString sLabelRef(
"Reco.");
64 const TString sComp[
NComp] = {
"tuning_detector_effects/SphenixTruthShift0Check_output.root",
65 "tuning_detector_effects/SphenixTruthShift.001Check_output.root",
66 "tuning_detector_effects/SphenixTruthShift.005Check_output.root",
67 "tuning_detector_effects/SphenixTruthShift.01Check_output.root",
68 "tuning_detector_effects/SphenixTruthShift.015Check_output.root",
69 "tuning_detector_effects/SphenixTruthShift.02Check_output.root",
70 "tuning_detector_effects/SphenixTruthShift.025Check_output.root"};
71 const TString sHistComp[
NComp] = {
"EEC0",
78 const TString sNameComp[
NComp] = {
"hTrueEEC_pt15_noSmear",
79 "hTrueEEC_pt15_smear001",
80 "hTrueEEC_pt15_smear005",
81 "hTrueEEC_pt15_smear01",
82 "hTrueEEC_pt15_smear015",
83 "hTrueEEC_pt15_smear02",
84 "hTrueEEC_pt15_smear025"};
85 const TString sNameSub[
NComp] = {
"hSub_pt15_noSmear",
91 "hSub_pt15_smear025"};
92 const TString sLabelComp[
NComp] = {
"Truth (no smearing)",
93 "Truth (smear width = 0.001)",
94 "Truth (smear width = 0.005)",
95 "Truth (smear width = 0.01)",
96 "Truth (smear width = 0.015)",
97 "Truth (smear width = 0.02)",
98 "Truth (smear width = 0.025)"};
101 const UInt_t nRebin(2);
102 const Float_t rMainPeak[
NRange] = {0.001, 1.};
103 const TString sTitleSubs[
NModes] = {
"\%-difference",
"\%-diff. of logs",
"difference",
"diff. of logs"};
106 const TString sOptRef(
"");
107 const TString sOptComp[
NComp] = {
"SAME",
"SAME",
"SAME",
"SAME",
"SAME",
"SAME",
"SAME"};
108 const TString sOptSub[
NComp] = {
"HIST P",
"SAME HIST P",
"SAME HIST P",
"SAME HIST P",
"SAME HIST P",
"SAME HIST P",
"SAME HIST p"};
109 const Float_t xPlotRange[
NPlot] = {0.0001, 1.};
112 const TString sTitle(
"");
113 const TString sTitleX(
"#DeltaR");
114 const TString sTitleY(
"Normalized EEC");
115 const UInt_t fColDen(923);
116 const UInt_t fMarDen(20);
117 const UInt_t fColNum[
NComp] = {921, 799, 819, 839, 859, 879, 899};
118 const UInt_t fMarNum[
NComp] = {24, 26, 32, 25, 27, 28, 30};
121 const TString sHeader(
"");
122 const TString sTxt[
NTxt] = {
"#bf{#it{sPHENIX}} Simulation [Run6]",
"PYTHIA-8, JS 40 GeV jet sample",
"#bf{p_{T}^{jet} #in (15, 20) GeV/c}"};
125 TFile *fOut =
new TFile(sOut.Data(),
"recreate");
126 TFile *fRef =
new TFile(sRef.Data(),
"read");
127 if (!fOut || !fRef) {
128 cerr <<
"PANIC: couldn't open output or reference file!\n"
129 <<
" fOut = " << fOut <<
", fRef = " << fRef
133 cout <<
" Opened output and reference files." << endl;
137 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
138 fComp[iComp] =
new TFile(sComp[iComp].
Data(),
"read");
140 cerr <<
"PANIC: couldn't open comparison file #" << iComp <<
"!" << endl;
144 cout <<
" Opened comparison files." << endl;
147 TH1D *hRef = (TH1D*) fRef ->
Get(sHistRef.Data());
149 cerr <<
"PANIC: couldn't grab reference histogram!" << endl;
152 hRef ->
SetName(sNameRef.Data());
153 cout <<
" Grabbed reference histogram." << endl;
157 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
158 hComp[iComp] = (TH1D*) fComp[iComp] ->
Get(sHistComp[iComp]);
160 cerr <<
"PANIC: couldn't grab comparison histogram #" << iComp <<
"!" << endl;
165 cout <<
" Grabbed comparison histograms." << endl;
169 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
170 hComp[iComp] -> Rebin(nRebin);
172 hRef -> Rebin(nRebin);
173 cout <<
" Rebinned histograms." << endl;
186 const UInt_t nBins = hRef -> GetNbinsX();
189 Double_t yMainPeak = 0.;
190 for (UInt_t iBin = 1; iBin < (nBins + 1); iBin++) {
193 const Double_t xBinCenter = hRef -> GetBinCenter(iBin);
194 const Bool_t isInMainPeakRange = ((xBinCenter >= rMainPeak[0]) && (xBinCenter < rMainPeak[1]));
195 if (!isInMainPeakRange)
continue;
198 const Double_t yBin = hRef -> GetBinContent(iBin);
199 if (yBin > yMainPeak) {
205 for (UInt_t iBin = 1; iBin < (nBins + 1); iBin++) {
208 const Double_t xBinCenter = hRef -> GetBinCenter(iBin);
209 const Bool_t isBelowMainPeak = (xBinCenter < rMainPeak[0]);
210 if (!isBelowMainPeak)
continue;
213 const Double_t yBin = hRef -> GetBinContent(iBin);
214 if (yBin >= yMainPeak) {
220 cout <<
" Removed fluctuations for reference histogram." << endl;
223 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
226 const UInt_t nBins = hRef -> GetNbinsX();
229 Double_t yMainPeak = 0.;
230 for (UInt_t iBin = 1; iBin < (nBins + 1); iBin++) {
233 const Double_t xBinCenter = hComp[iComp] -> GetBinCenter(iBin);
234 const Bool_t isInMainPeakRange = ((xBinCenter >= rMainPeak[0]) && (xBinCenter < rMainPeak[1]));
235 if (!isInMainPeakRange)
continue;
238 const Double_t yBin = hComp[iComp] -> GetBinContent(iBin);
239 if (yBin > yMainPeak) {
245 for (UInt_t iBin = 1; iBin < (nBins + 1); iBin++) {
248 const Double_t xBinCenter = hComp[iComp] -> GetBinCenter(iBin);
249 const Bool_t isBelowMainPeak = (xBinCenter < rMainPeak[0]);
250 if (!isBelowMainPeak)
continue;
253 const Double_t yBin = hComp[iComp] -> GetBinContent(iBin);
254 if (yBin >= yMainPeak) {
260 cout <<
" Removed fluctuations for comparison histograms." << endl;
263 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
264 const Double_t intComp = hComp[iComp] -> Integral();
265 if (intComp > 0.) hComp[iComp] -> Scale(1. / intComp);
268 const Double_t intRef = hRef -> Integral();
269 if (intRef > 0.) hRef -> Scale(1. / intRef);
270 cout <<
" Normalized histograms." << endl;
275 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
278 hSub[iComp] = (TH1D*) hRef -> Clone();
279 hSub[iComp] ->
Reset(
"ICE");
280 hSub[iComp] ->
SetName(sNameSub[iComp]);
283 const UInt_t nBins = hSub[iComp] -> GetNbinsX();
284 for (UInt_t iBin = 1; iBin < (nBins + 1); iBin++) {
287 const Double_t yRef = hRef -> GetBinContent(iBin);
288 const Double_t yComp = hComp[iComp] -> GetBinContent(iBin);
289 const Double_t eRef = hRef -> GetBinError(iBin);
290 const Double_t eComp = hComp[iComp] -> GetBinError(iBin);
297 ySub = (yRef - yComp) / yComp;
313 ySub = (yRef - yComp) / yRef;
328 cout <<
" Calculated ratios." << endl;
334 sTitleS = sTitleSubs[0];
337 sTitleS = sTitleSubs[1];
340 sTitleS = sTitleSubs[2];
343 sTitleS = sTitleSubs[3];
346 sTitleS = sTitleSubs[0];
351 const UInt_t fFil(0);
352 const UInt_t fLin(1);
353 const UInt_t fWid(1);
354 const UInt_t fTxt(42);
355 const UInt_t fAln(12);
356 const UInt_t fCnt(1);
357 const Float_t fLab[
NPad] = {0.074, 0.04};
358 const Float_t fTit[
NPad] = {0.074, 0.04};
359 const Float_t fOffX[
NPad] = {1.1, 1.};
360 const Float_t fOffY[
NPad] = {0.7, 1.3};
369 hRef -> SetTitleFont(fTxt);
370 hRef ->
GetXaxis() -> SetRangeUser(xPlotRange[0], xPlotRange[1]);
372 hRef ->
GetXaxis() -> SetTitleFont(fTxt);
373 hRef ->
GetXaxis() -> SetTitleSize(fTit[1]);
374 hRef ->
GetXaxis() -> SetTitleOffset(fOffX[1]);
375 hRef ->
GetXaxis() -> SetLabelFont(fTxt);
376 hRef ->
GetXaxis() -> SetLabelSize(fLab[1]);
377 hRef ->
GetXaxis() -> CenterTitle(fCnt);
379 hRef ->
GetYaxis() -> SetTitleFont(fTxt);
380 hRef ->
GetYaxis() -> SetTitleSize(fTit[1]);
381 hRef ->
GetYaxis() -> SetTitleOffset(fOffY[1]);
382 hRef ->
GetYaxis() -> SetLabelFont(fTxt);
383 hRef ->
GetYaxis() -> SetLabelSize(fLab[1]);
384 hRef ->
GetYaxis() -> CenterTitle(fCnt);
385 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
393 hComp[iComp] ->
SetTitle(sTitle.Data());
394 hComp[iComp] -> SetTitleFont(fTxt);
395 hComp[iComp] ->
GetXaxis() -> SetRangeUser(xPlotRange[0], xPlotRange[1]);
397 hComp[iComp] ->
GetXaxis() -> SetTitleFont(fTxt);
398 hComp[iComp] ->
GetXaxis() -> SetTitleSize(fTit[1]);
399 hComp[iComp] ->
GetXaxis() -> SetTitleOffset(fOffX[1]);
400 hComp[iComp] ->
GetXaxis() -> SetLabelFont(fTxt);
401 hComp[iComp] ->
GetXaxis() -> SetLabelSize(fLab[1]);
402 hComp[iComp] ->
GetXaxis() -> CenterTitle(fCnt);
404 hComp[iComp] ->
GetYaxis() -> SetTitleFont(fTxt);
405 hComp[iComp] ->
GetYaxis() -> SetTitleSize(fTit[1]);
406 hComp[iComp] ->
GetYaxis() -> SetTitleOffset(fOffY[1]);
407 hComp[iComp] ->
GetYaxis() -> SetLabelFont(fTxt);
408 hComp[iComp] ->
GetYaxis() -> SetLabelSize(fLab[1]);
409 hComp[iComp] ->
GetYaxis() -> CenterTitle(fCnt);
417 hSub[iComp] ->
SetTitle(sTitle.Data());
418 hSub[iComp] -> SetTitleFont(fTxt);
419 hSub[iComp] ->
GetXaxis() -> SetRangeUser(xPlotRange[0], xPlotRange[1]);
421 hSub[iComp] ->
GetXaxis() -> SetTitleFont(fTxt);
422 hSub[iComp] ->
GetXaxis() -> SetTitleSize(fTit[0]);
423 hSub[iComp] ->
GetXaxis() -> SetTitleOffset(fOffX[0]);
424 hSub[iComp] ->
GetXaxis() -> SetLabelFont(fTxt);
425 hSub[iComp] ->
GetXaxis() -> SetLabelSize(fLab[0]);
426 hSub[iComp] ->
GetXaxis() -> CenterTitle(fCnt);
428 hSub[iComp] ->
GetYaxis() -> SetTitleFont(fTxt);
429 hSub[iComp] ->
GetYaxis() -> SetTitleSize(fTit[0]);
430 hSub[iComp] ->
GetYaxis() -> SetTitleOffset(fOffY[0]);
431 hSub[iComp] ->
GetYaxis() -> SetLabelFont(fTxt);
432 hSub[iComp] ->
GetYaxis() -> SetLabelSize(fLab[0]);
433 hSub[iComp] ->
GetYaxis() -> CenterTitle(fCnt);
435 cout <<
" Set styles." << endl;
438 const UInt_t fColLe = 0;
439 const UInt_t fFilLe = 0;
440 const UInt_t fLinLe = 0;
441 const Float_t yObjLe = 0.1 + ((NComp + 1) * 0.05);
442 const Float_t fLegXY[
NVtx] = {0.1, 0.1, 0.3, yObjLe};
444 TLegend *
leg =
new TLegend(fLegXY[0], fLegXY[1], fLegXY[2], fLegXY[3], sHeader.Data());
450 leg -> SetTextAlign(fAln);
451 leg ->
AddEntry(hRef, sLabelRef.Data(),
"pf");
452 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
453 leg ->
AddEntry(hComp[iComp], sLabelComp[iComp],
"pf");
455 cout <<
" Made legend." << endl;
458 const UInt_t fColTx = 0;
459 const UInt_t fFilTx = 0;
460 const UInt_t fLinTx = 0;
461 const Float_t yObjTx = 0.1 + (
NTxt * 0.05);
462 const Float_t fTxtXY[
NVtx] = {0.3, 0.1, 0.5, yObjTx};
464 TPaveText *txt =
new TPaveText(fTxtXY[0], fTxtXY[1], fTxtXY[2], fTxtXY[3],
"NDC NB");
470 txt -> SetTextAlign(fAln);
471 for (UInt_t iTxt = 0; iTxt <
NTxt; iTxt++) {
472 txt -> AddText(sTxt[iTxt].
Data());
474 cout <<
" Made text." << endl;
477 const UInt_t fColLi(1);
478 const UInt_t fLinLi(9);
479 const UInt_t fWidLi(1);
480 const Float_t fLinXY[
NVtx] = {xPlotRange[0], 0., xPlotRange[1], 0.};
482 TLine *
line =
new TLine(fLinXY[0], fLinXY[1], fLinXY[2], fLinXY[3]);
486 cout <<
" Made line." << endl;
489 const UInt_t
width(750);
490 const UInt_t height(950);
491 const UInt_t fMode(0);
492 const UInt_t fBord(2);
493 const UInt_t fGrid(0);
494 const UInt_t fTick(1);
495 const UInt_t fLogX(1);
496 const UInt_t fLogY1(0);
497 const UInt_t fLogY2(1);
498 const UInt_t fFrame(0);
499 const Float_t fMarginL(0.15);
500 const Float_t fMarginR(0.02);
501 const Float_t fMarginT1(0.005);
502 const Float_t fMarginT2(0.02);
503 const Float_t fMarginTNR(0.02);
504 const Float_t fMarginB1(0.25);
505 const Float_t fMarginB2(0.005);
506 const Float_t fMarginBNR(0.15);
507 const Float_t fPadXY1[
NVtx] = {0., 0., 1., 0.35};
508 const Float_t fPadXY2[
NVtx] = {0., 0.35, 1., 1.};
510 TCanvas *cPlot =
new TCanvas(
"cPlot",
"", width, height);
511 TPad *pPad1 =
new TPad(
"pPad1",
"", fPadXY1[0], fPadXY1[1], fPadXY1[2], fPadXY1[3]);
512 TPad *pPad2 =
new TPad(
"pPad2",
"", fPadXY2[0], fPadXY2[1], fPadXY2[2], fPadXY2[3]);
513 cPlot -> SetGrid(fGrid, fGrid);
514 cPlot -> SetTicks(fTick, fTick);
517 pPad1 -> SetGrid(fGrid, fGrid);
518 pPad1 -> SetTicks(fTick, fTick);
519 pPad1 -> SetLogx(fLogX);
528 pPad2 -> SetGrid(fGrid, fGrid);
529 pPad2 -> SetTicks(fTick, fTick);
530 pPad2 -> SetLogx(fLogX);
544 for (UInt_t iComp = 1; iComp <
NComp; iComp++) {
545 hSub[iComp] ->
Draw(sOptSub[iComp].
Data());
549 hRef ->
Draw(sOptRef.Data());
550 for(UInt_t iComp = 0; iComp <
NComp; iComp++) {
551 hComp[iComp] ->
Draw(sOptComp[iComp].
Data());
558 cout <<
" Made plot." << endl;
563 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
564 hComp[iComp] ->
Write();
565 hSub[iComp] ->
Write();
567 cout <<
" Saved histograms." << endl;
574 for (UInt_t iComp = 0; iComp <
NComp; iComp++) {
575 fComp[iComp] ->
cd();
576 fComp[iComp] ->
Close();
578 cout <<
" Finished plot!\n" << endl;