25#include "TGraphAsymmErrors.h"
46#pragma GCC diagnostic ignored "-Wfloat-conversion"
47#pragma GCC diagnostic ignored "-Wconversion"
83void copyParToBlockHist(
int localBin, std::string paramName, TH1D*blockHist, std::string type,
int fileId,
bool setLabels =
true){
85 MACH3LOG_DEBUG(
"copying data from at local bin {}: for parameter {}", localBin, paramName);
94 blockHist->GetXaxis()->SetBinLabel(localBin +1, paramName.c_str());
95 blockHist->GetXaxis()->LabelsOption(
"v");
101 pad3 =
new TPad(
"Top",
"Top", 0.0, 0.4, 1.0, 1.0);
102 pad3->SetLeftMargin(canvas->GetLeftMargin());
103 pad3->SetRightMargin(canvas->GetRightMargin());
104 pad3->SetTopMargin(canvas->GetTopMargin());
105 pad3->SetBottomMargin(0);
109 pad4 =
new TPad(
"Bottom",
"Bottom", 0.0, 0.0, 1.0, 0.4);
110 pad4->SetLeftMargin(canvas->GetLeftMargin());
111 pad4->SetRightMargin(canvas->GetRightMargin());
112 pad4->SetTopMargin(0);
113 pad4->SetBottomMargin(0.75);
118 for(
unsigned int i = 0; i <
ParamNames.size(); i++)
120 int ParamBinId = -999;
121 for (
int ix = 0; ix < FullViolin->GetXaxis()->GetNbins(); ++ix) {
122 if(FullViolin->GetXaxis()->GetBinLabel(ix+1) ==
ParamNames[i])
128 if(ParamBinId == -999) {
133 for (
int iy = 0; iy < FullViolin->GetYaxis()->GetNbins(); ++iy) {
134 ReducedViolin->SetBinContent(i+1, iy+1, FullViolin->GetBinContent(ParamBinId, iy+1));
135 ReducedViolin->GetXaxis()->SetBinLabel(i+1,
ParamNames[i].c_str());
138 ReducedViolin->SetFillColor(FullViolin->GetFillColor());
139 ReducedViolin->SetFillColorAlpha(FullViolin->GetMarkerColor(), 0.35);
140 ReducedViolin->SetLineColor(FullViolin->GetMarkerColor());
142 ReducedViolin->SetMarkerColor(FullViolin->GetMarkerColor());
143 ReducedViolin->SetMarkerStyle(FullViolin->GetMarkerStyle());
144 ReducedViolin->SetMarkerSize(FullViolin->GetMarkerSize());
146 ReducedViolin->GetYaxis()->SetTitleOffset(FullViolin->GetTitleOffset());
147 ReducedViolin->GetYaxis()->SetTitle(FullViolin->GetYaxis()->GetTitle());
148 ReducedViolin->GetXaxis()->LabelsOption(
"v");
152 for (
int i = 0; i < Hist->GetXaxis()->GetNbins(); ++i)
154 std::string title = Hist->GetXaxis()->GetBinLabel(i+1);
156 Hist->GetXaxis()->SetBinLabel(i+1, title.c_str());
161 for (
int i = 0; i < Hist->GetXaxis()->GetNbins(); ++i)
163 std::string title = Hist->GetXaxis()->GetBinLabel(i+1);
166 Hist->GetXaxis()->SetBinLabel(i+1, title.c_str());
176 TTree *Settings = (File1->Get<TTree>(
"Settings"));
179 if (!Settings)
return false;
187 Settings->SetBranchAddress(
"CrossSectionParametersStartingPos", &
XsecStartingPos);
188 Settings->SetBranchAddress(
"NDParameters", &
NDParameters);
190 Settings->SetBranchAddress(
"FDParameters", &
FDParameters);
193 std::vector<int> *NDSamples_Bins = 0;
194 std::vector<std::string> *NDSamples_Names = 0;
195 Settings->SetBranchAddress(
"NDSamplesNames", &NDSamples_Names);
196 Settings->SetBranchAddress(
"NDSamplesBins", &NDSamples_Bins);
198 Settings->GetEntry(0);
207inline TH1D*
makeRatio(TH1D *PrefitCopy, TH1D *PostfitCopy,
bool setAxes){
209 TH1D* Ratio =
static_cast<TH1D*
>(PrefitCopy->Clone());
210 Ratio->GetYaxis()->SetTitle(
"(x_{Post}-#mu_{Prior})/#sigma_{Prior}");
211 Ratio->SetMinimum(-3.7);
212 Ratio->SetMaximum(3.7);
214 for (
int j = 0; j < Ratio->GetXaxis()->GetNbins(); ++j)
216 if ( PrefitCopy->GetBinError(j+1) > 1.e-5 )
218 Ratio->SetBinContent(j+1, (PostfitCopy->GetBinContent(j+1)-PrefitCopy->GetBinContent(j+1))/PrefitCopy->GetBinError(j+1));
220 double up = (PostfitCopy->GetBinContent(j+1)+PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1))/PrefitCopy->GetBinError(j+1);
221 double down = (PostfitCopy->GetBinContent(j+1)-PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1))/PrefitCopy->GetBinError(j+1);
223 double maximum = up-Ratio->GetBinContent(j+1);
224 double minimum = Ratio->GetBinContent(j+1)-down;
226 Ratio->SetBinError(j+1, std::max(maximum, minimum));
230 Ratio->SetBinContent(j+1, (PostfitCopy->GetBinContent(j+1)-PrefitCopy->GetBinContent(j+1)));
232 double up = (PostfitCopy->GetBinContent(j+1)+PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1));
233 double down = (PostfitCopy->GetBinContent(j+1)-PostfitCopy->GetBinError(j+1)-PrefitCopy->GetBinContent(j+1));
235 double maximum = up-Ratio->GetBinContent(j+1);
236 double minimum = Ratio->GetBinContent(j+1)-down;
238 Ratio->SetBinError(j+1, std::max(maximum, minimum));
243 Ratio->SetFillStyle(0);
244 Ratio->SetFillColor(0);
246 Ratio->SetLineColor(PostfitCopy->GetLineColor());
247 if (Ratio->GetLineColor() == 0) Ratio->SetLineColor(kBlack);
248 Ratio->SetMarkerColor(PostfitCopy->GetMarkerColor());
250 Ratio->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
253 Ratio->SetMarkerSize(2);
254 Ratio->SetMarkerStyle(20);
256 Ratio->GetYaxis()->SetTitleSize(25);
257 Ratio->GetYaxis()->SetTitleFont(43);
258 Ratio->GetYaxis()->SetTitleOffset(2.0);
259 Ratio->GetYaxis()->SetLabelFont(43);
260 Ratio->GetYaxis()->SetLabelSize(25);
261 Ratio->GetYaxis()->CenterTitle();
262 Ratio->GetYaxis()->SetNdivisions(5,2,0);
264 Ratio->GetXaxis()->SetTitleSize(25);
265 Ratio->GetXaxis()->SetTitleFont(43);
266 Ratio->GetXaxis()->SetTitleOffset(4.0);
267 Ratio->GetXaxis()->SetLabelOffset(0.025);
268 Ratio->GetXaxis()->SetLabelFont(43);
269 Ratio->GetXaxis()->SetLabelSize(25);
275inline void DrawPlots(TCanvas *plotCanv, TH1D* PrefitCopy,
const std::vector<TH1D*>& PostfitVec, TPad *mainPad, TPad *ratioPad) {
280 PrefitCopy->GetYaxis()->SetTitle(
"Parameter Value");
282 PrefitCopy->GetYaxis()->SetLabelSize(0.);
283 PrefitCopy->GetYaxis()->SetTitleSize(0.05);
284 PrefitCopy->GetYaxis()->SetTitleOffset(1.3);
285 PrefitCopy->Draw(
"e2");
287 for (
int fileId = 0; fileId < static_cast<int>(PostfitVec.size()); fileId++) {
288 TH1D *postFitHist = PostfitVec[fileId];
290 postFitHist->SetMarkerColor(TColor::GetColorPalette(fileId));
291 postFitHist->SetLineColor(TColor::GetColorPalette(fileId));
292 postFitHist->SetMarkerStyle(7);
293 postFitHist->SetLineStyle(1+fileId);
294 postFitHist->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
296 postFitHist->Draw(
"e1, same");
300 TGaxis *axis =
new TGaxis(PrefitCopy->GetXaxis()->GetBinLowEdge(PrefitCopy->GetXaxis()->GetFirst()), gPad->GetUymin()+0.01,
301 PrefitCopy->GetXaxis()->GetBinLowEdge(PrefitCopy->GetXaxis()->GetFirst()), gPad->GetUymax(),
302 gPad->GetUymin()+0.01, gPad->GetUymax(), 510,
"");
303 axis->SetLabelFont(43);
304 axis->SetLabelSize(25);
311 std::vector<TH1D*> ratioHists;
314 ratioHists.push_back(
makeRatio(PrefitCopy, PostfitVec[0],
true));
316 ratioHists[0]->Draw(
"p");
317 for(
int postFitIdx = 1; postFitIdx < static_cast<int>(PostfitVec.size()); postFitIdx++){
318 ratioHists.push_back(
makeRatio(PrefitCopy, PostfitVec[postFitIdx],
true));
320 ratioHists[postFitIdx]->SetMarkerColor(TColor::GetColorPalette(postFitIdx));
321 ratioHists[postFitIdx]->SetLineColor(TColor::GetColorPalette(postFitIdx));
322 ratioHists[postFitIdx]->SetMarkerStyle(7);
323 ratioHists[postFitIdx]->SetLineStyle(1+postFitIdx);
324 ratioHists[postFitIdx]->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
326 ratioHists[postFitIdx]->Draw(
"p same");
330 TLine line(ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetFirst()), 0.0, ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetLast()+1), 0.0);
331 TLine line2(ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetFirst()), 1.0, ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetLast()+1), 1.0);
332 TLine line3(ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetFirst()), -1.0, ratioHists[0]->GetXaxis()->GetBinLowEdge(ratioHists[0]->GetXaxis()->GetLast()+1), -1.0);
334 line.SetLineColor(kRed);
335 line.SetLineStyle(kDashed);
337 line2.SetLineColor(kRed);
338 line2.SetLineStyle(kDashed);
339 line2.SetLineWidth(
man->
getOption<
int>(
"refLineWidth"));
340 line3.SetLineColor(kRed);
341 line3.SetLineStyle(kDashed);
342 line3.SetLineWidth(
man->
getOption<
int>(
"refLineWidth"));
348 plotCanv->Print((
SaveName).c_str());
357 std::vector<std::string>
const blockNames =
man->
getOption<std::vector<std::string>>(
"paramGroups");
358 const int XsecPlots =
static_cast<int>(blockNames.size());
360 for (
int i = 0; i < XsecPlots; i++)
363 std::string blockName = blockNames[i];
365 std::string blockTitle = paramBlock[0].as<std::string>();
366 std::vector<double> blockLimits = paramBlock[1].as<std::vector<double>>();
367 std::vector<std::string> blockContents = paramBlock[2].as<std::vector<std::string>>();
370 const int nParams =
static_cast<int>(blockContents.size());
373 TH1D *blockHist_prefit =
new TH1D(blockName.c_str(),
374 blockTitle.c_str(), nParams, 0.0,
static_cast<double>(nParams));
379 for(
int localBin=0; localBin < nParams; localBin ++){
381 std::string paramName = blockContents[localBin];
386 std::vector <TH1D *> blockHist_postfit_Vec;
387 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
389 TH1D *blockHist_postfit =
new TH1D((blockName +
man->
getFileName(fileId)).c_str(),
390 blockTitle.c_str(), nParams, 0.0,
static_cast<double>(nParams));
393 for(
int localBin=0; localBin < nParams; localBin ++){
395 std::string paramName = blockContents[localBin];
399 blockHist_postfit_Vec.push_back(blockHist_postfit);
403 blockHist_prefit->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
409 delete blockHist_prefit;
410 for (
auto hist : blockHist_postfit_Vec) {
413 blockHist_postfit_Vec.clear();
420 TPad* p1 =
new TPad(
"p1",
"p1", 0.0, 0.3, 1.0, 1.0);
421 TPad* p2 =
new TPad(
"p2",
"p2", 0.0, 0.0, 1.0, 0.3);
422 p1->SetLeftMargin(
canv->GetLeftMargin());
423 p1->SetRightMargin(
canv->GetRightMargin());
424 p1->SetTopMargin(
canv->GetTopMargin());
425 p1->SetBottomMargin(0);
427 p2->SetLeftMargin(
canv->GetLeftMargin());
428 p2->SetRightMargin(
canv->GetRightMargin());
430 p2->SetBottomMargin(0.25);
437 std::vector<std::string>
const fluxBlockNames =
man->
getOption<std::vector<std::string>>(
"fluxGroups");
438 auto const fluxBinningTable =
man->
getOption(
"FluxBinning");
440 const int FluxPlots =
static_cast<int>(fluxBlockNames.size());
442 for (
int i = 0; i < FluxPlots; i++)
445 std::string fluxBlockName = fluxBlockNames[i];
447 std::string blockTitle = paramBlock[0].as<std::string>();
448 std::vector<double> blockLimits = paramBlock[1].as<std::vector<double>>();
449 std::string blockBinningName = paramBlock[2].as<std::string>();
450 std::vector<int> blockContents = paramBlock[3].as<std::vector<int>>();
453 std::vector<double> binning = fluxBinningTable[blockBinningName].as<std::vector<double>>();
456 int nParams = blockContents[1] - blockContents[0] +1;
458 if(nParams <= 0 || blockContents.size() > 2){
459 MACH3LOG_CRITICAL(
"Invalid flux parameter block endpoints specified for {}", fluxBlockName);
463 if (nParams !=
static_cast<int>(binning.size()) - 1) {
464 MACH3LOG_CRITICAL(
"Binning provided for flux param block {} does not match the number of parameters specified for the block", fluxBlockName);
465 MACH3LOG_CRITICAL(
" Provided {} parameters but {} bins", nParams, binning.size() -1);
469 TH1D *blockHist_prefit =
new TH1D(fluxBlockName.c_str(), blockTitle.c_str(), nParams, binning.data());
470 blockHist_prefit->GetYaxis()->SetTitle(
"Parameter Variation");
471 blockHist_prefit->GetXaxis()->SetTitle(
"E_{#nu} (GeV)");
472 blockHist_prefit->GetXaxis()->SetTitleOffset(blockHist_prefit->GetXaxis()->GetTitleOffset()*1.2);
475 for(
int fluxParId = blockContents[0]; fluxParId <= blockContents[1]; fluxParId++){
476 int localBin = fluxParId - blockContents[0];
477 std::string paramName =
"b_" + std::to_string(fluxParId);
482 std::vector <TH1D *> blockHist_postfit_Vec;
483 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
484 TH1D *blockHist_postfit =
new TH1D(fluxBlockName.c_str(), blockTitle.c_str(), nParams, binning.data());
486 for(
int fluxParId = blockContents[0]; fluxParId <= blockContents[1]; fluxParId++){
487 int localBin = fluxParId - blockContents[0];
488 std::string paramName =
"b_" + std::to_string(fluxParId);
493 blockHist_postfit_Vec.push_back(blockHist_postfit);
497 blockHist_prefit->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
499 DrawPlots(
canv, blockHist_prefit, blockHist_postfit_Vec, p1, p2);
500 delete blockHist_prefit;
501 for (
auto hist : blockHist_postfit_Vec) {
504 blockHist_postfit_Vec.clear();
508 canv->SetLogx(
false);
509 canv->SetBottomMargin(
canv->GetBottomMargin()*1.7);
517 Prefit->GetYaxis()->SetTitleOffset(
Prefit->GetYaxis()->GetTitleOffset()*1.2);
519 TPad* pTop =
nullptr;
520 TPad* pDown =
nullptr;
524 int Start = NDbinCounter;
533 std::vector<TH1D*> PostfitNDDetHistVec(
man->
getNFiles());
538 while (temp.find(
"_") != std::string::npos) {
539 temp.replace(temp.find(
"_"), 1, std::string(
" "));
541 PreFitNDDetHist->SetTitle(temp.c_str());
542 PreFitNDDetHist->GetXaxis()->SetRangeUser(Start, NDbinCounter);
544 MACH3LOG_DEBUG(
" Start bin: {} :: End bin: {}", Start, NDbinCounter);
546 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
553 bool ProductOfTen =
false;
554 if(j % 10) ProductOfTen =
true;
555 if(j != 0 && ProductOfTen) PreFitNDDetHist->GetXaxis()->SetBinLabel(Start+j+1,
" ");
557 PreFitNDDetHist->GetXaxis()->SetBinLabel(Start+j+1, Form(
"Det Variation Bin %i", Start+j));
561 PreFitNDDetHist->GetYaxis()->SetRangeUser(
man->
getOption<
double>(
"detParYRange_low"),
man->
getOption<
double>(
"detParYRange_high"));
565 DrawPlots(
canv, PreFitNDDetHist, PostfitNDDetHistVec, pTop, pDown);
574 Prefit->GetYaxis()->SetTitleOffset(
Prefit->GetYaxis()->GetTitleOffset()*1.2);
577 TPad* pTop =
nullptr;
578 TPad* pDown =
nullptr;
582 int Start = FDbinCounter;
584 double FDSamplesBins[7] = {12,18,30,36,44,57,58};
585 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"};
586 for (
unsigned int i = 0; i < 7; ++i)
591 Prefit->SetTitle(FDSamplesNames[i].c_str());
592 Prefit->GetXaxis()->SetRangeUser(Start, FDbinCounter);
594 for(
int j = 0; j < FDSamplesBins[i]; ++j)
614 gStyle->SetPalette(51);
616 TCanvas *blankCanv =
new TCanvas (
"blankCanv",
"blankCanv", 2048, 2048);
617 blankCanv->SaveAs(
"RidgePlots.pdf[");
620 std::vector<std::string>
const blockNames =
man->
getOption<std::vector<std::string>>(
"paramGroups");
621 const int XsecPlots =
static_cast<int>(blockNames.size());
623 double padTopMargin = 0.9;
624 double padBottomMargin = 0.1;
625 double padOverlap = 0.9;
626 double ridgeLineWidth = 1.0;
628 for (
int i = 0; i < XsecPlots; i++)
631 std::string blockName = blockNames[i];
633 auto blockTitle = paramBlock[0].as<std::string>();
634 auto blockLimits = paramBlock[1].as<std::vector<double>>();
635 auto blockContents = paramBlock[2].as<std::vector<std::string>>();
638 TDirectoryFile *posteriorDir =
man->
input().
getFile(0).
file->Get<TDirectoryFile>(
"Post_1d_hists");
641 int nParams =
static_cast<int>(blockContents.size());
642 TCanvas *ridgeCanv =
new TCanvas (
"RidgePlotCanv",
"RidgePlotCanv", 2048, 2048);
643 ridgeCanv->Divide(1,1+nParams, 0.01, 0.0);
645 auto title = std::make_unique<TLatex>();
646 title->SetTextAlign(21);
647 title->SetTextSize(0.03);
648 title->DrawLatex(0.5, 0.95, blockTitle.c_str());
650 auto label = std::make_unique<TLatex>();
651 label->SetTextAlign(31);
652 label->SetTextSize(0.02);
654 auto line = std::make_unique<TLine>();
655 line->SetLineColor(kBlack);
656 line->SetLineWidth(ridgeLineWidth);
659 TH1D *axisPlot =
new TH1D(
"axis plot",
"", 1, blockLimits[0], blockLimits[1]);
661 for(
int parId = 0; parId < nParams; parId++) {
662 std::string paramName = blockContents[parId];
664 TH1D *posteriorDist =
nullptr;
666 TIter next(posteriorDir->GetListOfKeys());
667 while (TKey* key =
static_cast<TKey*
>(next())) {
669 std::string str(key->GetTitle());
671 uint pos = str.find(name);
672 bool foundPar = (pos == str.length() - name.length());
675 posteriorDist = posteriorDir->Get<TH1D>(key->GetName());
679 if(posteriorDist ==
nullptr){
680 MACH3LOG_WARN(
"Couldn't find parameter {} when making ridgeline plots", paramName);
685 double padAnchor = padBottomMargin + (
static_cast<double>(nParams - parId - 1) /
686 static_cast<double>(nParams - 1)) * (padTopMargin - padBottomMargin);
687 double padWidth = (padTopMargin - padBottomMargin) /
static_cast<double>(nParams);
688 double norm = (padTopMargin - padBottomMargin);
690 double padTop = padWidth * (1.0 + padOverlap) * (padTopMargin - padAnchor) / norm + padAnchor;
691 double padBottom = padAnchor - padWidth * (1.0 + padOverlap) * (padAnchor - padBottomMargin) / norm;
693 TPad *pad =
new TPad(paramName.c_str(),
"", 0.3, padBottom, 0.9, padTop, -1, 0, -1);
696 pad->SetBottomMargin(0.0);
697 pad->SetTopMargin(0.0);
698 pad->SetLeftMargin(0.0);
699 pad->SetRightMargin(0.0);
703 pad->SetFillStyle(4000);
705 gPad->SetFrameFillStyle(4000);
706 posteriorDist->GetFunction(
"Gauss")->SetBit(TF1::kNotDraw);
707 posteriorDist->SetTitle(
"");
708 posteriorDist->SetLineWidth(ridgeLineWidth);
710 TH1D* axisPlot_tmp =
static_cast<TH1D*
>(axisPlot->Clone(Form(
"AxisPlot_%s", paramName.c_str())));
711 axisPlot_tmp->Draw(
"A");
712 posteriorDist->Draw(
"H SAME");
714 axisPlot_tmp->GetYaxis()->SetRangeUser(0.0, 0.7 *posteriorDist->GetMaximum());
715 posteriorDist->SetLineColor(kWhite);
716 posteriorDist->SetFillColorAlpha(TColor::GetColorPalette(floor(
static_cast<float>(parId) *
717 TColor::GetNumberOfColors() /
static_cast<float>(nParams))), 0.85);
719 posteriorDist->GetXaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
720 posteriorDist->GetYaxis()->SetTitle(paramName.c_str());
723 gPad->Modified(); gPad->Update();
724 TFrame *frame = gPad->GetFrame();
725 frame->SetLineColorAlpha(0, 0.0);
729 line->DrawLine(0.1, padBottom, 0.9, padBottom);
733 ridgeCanv->SetGrid(1,1);
734 TPad *axisPad =
new TPad(
"AxisPad",
"", 0.3, 0.0, 0.9, 1.0, -1, 0, -1);
735 axisPad->SetLeftMargin(0.0);
736 axisPad->SetRightMargin(0.0);
739 axisPad->SetGrid(1,1);
740 axisPad->SetFrameFillStyle(4000);
742 axisPlot->GetXaxis()->SetTickSize(0.01);
743 axisPlot->GetXaxis()->SetTitle(
"");
744 axisPlot->GetYaxis()->SetLabelOffset(9999);
745 axisPlot->GetYaxis()->SetLabelSize(0);
746 axisPlot->GetYaxis()->SetTickSize(0);
747 axisPlot->GetYaxis()->SetAxisColor(0,0.0);
748 axisPlot->Draw(
"AXIS");
749 axisPlot->Draw(
"AXIG SAME");
751 axisPlot->SetFillStyle(4000);
752 axisPad->SetFillStyle(4000);
754 axisPad->SetGrid(1,1);
755 gPad->Modified(); gPad->Update();
756 gPad->SetFrameFillStyle(4000);
758 gPad->Modified(); gPad->Update();
759 TFrame *frame = gPad->GetFrame();
760 frame->SetLineColorAlpha(0, 0.0);
762 ridgeCanv->SaveAs(
"RidgePlots.pdf");
766 blankCanv->SaveAs(
"RidgePlots.pdf]");
781 bool plotNDDet =
false;
782 for (
size_t fileId = 0; fileId <
man->
input().getNInputFiles(); fileId++) {
784 MACH3LOG_INFO(
"at least one file provided does not have 'settings' tree indicating it is not MaCh3 ND file");
785 MACH3LOG_INFO(
" sadly this means I cannot plot ND Det parameters as this is only supported for MaCh3 ND files for now... sorry :(");
790 canv =
new TCanvas(
"canv",
"canv", 1024, 1024);
792 gStyle->SetOptStat(0);
793 canv->SetLeftMargin(0.12);
794 canv->SetBottomMargin(0.12);
795 canv->SetTopMargin(0.08);
796 canv->SetRightMargin(0.04);
804 auto leg = std::make_unique<TLegend>(0.0, 0.0, 1.0, 1.0);
808 leg->AddEntry(
Prefit,
"Prior",
"lpf");
810 for(
unsigned int fileId = 0; fileId <
man->
getNFiles(); fileId++){
811 TH1D *postFitHist_tmp =
new TH1D();
812 postFitHist_tmp->SetBit(kCanDelete);
814 postFitHist_tmp->SetMarkerColor(TColor::GetColorPalette(fileId));
815 postFitHist_tmp->SetLineColor(TColor::GetColorPalette(fileId));
816 postFitHist_tmp->SetMarkerStyle(7);
817 postFitHist_tmp->SetLineStyle(1+fileId);
818 postFitHist_tmp->SetLineWidth(
man->
getOption<
int>(
"plotLineWidth"));
819 leg->AddEntry(postFitHist_tmp,
man->
getFileLabel(fileId).c_str(),
"lpf");
847 int GraphBins = Index.size() == 0 ?
nBins : Index.size();
848 std::vector<double> x(GraphBins);
849 std::vector<double> y(GraphBins);
850 std::vector<double> exl(GraphBins);
851 std::vector<double> eyl(GraphBins);
852 std::vector<double> exh(GraphBins);
853 std::vector<double> eyh(GraphBins);
855 TH1D* PostHist =
static_cast<TH1D*
>(File->Get( (
"param_xsec_"+
plotType).c_str() ));
857 TVectorD* Errors_HPD_Positive =
static_cast<TVectorD*
>(File->Get(
"Errors_HPD_Positive" ));
858 TVectorD* Errors_HPD_Negative =
static_cast<TVectorD*
>(File->Get(
"Errors_HPD_Negative" ));
860 for(
int i = 0; i < GraphBins; ++i)
862 int Counter = Index.size() == 0 ? i : Index[i];
865 y[i] = PostHist->GetBinContent(Counter+1);
870 eyh[i] = (*Errors_HPD_Positive)(Counter);
871 eyl[i] = (*Errors_HPD_Negative)(Counter);
873 TGraphAsymmErrors* PostGraph =
new TGraphAsymmErrors(GraphBins, x.data(), y.data(), exl.data(), exh.data(), eyl.data(), eyh.data());
874 PostGraph->SetTitle(
"");
883 bool PlotAssym =
true;
886 TCandle::SetScaledViolin(
false);
889 if (!FileName1.empty())
MACH3LOG_INFO(
"File 1: {} ", FileName1);
890 if (!FileName2.empty())
MACH3LOG_INFO(
"File 2: {}", FileName2);
894 if(FileName2 !=
"")
SaveName += FileName2;
899 std::shared_ptr<TFile> File1 = std::make_shared<TFile>(FileName1.c_str());
900 std::shared_ptr<TFile> File2 =
nullptr;
901 if(FileName2 !=
"") File2 = std::make_shared<TFile>(FileName2.c_str());
903 canv =
new TCanvas(
"canv",
"canv", 1024, 1024);
905 gStyle->SetOptStat(0);
907 if(!PlotAssym) gStyle->SetErrorX(0.0001);
910 canv->SetBottomMargin(0.25);
911 canv->SetTopMargin(0.08);
912 canv->SetRightMargin(0.03);
913 canv->SetLeftMargin(0.10);
918 ViolinPre = File1->Get<TH2D>(
"param_violin_prior" );
919 Violin = File1->Get<TH2D>(
"param_violin" );
922 MACH3LOG_ERROR(
"Couldn't find violin plot, make sure method from MCMCProcessor is being called");
927 ViolinPre->SetFillColorAlpha(kRed, 0.35);
932 ViolinPre->GetYaxis()->SetTitleOffset(1.3);
933 ViolinPre->GetYaxis()->SetTitle(
"Parameter Value");
934 ViolinPre->GetXaxis()->LabelsOption(
"v");
936 Violin->SetFillColor(kBlue);
937 Violin->SetFillColorAlpha(kBlue, 0.35);
938 Violin->SetMarkerColor(kBlue);
939 Violin->SetMarkerStyle(20);
940 Violin->SetMarkerSize(0.5);
942 TH1D* Postfit = File1->Get<TH1D>( (
"param_xsec_"+
plotType).c_str() );
943 Postfit->SetMarkerColor(kRed);
944 Postfit->SetLineColor(kRed);
945 Postfit->SetMarkerStyle(7);
949 Violin2 = File2->Get<TH2D>(
"param_violin" );
950 Violin2->SetMarkerColor(kGreen);
953 Violin2->SetFillColorAlpha(kGreen, 0.35);
959 auto leg = std::make_unique<TLegend>(0.0, 0.0, 1.0, 1.0);
961 if (
Violin !=
nullptr) leg->AddEntry(
Violin,
"Posterior",
"lpf");
962 if (
Violin2 !=
nullptr) leg->AddEntry(
Violin2,
"Second Violin",
"lpf");
963 if(PlotAssym) leg->AddEntry(PostGraphAll,
"HPD Assym",
"lp");
964 else leg->AddEntry(Postfit,
"HPD",
"lpf");
972 std::vector<std::string>
const blockNames =
man->
getOption<std::vector<std::string>>(
"paramGroups");
973 const int XsecPlots =
static_cast<int>(blockNames.size());
975 for (
int i = 0; i < XsecPlots; i++)
978 std::string blockName = blockNames[i];
980 std::string blockTitle = paramBlock[0].as<std::string>();
981 std::vector<double> blockLimits = paramBlock[1].as<std::vector<double>>();
982 std::vector<std::string> blockContents = paramBlock[2].as<std::vector<std::string>>();
985 const int nParams =
static_cast<int>(blockContents.size());
988 auto blockHist_prefit = std::make_unique<TH2D>(blockName.c_str(), blockTitle.c_str(), nParams, 0.0,
static_cast<double>(nParams),
992 blockHist_prefit->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
993 auto blockHist_Violin1 = std::make_unique<TH2D>((blockTitle +
"Violin1").c_str(), (blockTitle +
"Violin1").c_str(), nParams, 0.0,
static_cast<double>(nParams),
994 Violin->GetYaxis()->GetNbins(),
Violin->GetYaxis()->GetXmin(),
Violin->GetYaxis()->GetXmax());
996 blockHist_Violin1->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
997 std::unique_ptr<TH2D> blockHist_Violin2 =
nullptr;
999 blockHist_Violin2 = std::make_unique<TH2D>((blockTitle +
"Violin2").c_str(), (blockTitle +
"Violin2").c_str(), nParams, 0.0,
static_cast<double>(nParams),
1002 blockHist_Violin2->GetYaxis()->SetRangeUser(blockLimits[0], blockLimits[1]);
1008 auto blockHist_Best = std::make_unique<TH1D>(blockName.c_str(), blockTitle.c_str(),
1009 nParams, 0.0,
static_cast<double>(nParams));
1011 for(
int localBin=0; localBin < nParams; localBin ++){
1013 std::string paramName = blockContents[localBin];
1017 std::vector<int> Index;
1018 for(
unsigned int is = 0; is < blockContents.size(); is++) {
1019 int ParamBinId = -999;
1020 for (
int ix = 0; ix <
ViolinPre->GetXaxis()->GetNbins(); ++ix) {
1021 if(
ViolinPre->GetXaxis()->GetBinLabel(ix+1) == blockContents[is]) {
1026 Index.push_back(ParamBinId);
1029 PostGraph->SetMarkerColor(kBlack);
1030 PostGraph->SetLineColor(kBlack);
1031 PostGraph->SetMarkerStyle(7);
1032 PostGraph->SetLineWidth(2);
1033 PostGraph->SetLineStyle(kSolid);
1035 blockHist_prefit->Draw(
"violinX(03100300)");
1036 blockHist_Violin1->Draw(
"violinX(03100300) SAME");
1037 if(blockHist_Violin2 !=
nullptr) {
1038 blockHist_Violin2->Draw(
"violinX(03100300) SAME");
1040 if(PlotAssym) PostGraph->Draw(
"P SAME");
1041 else Postfit->Draw(
"SAME");
1050 delete PostGraphAll;
1054 if(File2 !=
nullptr) {
1063 gErrorIgnoreLevel = kWarning;
1068 std::cout << std::endl << std::endl <<
"====================" << std::endl;
#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
int main(int argc, char *argv[])
void DrawPlots(TCanvas *plotCanv, TH1D *PrefitCopy, const std::vector< TH1D * > &PostfitVec, TPad *mainPad, TPad *ratioPad)
bool ReadSettings(std::shared_ptr< TFile > File1)
std::vector< int > NDSamplesBins
void InitializePads(TCanvas *canvas, TPad *&pad3, TPad *&pad4)
int CrossSectionParameters
int FDParametersStartingPos
TH1D * makeRatio(TH1D *PrefitCopy, TH1D *PostfitCopy, bool setAxes)
void GetViolinPlots(std::string FileName1="", std::string FileName2="")
MaCh3Plotting::PlottingManager * man
int NDParametersStartingPos
std::vector< std::string > NDSamplesNames
void PrettifyTitles(TH1D *Hist)
void GetPostfitParamPlots()
std::vector< TH1D * > PostfitHistVec
void copyParToBlockHist(int localBin, std::string paramName, TH1D *blockHist, std::string type, int fileId, bool setLabels=true)
TGraphAsymmErrors * MakeTGraphAsymmErrors(std::shared_ptr< TFile > File, std::vector< int > Index={})
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 getOutputName()
Get the straight up output file name with no bells or whistles, just the file extension.
void setExec(std::string execName)
Internally set the name of the executable that manager is being used in.
void parseInputs(int argc, char *const *argv)
Parse command line arguments.
const std::string getFileName(int i)
const std::string getFileLabel(int i)
const StyleManager & style()
Get the StyleManager contained within this PlottingManager, for doing style related things.
T getOption(std::string option)
Get a specific option from the config for this executable.
const InputManager & input()
Get the InputManager contained within this PlottingManager, for doing input 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, std::string styleName) const
Set the style of a TH1 to one of the styles defined in the style config.
void setPalette(int rootPlotStyle) const
Set the root colour palette to one of the default root pallettes as defined in (root docs)[https://ro...
@ kPostFit
Processed post fit errors.