25 #include "TGraphAsymmErrors.h"
46 #pragma GCC diagnostic ignored "-Wfloat-conversion"
47 #pragma GCC diagnostic ignored "-Wconversion"
73 Color_t
PlotColor[] = {kRed, kBlack, kBlue, kGreen};
79 const std::string& type,
const int fileId,
const bool setLabels =
true){
81 MACH3LOG_DEBUG(
"copying data from at local bin {}: for parameter {}", localBin, paramName);
90 blockHist->GetXaxis()->SetBinLabel(localBin +1, paramName.c_str());
91 blockHist->GetXaxis()->LabelsOption(
"v");
97 pad3 =
new TPad(
"Top",
"Top", 0.0, 0.4, 1.0, 1.0);
98 pad3->SetLeftMargin(canvas->GetLeftMargin());
99 pad3->SetRightMargin(canvas->GetRightMargin());
100 pad3->SetTopMargin(canvas->GetTopMargin());
101 pad3->SetBottomMargin(0);
105 pad4 =
new TPad(
"Bottom",
"Bottom", 0.0, 0.0, 1.0, 0.4);
106 pad4->SetLeftMargin(canvas->GetLeftMargin());
107 pad4->SetRightMargin(canvas->GetRightMargin());
108 pad4->SetTopMargin(0);
109 pad4->SetBottomMargin(0.75);
114 for(
unsigned int i = 0; i <
ParamNames.size(); i++)
117 for (
int ix = 0; ix < FullViolin->GetXaxis()->GetNbins(); ++ix) {
118 if(FullViolin->GetXaxis()->GetBinLabel(ix+1) ==
ParamNames[i])
129 for (
int iy = 0; iy < FullViolin->GetYaxis()->GetNbins(); ++iy) {
130 ReducedViolin->SetBinContent(i+1, iy+1, FullViolin->GetBinContent(ParamBinId, iy+1));
131 ReducedViolin->GetXaxis()->SetBinLabel(i+1,
ParamNames[i].c_str());
134 ReducedViolin->SetFillColor(FullViolin->GetFillColor());
135 ReducedViolin->SetFillColorAlpha(FullViolin->GetMarkerColor(), 0.35);
136 ReducedViolin->SetLineColor(FullViolin->GetMarkerColor());
138 ReducedViolin->SetMarkerColor(FullViolin->GetMarkerColor());
139 ReducedViolin->SetMarkerStyle(FullViolin->GetMarkerStyle());
140 ReducedViolin->SetMarkerSize(FullViolin->GetMarkerSize());
142 ReducedViolin->GetYaxis()->SetTitleOffset(FullViolin->GetTitleOffset());
143 ReducedViolin->GetYaxis()->SetTitle(FullViolin->GetYaxis()->GetTitle());
144 ReducedViolin->GetXaxis()->LabelsOption(
"v");
148 for (
int i = 0; i < Hist->GetXaxis()->GetNbins(); ++i)
150 std::string title = Hist->GetXaxis()->GetBinLabel(i+1);
152 Hist->GetXaxis()->SetBinLabel(i+1, title.c_str());
157 for (
int i = 0; i < Hist->GetXaxis()->GetNbins(); ++i)
159 std::string title = Hist->GetXaxis()->GetBinLabel(i+1);
162 Hist->GetXaxis()->SetBinLabel(i+1, title.c_str());
172 TTree *Settings = (File1->Get<TTree>(
"Settings"));
175 if (!Settings)
return false;
180 Settings->SetBranchAddress(
"NDParameters", &
NDParameters);
182 Settings->SetBranchAddress(
"FDParameters", &
FDParameters);
185 std::vector<int> *NDSamples_Bins = 0;
186 std::vector<std::string> *NDSamples_Names = 0;
187 Settings->SetBranchAddress(
"NDSamplesNames", &NDSamples_Names);
188 Settings->SetBranchAddress(
"NDSamplesBins", &NDSamples_Bins);
190 Settings->GetEntry(0);
199 inline std::unique_ptr<TH1D>
makeRatio(TH1D *PrefitCopy, TH1D *PostfitCopy,
bool setAxes){
201 std::unique_ptr<TH1D> Ratio =
M3::Clone(PrefitCopy);
202 Ratio->GetYaxis()->SetTitle(
"(x_{Post}-#mu_{Prior})/#sigma_{Prior}");
203 Ratio->SetMinimum(-3.7);
204 Ratio->SetMaximum(3.7);
206 for (
int j = 0; j < Ratio->GetXaxis()->GetNbins(); ++j)
208 if ( PrefitCopy->GetBinError(j+1) > 1.e-5 )
210 Ratio->SetBinContent(j+1, (PostfitCopy->GetBinContent(j+1)-PrefitCopy->GetBinContent(j+1))/PrefitCopy->GetBinError(j+1));
212 double up = (PostfitCopy->GetBinContent(j+1)+PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1))/PrefitCopy->GetBinError(j+1);
213 double down = (PostfitCopy->GetBinContent(j+1)-PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1))/PrefitCopy->GetBinError(j+1);
215 double maximum = up-Ratio->GetBinContent(j+1);
216 double minimum = Ratio->GetBinContent(j+1)-down;
218 Ratio->SetBinError(j+1, std::max(maximum, minimum));
222 Ratio->SetBinContent(j+1, (PostfitCopy->GetBinContent(j+1)-PrefitCopy->GetBinContent(j+1)));
224 double up = (PostfitCopy->GetBinContent(j+1)+PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1));
225 double down = (PostfitCopy->GetBinContent(j+1)-PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1));
227 double maximum = up-Ratio->GetBinContent(j+1);
228 double minimum = Ratio->GetBinContent(j+1)-down;
230 Ratio->SetBinError(j+1, std::max(maximum, minimum));
235 Ratio->SetFillStyle(0);
236 Ratio->SetFillColor(0);
238 Ratio->SetLineColor(PostfitCopy->GetLineColor());
239 if (Ratio->GetLineColor() == 0) Ratio->SetLineColor(kBlack);
240 Ratio->SetMarkerColor(PostfitCopy->GetMarkerColor());
242 Ratio->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
245 Ratio->SetMarkerSize(2);
246 Ratio->SetMarkerStyle(20);
248 Ratio->GetYaxis()->SetTitleSize(25);
249 Ratio->GetYaxis()->SetTitleFont(43);
250 Ratio->GetYaxis()->SetTitleOffset(2.0);
251 Ratio->GetYaxis()->SetLabelFont(43);
252 Ratio->GetYaxis()->SetLabelSize(25);
253 Ratio->GetYaxis()->CenterTitle();
254 Ratio->GetYaxis()->SetNdivisions(5,2,0);
256 Ratio->GetXaxis()->SetTitleSize(25);
257 Ratio->GetXaxis()->SetTitleFont(43);
258 Ratio->GetXaxis()->SetTitleOffset(4.0);
259 Ratio->GetXaxis()->SetLabelOffset(0.025);
260 Ratio->GetXaxis()->SetLabelFont(43);
261 Ratio->GetXaxis()->SetLabelSize(25);
267 inline void DrawPlots(TCanvas *plotCanv, TH1D* PrefitCopy,
const std::vector<std::unique_ptr<TH1D>>& PostfitVec, TPad *mainPad, TPad *ratioPad) {
272 PrefitCopy->GetYaxis()->SetTitle(
"Parameter Value");
274 PrefitCopy->GetYaxis()->SetLabelSize(0.);
275 PrefitCopy->GetYaxis()->SetTitleSize(0.05);
276 PrefitCopy->GetYaxis()->SetTitleOffset(1.3);
277 PrefitCopy->Draw(
"e2");
279 for (
int fileId = 0; fileId < static_cast<int>(PostfitVec.size()); fileId++) {
280 TH1D *postFitHist = PostfitVec[fileId].get();
282 postFitHist->SetMarkerColor(TColor::GetColorPalette(fileId));
283 postFitHist->SetLineColor(TColor::GetColorPalette(fileId));
284 postFitHist->SetMarkerStyle(7);
285 postFitHist->SetLineStyle(1+fileId);
286 postFitHist->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
288 postFitHist->Draw(
"e1, same");
292 auto axis = std::make_unique<TGaxis>(PrefitCopy->GetXaxis()->GetBinLowEdge(PrefitCopy->GetXaxis()->GetFirst()), gPad->GetUymin()+0.01,
293 PrefitCopy->GetXaxis()->GetBinLowEdge(PrefitCopy->GetXaxis()->GetFirst()), gPad->GetUymax(),
294 gPad->GetUymin()+0.01, gPad->GetUymax(), 510,
"");
295 axis->SetLabelFont(43);
296 axis->SetLabelSize(25);
303 std::vector<std::unique_ptr<TH1D>> ratioHists;
305 ratioHists.push_back(
makeRatio(PrefitCopy, PostfitVec[0].get(),
true));
307 ratioHists[0]->Draw(
"p");
308 for(
int postFitIdx = 1; postFitIdx < static_cast<int>(PostfitVec.size()); postFitIdx++){
309 ratioHists.push_back(
makeRatio(PrefitCopy, PostfitVec[postFitIdx].get(),
true));
311 ratioHists[postFitIdx]->SetMarkerColor(TColor::GetColorPalette(postFitIdx));
312 ratioHists[postFitIdx]->SetLineColor(TColor::GetColorPalette(postFitIdx));
313 ratioHists[postFitIdx]->SetMarkerStyle(7);
314 ratioHists[postFitIdx]->SetLineStyle(1+postFitIdx);
315 ratioHists[postFitIdx]->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
317 ratioHists[postFitIdx]->Draw(
"p same");
321 TLine line(ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetFirst()), 0.0, ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetLast()+1), 0.0);
322 TLine line2(ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetFirst()), 1.0, ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetLast()+1), 1.0);
323 TLine line3(ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetFirst()), -1.0, ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetLast()+1), -1.0);
325 line.SetLineColor(kRed);
326 line.SetLineStyle(kDashed);
328 line2.SetLineColor(kRed);
329 line2.SetLineStyle(kDashed);
330 line2.SetLineWidth(
man->
getOption<
int>(
"refLineWidth"));
331 line3.SetLineColor(kRed);
332 line3.SetLineStyle(kDashed);
333 line3.SetLineWidth(
man->
getOption<
int>(
"refLineWidth"));
339 plotCanv->Print((
SaveName).c_str());
345 std::vector<std::string>
const blockNames =
man->
getOption<std::vector<std::string>>(
"paramGroups");
346 const int XsecPlots =
static_cast<int>(blockNames.size());
348 for (
int i = 0; i < XsecPlots; i++)
351 std::string blockName = blockNames[i];
353 auto blockTitle = paramBlock[0].as<std::string>();
354 auto blockLimits = paramBlock[1].as<std::vector<double>>();
355 auto blockContents = paramBlock[2].as<std::vector<std::string>>();
358 const int nParams =
static_cast<int>(blockContents.size());
361 auto blockHist_prefit = std::make_unique<TH1D>(blockName.c_str(), blockTitle.c_str(),
362 nParams, 0.0,
static_cast<double>(nParams));
367 for(
int localBin=0; localBin < nParams; localBin ++){
369 std::string paramName = blockContents[localBin];
374 std::vector <std::unique_ptr<TH1D>> blockHist_postfit_Vec;
375 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
377 auto blockHist_postfit = std::make_unique<TH1D>((blockName +
man->
getFileName(fileId)).c_str(),
378 blockTitle.c_str(), nParams, 0.0,
static_cast<double>(nParams));
381 for(
int localBin=0; localBin < nParams; localBin ++){
383 std::string paramName = blockContents[localBin];
386 blockHist_postfit_Vec.push_back(std::move(blockHist_postfit));
389 blockHist_prefit->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
401 auto p1 = std::make_unique<TPad>(
"p1",
"p1", 0.0, 0.3, 1.0, 1.0);
402 auto p2 = std::make_unique<TPad>(
"p2",
"p2", 0.0, 0.0, 1.0, 0.3);
403 p1->SetLeftMargin(
canv->GetLeftMargin());
404 p1->SetRightMargin(
canv->GetRightMargin());
405 p1->SetTopMargin(
canv->GetTopMargin());
406 p1->SetBottomMargin(0);
408 p2->SetLeftMargin(
canv->GetLeftMargin());
409 p2->SetRightMargin(
canv->GetRightMargin());
411 p2->SetBottomMargin(0.25);
418 std::vector<std::string>
const fluxBlockNames =
man->
getOption<std::vector<std::string>>(
"fluxGroups");
419 auto const fluxBinningTable =
man->
getOption(
"FluxBinning");
421 const int FluxPlots =
static_cast<int>(fluxBlockNames.size());
423 for (
int i = 0; i < FluxPlots; i++)
426 std::string fluxBlockName = fluxBlockNames[i];
428 std::string blockTitle = paramBlock[0].as<std::string>();
429 std::vector<double> blockLimits = paramBlock[1].as<std::vector<double>>();
430 std::string blockBinningName = paramBlock[2].as<std::string>();
431 std::vector<int> blockContents = paramBlock[3].as<std::vector<int>>();
434 std::vector<double> binning = fluxBinningTable[blockBinningName].as<std::vector<double>>();
437 int nParams = blockContents[1] - blockContents[0] +1;
439 if(nParams <= 0 || blockContents.size() > 2){
440 MACH3LOG_CRITICAL(
"Invalid flux parameter block endpoints specified for {}", fluxBlockName);
444 if (nParams !=
static_cast<int>(binning.size()) - 1) {
445 MACH3LOG_CRITICAL(
"Binning provided for flux param block {} does not match the number of parameters specified for the block", fluxBlockName);
446 MACH3LOG_CRITICAL(
" Provided {} parameters but {} bins", nParams, binning.size() -1);
450 auto blockHist_prefit = std::make_unique<TH1D>(fluxBlockName.c_str(), blockTitle.c_str(), nParams, binning.data());
451 blockHist_prefit->GetYaxis()->SetTitle(
"Parameter Variation");
452 blockHist_prefit->GetXaxis()->SetTitle(
"E_{#nu} (GeV)");
453 blockHist_prefit->GetXaxis()->SetTitleOffset(blockHist_prefit->GetXaxis()->GetTitleOffset()*1.2);
456 for(
int fluxParId = blockContents[0]; fluxParId <= blockContents[1]; fluxParId++){
457 int localBin = fluxParId - blockContents[0];
458 std::string paramName =
"b_" + std::to_string(fluxParId);
463 std::vector <std::unique_ptr<TH1D>> blockHist_postfit_Vec;
464 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
465 auto blockHist_postfit = std::make_unique<TH1D>(fluxBlockName.c_str(), blockTitle.c_str(), nParams, binning.data());
467 for(
int fluxParId = blockContents[0]; fluxParId <= blockContents[1]; fluxParId++){
468 int localBin = fluxParId - blockContents[0];
469 std::string paramName =
"b_" + std::to_string(fluxParId);
473 blockHist_postfit_Vec.push_back(std::move(blockHist_postfit));
476 blockHist_prefit->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
477 DrawPlots(
canv, blockHist_prefit.get(), blockHist_postfit_Vec, p1.get(), p2.get());
481 canv->SetLogx(
false);
482 canv->SetBottomMargin(
canv->GetBottomMargin()*1.7);
488 Prefit->GetYaxis()->SetTitleOffset(
Prefit->GetYaxis()->GetTitleOffset()*1.2);
490 TPad* pTop =
nullptr;
491 TPad* pDown =
nullptr;
495 int Start = NDbinCounter;
504 std::vector<std::unique_ptr<TH1D>> PostfitNDDetHistVec(
man->
getNFiles());
509 while (temp.find(
"_") != std::string::npos) {
510 temp.replace(temp.find(
"_"), 1, std::string(
" "));
512 PreFitNDDetHist->SetTitle(temp.c_str());
513 PreFitNDDetHist->GetXaxis()->SetRangeUser(Start, NDbinCounter);
515 MACH3LOG_DEBUG(
" Start bin: {} :: End bin: {}", Start, NDbinCounter);
517 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
524 bool ProductOfTen =
false;
525 if(j % 10) ProductOfTen =
true;
526 if(j != 0 && ProductOfTen) PreFitNDDetHist->GetXaxis()->SetBinLabel(Start+j+1,
" ");
528 PreFitNDDetHist->GetXaxis()->SetBinLabel(Start+j+1, Form(
"Det Variation Bin %i", Start+j));
532 PreFitNDDetHist->GetYaxis()->SetRangeUser(
man->
getOption<
double>(
"detParYRange_low"),
man->
getOption<
double>(
"detParYRange_high"));
536 DrawPlots(
canv, PreFitNDDetHist, PostfitNDDetHistVec, pTop, pDown);
545 Prefit->GetYaxis()->SetTitleOffset(
Prefit->GetYaxis()->GetTitleOffset()*1.2);
548 TPad* pTop =
nullptr;
549 TPad* pDown =
nullptr;
553 int Start = FDbinCounter;
555 double FDSamplesBins[7] = {12,18,30,36,44,57,58};
556 std::string FDSamplesNames[7] = {
"FHC 1Re",
"FHC 1R#mu",
"RHC 1Re",
"RHC 1R#mu",
"FHC 1Re 1 d.e.",
"FHC MR#mu 1 or 2 d.e.",
"Momentum Scale"};
557 for (
unsigned int i = 0; i < 7; ++i)
562 Prefit->SetTitle(FDSamplesNames[i].c_str());
563 Prefit->GetXaxis()->SetRangeUser(Start, FDbinCounter);
565 for(
int j = 0; j < FDSamplesBins[i]; ++j)
585 gStyle->SetPalette(51);
587 auto blankCanv = std::make_unique<TCanvas>(
"blankCanv",
"blankCanv", 2048, 2048);
588 blankCanv->SaveAs(
"RidgePlots.pdf[");
591 const auto blockNames =
man->
getOption<std::vector<std::string>>(
"paramGroups");
592 const int XsecPlots =
static_cast<int>(blockNames.size());
594 constexpr
double padTopMargin = 0.9;
595 constexpr
double padBottomMargin = 0.1;
596 constexpr
double padOverlap = 0.9;
597 constexpr
double ridgeLineWidth = 1.0;
598 for (
int i = 0; i < XsecPlots; i++)
601 std::string blockName = blockNames[i];
603 auto blockTitle = paramBlock[0].as<std::string>();
604 auto blockLimits = paramBlock[1].as<std::vector<double>>();
605 auto blockContents = paramBlock[2].as<std::vector<std::string>>();
608 TDirectoryFile *posteriorDir =
man->
input().
getFile(0).
file->Get<TDirectoryFile>(
"Post_1d_hists");
611 int nParams =
static_cast<int>(blockContents.size());
612 auto ridgeCanv = std::make_unique<TCanvas>(
"RidgePlotCanv",
"RidgePlotCanv", 2048, 2048);
613 ridgeCanv->Divide(1,1+nParams, 0.01, 0.0);
615 auto title = std::make_unique<TLatex>();
616 title->SetTextAlign(21);
617 title->SetTextSize(0.03);
618 title->DrawLatex(0.5, 0.95, blockTitle.c_str());
620 auto label = std::make_unique<TLatex>();
621 label->SetTextAlign(31);
622 label->SetTextSize(0.02);
624 auto line = std::make_unique<TLine>();
625 line->SetLineColor(kBlack);
626 line->SetLineWidth(ridgeLineWidth);
629 auto axisPlot = std::make_unique<TH1D>(
"axis plot",
"", 1, blockLimits[0], blockLimits[1]);
631 std::vector<std::unique_ptr<TH1D>> axisPlot_holder(nParams);
632 std::vector<std::unique_ptr<TPad>> graph_holder(nParams);
633 for(
int parId = 0; parId < nParams; parId++) {
634 std::string paramName = blockContents[parId];
636 TH1D *posteriorDist =
nullptr;
638 TIter next(posteriorDir->GetListOfKeys());
639 while (TKey* key =
static_cast<TKey*
>(next())) {
641 std::string str(key->GetTitle());
643 uint pos = str.find(name);
644 bool foundPar = (pos == str.length() - name.length());
649 posteriorDist = posteriorDir->Get<TH1D>(key->GetName());
653 if(posteriorDist ==
nullptr){
654 MACH3LOG_WARN(
"Couldn't find parameter {} when making ridgeline plots", paramName);
660 double padAnchor = padBottomMargin + (
static_cast<double>(nParams - parId - 1) /
661 static_cast<double>(nParams - 1)) * (padTopMargin - padBottomMargin);
662 double padWidth = (padTopMargin - padBottomMargin) /
static_cast<double>(nParams);
663 double norm = (padTopMargin - padBottomMargin);
665 double padTop = padWidth * (1.0 + padOverlap) * (padTopMargin - padAnchor) / norm + padAnchor;
666 double padBottom = padAnchor - padWidth * (1.0 + padOverlap) * (padAnchor - padBottomMargin) / norm;
668 auto pad = std::make_unique<TPad>(paramName.c_str(),
"", 0.3, padBottom, 0.9, padTop, -1, 0, -1);
671 pad->SetBottomMargin(0.0);
672 pad->SetTopMargin(0.0);
673 pad->SetLeftMargin(0.0);
674 pad->SetRightMargin(0.0);
678 pad->SetFillStyle(4000);
680 gPad->SetFrameFillStyle(4000);
681 posteriorDist->GetFunction(
"Gauss")->SetBit(TF1::kNotDraw);
682 posteriorDist->SetTitle(
"");
683 posteriorDist->SetLineWidth(ridgeLineWidth);
685 auto axisPlot_tmp =
M3::Clone(axisPlot.get(), Form(
"AxisPlot_%s", paramName.c_str()));
686 axisPlot_tmp->Draw(
"A");
687 posteriorDist->Draw(
"H SAME");
689 axisPlot_tmp->GetYaxis()->SetRangeUser(0.0, 0.7 *posteriorDist->GetMaximum());
690 posteriorDist->SetLineColor(kWhite);
691 posteriorDist->SetFillColorAlpha(TColor::GetColorPalette(floor(
static_cast<float>(parId) *
692 TColor::GetNumberOfColors() /
static_cast<float>(nParams))), 0.85);
694 posteriorDist->GetXaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
695 posteriorDist->GetYaxis()->SetTitle(paramName.c_str());
698 gPad->Modified(); gPad->Update();
699 TFrame *frame = gPad->GetFrame();
700 frame->SetLineColorAlpha(0, 0.0);
704 line->DrawLine(0.1, padBottom, 0.9, padBottom);
706 axisPlot_holder[parId] = std::move(axisPlot_tmp);
707 graph_holder[parId] = std::move(pad);
711 ridgeCanv->SetGrid(1,1);
712 auto axisPad = std::make_unique<TPad>(
"AxisPad",
"", 0.3, 0.0, 0.9, 1.0, -1, 0, -1);
713 axisPad->SetLeftMargin(0.0);
714 axisPad->SetRightMargin(0.0);
717 axisPad->SetGrid(1,1);
718 axisPad->SetFrameFillStyle(4000);
720 axisPlot->GetXaxis()->SetTickSize(0.01);
721 axisPlot->GetXaxis()->SetTitle(
"");
722 axisPlot->GetYaxis()->SetLabelOffset(9999);
723 axisPlot->GetYaxis()->SetLabelSize(0);
724 axisPlot->GetYaxis()->SetTickSize(0);
725 axisPlot->GetYaxis()->SetAxisColor(0,0.0);
726 axisPlot->Draw(
"AXIS");
727 axisPlot->Draw(
"AXIG SAME");
729 axisPlot->SetFillStyle(4000);
730 axisPad->SetFillStyle(4000);
732 axisPad->SetGrid(1,1);
733 gPad->Modified(); gPad->Update();
734 gPad->SetFrameFillStyle(4000);
736 gPad->Modified(); gPad->Update();
737 TFrame *frame = gPad->GetFrame();
738 frame->SetLineColorAlpha(0, 0.0);
740 ridgeCanv->SaveAs(
"RidgePlots.pdf");
742 blankCanv->SaveAs(
"RidgePlots.pdf]");
756 bool plotNDDet =
false;
757 for (
size_t fileId = 0; fileId <
man->
input().getNInputFiles(); fileId++) {
759 MACH3LOG_INFO(
"at least one file provided does not have 'settings' tree indicating it is not MaCh3 ND file");
760 MACH3LOG_INFO(
" sadly this means I cannot plot ND Det parameters as this is only supported for MaCh3 ND files for now... sorry :(");
765 canv =
new TCanvas(
"canv",
"canv", 1024, 1024);
767 gStyle->SetOptStat(0);
768 canv->SetLeftMargin(0.12);
769 canv->SetBottomMargin(0.12);
770 canv->SetTopMargin(0.08);
771 canv->SetRightMargin(0.04);
779 auto leg = std::make_unique<TLegend>(0.0, 0.0, 1.0, 1.0);
783 leg->AddEntry(
Prefit,
"Prior",
"lpf");
785 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
786 TH1D *postFitHist_tmp =
new TH1D();
787 postFitHist_tmp->SetBit(kCanDelete);
789 postFitHist_tmp->SetMarkerColor(TColor::GetColorPalette(fileId));
790 postFitHist_tmp->SetLineColor(TColor::GetColorPalette(fileId));
791 postFitHist_tmp->SetMarkerStyle(7);
792 postFitHist_tmp->SetLineStyle(1+fileId);
793 postFitHist_tmp->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
794 leg->AddEntry(postFitHist_tmp,
man->
getFileLabel(fileId).c_str(),
"lpf");
820 inline std::unique_ptr<TGraphAsymmErrors>
MakeTGraphAsymmErrors(
const std::shared_ptr<TFile>& File, std::vector<int> Index = {})
822 int GraphBins = Index.size() == 0 ?
nBins : Index.size();
823 std::vector<double> x(GraphBins);
824 std::vector<double> y(GraphBins);
825 std::vector<double> exl(GraphBins);
826 std::vector<double> eyl(GraphBins);
827 std::vector<double> exh(GraphBins);
828 std::vector<double> eyh(GraphBins);
830 TH1D* PostHist =
static_cast<TH1D*
>(File->Get( (
"param_xsec_"+
plotType).c_str() ));
832 auto Errors_HPD_Positive =
static_cast<TVectorD*
>(File->Get(
"Errors_HPD_Positive" ));
833 auto Errors_HPD_Negative =
static_cast<TVectorD*
>(File->Get(
"Errors_HPD_Negative" ));
835 for(
int i = 0; i < GraphBins; ++i)
837 int Counter = Index.size() == 0 ? i : Index[i];
840 y[i] = PostHist->GetBinContent(Counter+1);
845 eyh[i] = (*Errors_HPD_Positive)(Counter);
846 eyl[i] = (*Errors_HPD_Negative)(Counter);
848 auto PostGraph = std::make_unique<TGraphAsymmErrors>(GraphBins, x.data(), y.data(), exl.data(), exh.data(), eyl.data(), eyh.data());
849 PostGraph->SetTitle(
"");
858 bool PlotAssym =
true;
861 TCandle::SetScaledViolin(
false);
864 if (!FileName1.empty())
MACH3LOG_INFO(
"File 1: {} ", FileName1);
865 if (!FileName2.empty())
MACH3LOG_INFO(
"File 2: {}", FileName2);
869 if(FileName2 !=
"")
SaveName += FileName2;
874 std::shared_ptr<TFile> File1 = std::make_shared<TFile>(FileName1.c_str());
875 std::shared_ptr<TFile> File2 =
nullptr;
876 if(FileName2 !=
"") File2 = std::make_shared<TFile>(FileName2.c_str());
878 canv =
new TCanvas(
"canv",
"canv", 1024, 1024);
880 gStyle->SetOptStat(0);
882 if(!PlotAssym) gStyle->SetErrorX(0.0001);
885 canv->SetBottomMargin(0.25);
886 canv->SetTopMargin(0.08);
887 canv->SetRightMargin(0.03);
888 canv->SetLeftMargin(0.10);
893 ViolinPre = File1->Get<TH2D>(
"param_violin_prior" );
894 Violin = File1->Get<TH2D>(
"param_violin" );
897 MACH3LOG_ERROR(
"Couldn't find violin plot, make sure method from MCMCProcessor is being called");
902 ViolinPre->SetFillColorAlpha(kRed, 0.35);
907 ViolinPre->GetYaxis()->SetTitleOffset(1.3);
908 ViolinPre->GetYaxis()->SetTitle(
"Parameter Value");
909 ViolinPre->GetXaxis()->LabelsOption(
"v");
911 Violin->SetFillColor(kBlue);
912 Violin->SetFillColorAlpha(kBlue, 0.35);
913 Violin->SetMarkerColor(kBlue);
914 Violin->SetMarkerStyle(20);
915 Violin->SetMarkerSize(0.5);
917 TH1D* Postfit = File1->Get<TH1D>( (
"param_xsec_"+
plotType).c_str() );
918 Postfit->SetMarkerColor(kRed);
919 Postfit->SetLineColor(kRed);
920 Postfit->SetMarkerStyle(7);
924 Violin2 = File2->Get<TH2D>(
"param_violin" );
925 Violin2->SetMarkerColor(kGreen);
928 Violin2->SetFillColorAlpha(kGreen, 0.35);
934 auto leg = std::make_unique<TLegend>(0.0, 0.0, 1.0, 1.0);
936 if (
Violin !=
nullptr) leg->AddEntry(
Violin,
"Posterior",
"lpf");
937 if (
Violin2 !=
nullptr) leg->AddEntry(
Violin2,
"Second Violin",
"lpf");
938 if(PlotAssym) leg->AddEntry(PostGraphAll.get(),
"HPD Assym",
"lp");
939 else leg->AddEntry(Postfit,
"HPD",
"lpf");
947 std::vector<std::string>
const blockNames =
man->
getOption<std::vector<std::string>>(
"paramGroups");
948 const int XsecPlots =
static_cast<int>(blockNames.size());
950 for (
int i = 0; i < XsecPlots; i++)
953 std::string blockName = blockNames[i];
955 std::string blockTitle = paramBlock[0].as<std::string>();
956 std::vector<double> blockLimits = paramBlock[1].as<std::vector<double>>();
957 std::vector<std::string> blockContents = paramBlock[2].as<std::vector<std::string>>();
960 const int nParams =
static_cast<int>(blockContents.size());
963 auto blockHist_prefit = std::make_unique<TH2D>((blockName +
"_Prefit").c_str(), blockTitle.c_str(), nParams, 0.0,
static_cast<double>(nParams),
967 blockHist_prefit->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
968 auto blockHist_Violin1 = std::make_unique<TH2D>((blockTitle +
"Violin1").c_str(), (blockTitle +
"Violin1").c_str(), nParams, 0.0,
static_cast<double>(nParams),
969 Violin->GetYaxis()->GetNbins(),
Violin->GetYaxis()->GetXmin(),
Violin->GetYaxis()->GetXmax());
971 blockHist_Violin1->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
972 std::unique_ptr<TH2D> blockHist_Violin2 =
nullptr;
974 blockHist_Violin2 = std::make_unique<TH2D>((blockTitle +
"Violin2").c_str(), (blockTitle +
"Violin2").c_str(), nParams, 0.0,
static_cast<double>(nParams),
977 blockHist_Violin2->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
983 auto blockHist_Best = std::make_unique<TH1D>(blockName.c_str(), blockTitle.c_str(),
984 nParams, 0.0,
static_cast<double>(nParams));
986 for(
int localBin=0; localBin < nParams; localBin ++){
988 std::string paramName = blockContents[localBin];
992 std::vector<int> Index;
993 for(
unsigned int is = 0; is < blockContents.size(); is++) {
995 for (
int ix = 0; ix <
ViolinPre->GetXaxis()->GetNbins(); ++ix) {
996 if(
ViolinPre->GetXaxis()->GetBinLabel(ix+1) == blockContents[is]) {
1001 Index.push_back(ParamBinId);
1004 PostGraph->SetMarkerColor(kBlack);
1005 PostGraph->SetLineColor(kBlack);
1006 PostGraph->SetMarkerStyle(7);
1007 PostGraph->SetLineWidth(2);
1008 PostGraph->SetLineStyle(kSolid);
1010 blockHist_prefit->Draw(
"violinX(03100300)");
1011 blockHist_Violin1->Draw(
"violinX(03100300) SAME");
1012 if(blockHist_Violin2 !=
nullptr) {
1013 blockHist_Violin2->Draw(
"violinX(03100300) SAME");
1015 if(PlotAssym) PostGraph->Draw(
"P SAME");
1016 else Postfit->Draw(
"SAME");
1027 if(File2 !=
nullptr) {
1035 auto canvas = std::make_unique<TCanvas>(
"canvas",
"canvas", 0, 0, 1024, 1024);
1036 canvas->SetBottomMargin(0.1f);
1037 canvas->SetTopMargin(0.05f);
1038 canvas->SetRightMargin(0.03f);
1039 canvas->SetLeftMargin(0.15f);
1042 TFile* File1 =
M3::Open(FileName1,
"READ", __FILE__, __LINE__);
1043 TFile* File2 =
M3::Open(FileName2,
"READ", __FILE__, __LINE__);
1046 TDirectory* Dir1 = File1->Get<TDirectory>(
"Post_2d_hists");
1047 TDirectory* Dir2 = File2->Get<TDirectory>(
"Post_2d_hists");
1049 if (!Dir1 || !Dir2) {
1050 MACH3LOG_WARN(
"Post_2d_hists directory not found in one or both files while running {}.", __func__);
1059 TIter next1(Dir1->GetListOfKeys());
1060 TKey* key1 =
nullptr;
1063 std::string SaveName2D =
"2DComparison_" + FileName1 +
"_" + FileName2;
1064 SaveName2D = SaveName2D.substr(0, SaveName2D.find(
".root"));
1065 SaveName2D = SaveName2D +
".pdf";
1067 canvas->Print((SaveName2D+
"[").c_str());
1069 while ((key1 =
static_cast<TKey*
>(next1()))) {
1070 TString histName = key1->GetName();
1073 if (TString(key1->GetClassName()) ==
"TH2D") {
1074 TH2D* hist1 =
static_cast<TH2D*
>(key1->ReadObj());
1077 TH2D* hist2 =
static_cast<TH2D*
>(Dir2->Get(histName));
1080 hist1->SetTitle(
"");
1081 hist1->SetTitle(
"");
1088 double xmin = std::min(hist1->GetXaxis()->GetXmin(), hist2->GetXaxis()->GetXmin());
1089 double xmax = std::max(hist1->GetXaxis()->GetXmax(), hist2->GetXaxis()->GetXmax());
1090 double ymin = std::min(hist1->GetYaxis()->GetXmin(), hist2->GetYaxis()->GetXmin());
1091 double ymax = std::max(hist1->GetYaxis()->GetXmax(), hist2->GetYaxis()->GetXmax());
1093 hist1->GetXaxis()->SetRangeUser(xmin, xmax);
1094 hist1->GetYaxis()->SetRangeUser(ymin, ymax);
1096 hist1->GetXaxis()->SetTitle(Xtitle.c_str());
1097 hist1->GetYaxis()->SetTitle(Ytitle.c_str());
1099 hist1->SetLineColor(kBlue);
1100 hist1->SetLineStyle(kSolid);
1101 hist1->SetLineWidth(2);
1103 hist2->SetLineColor(kRed);
1104 hist2->SetLineStyle(kDashed);
1105 hist2->SetLineWidth(2);
1107 hist1->Draw(
"CONT3");
1108 hist2->Draw(
"CONT3 SAME");
1110 auto Legend = std::make_unique<TLegend>(0.20, 0.7, 0.4, 0.92);
1113 Legend->SetTextSize(0.03);
1114 Legend->SetLineColor(0);
1115 Legend->SetLineStyle(0);
1116 Legend->SetFillColor(0);
1117 Legend->SetFillStyle(0);
1118 Legend->SetBorderSize(0);
1119 Legend->Draw(
"SAME");
1120 canvas->Print((SaveName2D).c_str());
1124 canvas->Print((SaveName2D+
"]").c_str());
1136 gErrorIgnoreLevel = kWarning;
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
std::vector< std::string > ParamNames
void DrawPlots(TCanvas *plotCanv, TH1D *PrefitCopy, const std::vector< std::unique_ptr< TH1D >> &PostfitVec, TPad *mainPad, TPad *ratioPad)
int main(int argc, char *argv[])
bool ReadSettings(std::shared_ptr< TFile > File1)
std::vector< int > NDSamplesBins
void InitializePads(TCanvas *canvas, TPad *&pad3, TPad *&pad4)
void copyParToBlockHist(const int localBin, const std::string ¶mName, TH1D *blockHist, const std::string &type, const int fileId, const bool setLabels=true)
std::unique_ptr< TH1D > makeRatio(TH1D *PrefitCopy, TH1D *PostfitCopy, bool setAxes)
std::vector< std::unique_ptr< TH1D > > PostfitHistVec
int FDParametersStartingPos
void Get2DComparison(const std::string &FileName1, const std::string &FileName2)
KS: Make comparison of 2D Posteriors.
void GetViolinPlots(std::string FileName1="", std::string FileName2="")
KS: Make fancy violin plots.
MaCh3Plotting::PlottingManager * man
int NDParametersStartingPos
std::vector< std::string > NDSamplesNames
void PrettifyTitles(TH1D *Hist)
std::unique_ptr< TGraphAsymmErrors > MakeTGraphAsymmErrors(const std::shared_ptr< TFile > &File, std::vector< int > Index={})
void GetPostfitParamPlots()
void CopyViolinToBlock(TH2D *FullViolin, TH2D *ReducedViolin, const std::vector< std::string > &ParamNames)
void MakeXsecRidgePlots()
#define MACH3LOG_CRITICAL
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Custom exception class for MaCh3 errors.
The main class to be used in plotting scripts.
const std::string getFileName(int i) const
void setExec(const std::string &execName)
Internally set the name of the executable that manager is being used in.
const std::string getFileLabel(int i) const
const InputManager & input() const
Get the InputManager contained within this PlottingManager, for doing input related things.
const std::string getOutputName() const
Get the straight up output file name with no bells or whistles, just the file extension.
void parseInputs(int argc, char *const *argv)
Parse command line arguments.
T getOption(const std::string &option)
Get a specific option from the config for this executable.
const StyleManager & style() const
Get the StyleManager contained within this PlottingManager, for doing style related things.
std::string prettifyParamName(const std::string &origName) const
Convert hideous and vulgar internal parameter name into a beautiful presentable name.
void setTH1Style(TH1 *hist, const std::string &styleName) const
Set the style of a TH1 to one of the styles defined in the style config.
void setPalette(const int rootPlotStyle) const
Set the root colour palette to one of the default root pallettes as defined in (root docs)[https://ro...
std::unique_ptr< ObjectType > Clone(const ObjectType *obj, const std::string &name="")
KS: Creates a copy of a ROOT-like object and wraps it in a smart pointer.
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.
constexpr static const int _BAD_INT_
Default value used for int initialisation.
@ kPostFit
Processed post fit errors.
void Print(const TTree *tree)