14#pragma GCC diagnostic ignored "-Wfloat-conversion"
18 Chain(nullptr), StepCut(
""), MadePostfit(false) {
92 ParStep_cpu =
nullptr;
93 NumeratorSum_cpu =
nullptr;
94 ParamSums_cpu =
nullptr;
95 DenomSum_cpu =
nullptr;
97 ParStep_gpu =
nullptr;
98 NumeratorSum_gpu =
nullptr;
99 ParamSums_gpu =
nullptr;
100 DenomSum_gpu =
nullptr;
125 for (
int i = 0; i <
nDraw; ++i)
131 for (
int i = 0; i <
nDraw; ++i)
133 for (
int j = 0; j <
nDraw; ++j)
159void MCMCProcessor::GetPostfit(TVectorD *&Central_PDF, TVectorD *&Errors_PDF, TVectorD *&Central_G, TVectorD *&Errors_G, TVectorD *&Peak_Values) {
180 const int ParamTypeSize = int(
ParamType.size());
182 for (
int i = 0; i < ParamTypeSize; ++i) {
184 (*PDF_Central)(ParamNumber) = (*
Means)(i);
185 (*PDF_Errors)(ParamNumber) = (*
Errors)(i);
186 (*Peak_Values)(ParamNumber) = (*
Means_HPD)(i);
196 Cov =
static_cast<TMatrixDSym*
>(
Covariance->Clone());
197 Corr =
static_cast<TMatrixDSym*
>(
Correlation->Clone());
204 auto rand = std::make_unique<TRandom3>(0);
205 const int uniform = int(rand->Uniform(0, 10000));
207 Posterior = std::make_unique<TCanvas>((
"Posterior" + std::to_string(uniform)).c_str(), (
"Posterior" + std::to_string(uniform)).c_str(), 0, 0, 1024, 1024);
209 TCandle::SetScaledViolin(
false);
212 gStyle->SetOptStat(0);
213 gStyle->SetOptTitle(0);
223 gErrorIgnoreLevel = kWarning;
246 int originalErrorLevel = gErrorIgnoreLevel;
247 gErrorIgnoreLevel = kFatal;
250 TDirectory *PostDir =
OutputFile->mkdir(
"Post");
251 TDirectory *PostHistDir =
OutputFile->mkdir(
"Post_1d_hists");
254 for (
int i = 0; i <
nDraw; ++i)
256 if (i % (
nDraw/5) == 0) {
261 double Prior = 1.0, PriorError = 1.0;
269 hpost[i]->SetMinimum(0);
270 hpost[i]->GetYaxis()->SetTitle(
"Steps");
271 hpost[i]->GetYaxis()->SetNoExponent(
false);
274 std::string CutPosterior1D =
"";
286 (*Central_Value)(i) = Prior;
288 double Mean, Err, Err_p, Err_m;
294 (*Means_Gauss)(i) =
Mean;
295 (*Errors_Gauss)(i) = Err;
298 (*Means_HPD)(i) =
Mean;
299 (*Errors_HPD)(i) = Err;
300 (*Errors_HPD_Positive)(i) = Err_p;
301 (*Errors_HPD_Negative)(i) = Err_m;
305 (*Correlation)(i,i) = 1.0;
311 hpost[i]->SetLineWidth(2);
312 hpost[i]->SetLineColor(kBlue-1);
314 hpost[i]->SetTitle(Title);
315 hpost[i]->GetXaxis()->SetTitle(
hpost[i]->GetTitle());
318 auto Asimov = std::make_unique<TLine>(Prior,
hpost[i]->GetMinimum(), Prior,
hpost[i]->GetMaximum());
321 auto leg = std::make_unique<TLegend>(0.12, 0.6, 0.6, 0.97);
323 leg->AddEntry(
hpost[i], Form(
"#splitline{PDF}{#mu = %.2f, #sigma = %.2f}",
hpost[i]->GetMean(),
hpost[i]->GetRMS()),
"l");
324 leg->AddEntry(
Gauss.get(), Form(
"#splitline{Gauss}{#mu = %.2f, #sigma = %.2f}",
Gauss->GetParameter(1),
Gauss->GetParameter(2)),
"l");
326 leg->AddEntry(Asimov.get(), Form(
"#splitline{Prior}{x = %.2f , #sigma = %.2f}", Prior, PriorError),
"l");
331 MACH3LOG_WARN(
"Found fixed parameter: {} ({}), moving on", Title, i);
334 (*Means_HPD)(i) = Prior;
335 (*Errors_HPD)(i) = PriorError;
349 Asimov->Draw(
"same");
358 hpost[i]->SetName(Title);
359 hpost[i]->SetTitle(Title);
365 TTree *SettingsBranch =
new TTree(
"Settings",
"Settings");
369 SettingsBranch->Branch(
"CrossSectionParametersStartingPos", &CrossSectionParametersStartingPos);
386 SettingsBranch->Fill();
387 SettingsBranch->Write();
388 delete SettingsBranch;
390 TDirectory *Names =
OutputFile->mkdir(
"Names");
393 TObjString((*it)).Write();
400 Means->Write(
"PDF_Means");
401 Errors->Write(
"PDF_Error");
411 PostHistDir->Close();
415 gErrorIgnoreLevel = originalErrorLevel;
427 prefit->GetXaxis()->SetTitle(
"");
431 std::string CutPosterior1D =
"";
439 TH1D *paramPlot =
new TH1D(
"paramPlot",
"paramPlot",
nDraw, 0,
nDraw);
440 paramPlot->SetName(
"mach3params");
441 paramPlot->SetTitle(CutPosterior1D.c_str());
442 paramPlot->SetFillStyle(3001);
443 paramPlot->SetFillColor(kBlue-1);
444 paramPlot->SetMarkerColor(paramPlot->GetFillColor());
445 paramPlot->SetMarkerStyle(20);
446 paramPlot->SetLineColor(paramPlot->GetFillColor());
447 paramPlot->SetMarkerSize(prefit->GetMarkerSize());
448 paramPlot->GetXaxis()->SetTitle(
"");
451 TH1D *paramPlot_Gauss =
static_cast<TH1D*
>(paramPlot->Clone());
452 paramPlot_Gauss->SetMarkerColor(kOrange-5);
453 paramPlot_Gauss->SetMarkerStyle(23);
454 paramPlot_Gauss->SetLineWidth(2);
455 paramPlot_Gauss->SetMarkerSize((prefit->GetMarkerSize())*0.75);
456 paramPlot_Gauss->SetFillColor(paramPlot_Gauss->GetMarkerColor());
457 paramPlot_Gauss->SetFillStyle(3244);
458 paramPlot_Gauss->SetLineColor(paramPlot_Gauss->GetMarkerColor());
459 paramPlot_Gauss->GetXaxis()->SetTitle(
"");
462 TH1D *paramPlot_HPD =
static_cast<TH1D*
>(paramPlot->Clone());
463 paramPlot_HPD->SetMarkerColor(kBlack);
464 paramPlot_HPD->SetMarkerStyle(25);
465 paramPlot_HPD->SetLineWidth(2);
466 paramPlot_HPD->SetMarkerSize((prefit->GetMarkerSize())*0.5);
467 paramPlot_HPD->SetFillColor(0);
468 paramPlot_HPD->SetFillStyle(0);
469 paramPlot_HPD->SetLineColor(paramPlot_HPD->GetMarkerColor());
470 paramPlot_HPD->GetXaxis()->SetTitle(
"");
473 for (
int i = 0; i <
nDraw; ++i)
481 double CentralValueTemp = 0;
482 double Central, Central_gauss, Central_HPD;
483 double Err, Err_Gauss, Err_HPD;
489 if ( CentralValueTemp != 0)
491 Central = (*Means)(i) / CentralValueTemp;
492 Err = (*Errors)(i) / CentralValueTemp;
494 Central_gauss = (*Means_Gauss)(i) / CentralValueTemp;
495 Err_Gauss = (*Errors_Gauss)(i) / CentralValueTemp;
497 Central_HPD = (*Means_HPD)(i) / CentralValueTemp;
498 Err_HPD = (*Errors_HPD)(i) / CentralValueTemp;
501 Central = 1+(*Means)(i);
504 Central_gauss = 1+(*Means_Gauss)(i);
505 Err_Gauss = (*Errors_Gauss)(i);
507 Central_HPD = 1+(*Means_HPD)(i) ;
508 Err_HPD = (*Errors_HPD)(i);
514 Central = (*Means)(i);
517 Central_gauss = (*Means_Gauss)(i);
518 Err_Gauss = (*Errors_Gauss)(i);
520 Central_HPD = (*Means_HPD)(i) ;
521 Err_HPD = (*Errors_HPD)(i);
524 paramPlot->SetBinContent(i+1, Central);
525 paramPlot->SetBinError(i+1, Err);
527 paramPlot_Gauss->SetBinContent(i+1, Central_gauss);
528 paramPlot_Gauss->SetBinError(i+1, Err_Gauss);
530 paramPlot_HPD->SetBinContent(i+1, Central_HPD);
531 paramPlot_HPD->SetBinError(i+1, Err_HPD);
533 paramPlot->GetXaxis()->SetBinLabel(i+1, prefit->GetXaxis()->GetBinLabel(i+1));
534 paramPlot_Gauss->GetXaxis()->SetBinLabel(i+1, prefit->GetXaxis()->GetBinLabel(i+1));
535 paramPlot_HPD->GetXaxis()->SetBinLabel(i+1, prefit->GetXaxis()->GetBinLabel(i+1));
537 prefit->GetXaxis()->LabelsOption(
"v");
538 paramPlot->GetXaxis()->LabelsOption(
"v");\
539 paramPlot_Gauss->GetXaxis()->LabelsOption(
"v");
540 paramPlot_HPD->GetXaxis()->LabelsOption(
"v");
543 auto CompLeg = std::make_unique<TLegend>(0.33, 0.73, 0.76, 0.95);
544 CompLeg->AddEntry(prefit.get(),
"Prefit",
"fp");
545 CompLeg->AddEntry(paramPlot,
"Postfit PDF",
"fp");
546 CompLeg->AddEntry(paramPlot_Gauss,
"Postfit Gauss",
"fp");
547 CompLeg->AddEntry(paramPlot_HPD,
"Postfit HPD",
"lfep");
548 CompLeg->SetFillColor(0);
549 CompLeg->SetFillStyle(0);
550 CompLeg->SetLineWidth(0);
551 CompLeg->SetLineStyle(0);
552 CompLeg->SetBorderSize(0);
568 else prefit->GetYaxis()->SetTitle(
"Parameter Value");
569 prefit->GetYaxis()->SetRangeUser(-2.5, 2.5);
571 prefit->GetXaxis()->SetRangeUser(Start, Start +
nParam[
kXSecPar]-nFlux);
572 paramPlot->GetXaxis()->SetRangeUser(Start, Start +
nParam[
kXSecPar]-nFlux);
573 paramPlot_Gauss->GetXaxis()->SetRangeUser(Start, Start+
nParam[
kXSecPar]-nFlux);
574 paramPlot_HPD->GetXaxis()->SetRangeUser(Start, Start +
nParam[
kXSecPar]-nFlux);
577 prefit->Write(
"param_xsec_prefit");
578 paramPlot->Write(
"param_xsec");
579 paramPlot_Gauss->Write(
"param_xsec_gaus");
580 paramPlot_HPD->Write(
"param_xsec_HPD");
584 paramPlot->Draw(
"e2, same");
585 paramPlot_Gauss->Draw(
"e2, same");
586 paramPlot_HPD->Draw(
"e1, same");
587 CompLeg->Draw(
"same");
595 prefit->GetYaxis()->SetRangeUser(0.7, 1.3);
596 paramPlot->GetYaxis()->SetRangeUser(0.7, 1.3);
597 paramPlot_Gauss->GetYaxis()->SetRangeUser(0.7, 1.3);
598 paramPlot_HPD->GetYaxis()->SetRangeUser(0.7, 1.3);
605 prefit->Write(
"param_flux_prefit");
606 paramPlot->Write(
"param_flux");
607 paramPlot_Gauss->Write(
"param_flux_gaus");
608 paramPlot_HPD->Write(
"param_flux_HPD");
611 paramPlot->Draw(
"e2, same");
612 paramPlot_Gauss->Draw(
"e1, same");
613 paramPlot_HPD->Draw(
"e1, same");
614 CompLeg->Draw(
"same");
622 int NDbinCounter = Start;
629 prefit->GetYaxis()->SetTitle((
"Variation for "+NDname).c_str());
630 prefit->GetYaxis()->SetRangeUser(0.6, 1.4);
631 prefit->GetXaxis()->SetRangeUser(Start, NDbinCounter);
633 paramPlot->GetYaxis()->SetTitle((
"Variation for "+NDname).c_str());
634 paramPlot->GetYaxis()->SetRangeUser(0.6, 1.4);
635 paramPlot->GetXaxis()->SetRangeUser(Start, NDbinCounter);
636 paramPlot->SetTitle(CutPosterior1D.c_str());
638 paramPlot_Gauss->GetYaxis()->SetTitle((
"Variation for "+NDname).c_str());
639 paramPlot_Gauss->GetYaxis()->SetRangeUser(0.6, 1.4);
640 paramPlot_Gauss->GetXaxis()->SetRangeUser(Start, NDbinCounter);
641 paramPlot_Gauss->SetTitle(CutPosterior1D.c_str());
643 paramPlot_HPD->GetYaxis()->SetTitle((
"Variation for "+NDname).c_str());
644 paramPlot_HPD->GetYaxis()->SetRangeUser(0.6, 1.4);
645 paramPlot_HPD->GetXaxis()->SetRangeUser(Start, NDbinCounter);
646 paramPlot_HPD->SetTitle(CutPosterior1D.c_str());
648 prefit->Write((
"param_"+NDname+
"_prefit").c_str());
649 paramPlot->Write((
"param_"+NDname).c_str());
650 paramPlot_Gauss->Write((
"param_"+NDname+
"_gaus").c_str());
651 paramPlot_HPD->Write((
"param_"+NDname+
"_HPD").c_str());
654 paramPlot->Draw(
"e2, same");
655 paramPlot_Gauss->Draw(
"e1, same");
656 paramPlot_HPD->Draw(
"e1, same");
657 CompLeg->Draw(
"same");
658 Posterior->Write((
"param_"+NDname+
"_canv").c_str());
665 delete paramPlot_Gauss;
666 delete paramPlot_HPD;
675 const std::vector<Color_t>& CredibleIntervalsColours,
676 const bool CredibleInSigmas) {
681 const double LeftMargin =
Posterior->GetLeftMargin();
686 const int nCredible = int(CredibleIntervals.size());
687 std::vector<std::unique_ptr<TH1D>> hpost_copy(
nDraw);
688 std::vector<std::vector<std::unique_ptr<TH1D>>> hpost_cl(
nDraw);
691 for (
int i = 0; i <
nDraw; ++i)
693 hpost_copy[i] = M3::Clone<TH1D>(
hpost[i], Form(
"hpost_copy_%i", i));
694 hpost_cl[i].resize(nCredible);
695 for (
int j = 0; j < nCredible; ++j)
697 hpost_cl[i][j] = M3::Clone<TH1D>(
hpost[i], Form(
"hpost_copy_%i_CL_%f", i, CredibleIntervals[j]));
700 hpost_cl[i][j]->Reset(
"");
701 hpost_cl[i][j]->Fill(0.0, 0.0);
706 #pragma omp parallel for
708 for (
int i = 0; i <
nDraw; ++i)
711 hpost_copy[i]->Scale(1. / hpost_copy[i]->Integral());
712 for (
int j = 0; j < nCredible; ++j)
715 hpost_cl[i][j]->Scale(1. / hpost_cl[i][j]->Integral());
718 hpost_cl[i][j]->SetFillColor(CredibleIntervalsColours[j]);
719 hpost_cl[i][j]->SetLineWidth(1);
721 hpost_copy[i]->GetYaxis()->SetTitleOffset(1.8);
722 hpost_copy[i]->SetLineWidth(1);
723 hpost_copy[i]->SetMaximum(hpost_copy[i]->GetMaximum()*1.2);
724 hpost_copy[i]->SetLineWidth(2);
725 hpost_copy[i]->SetLineColor(kBlack);
726 hpost_copy[i]->GetYaxis()->SetTitle(
"Posterior Probability");
730 TDirectory *CredibleDir =
OutputFile->mkdir(
"Credible");
732 for (
int i = 0; i <
nDraw; ++i)
738 double Prior = 1.0, PriorError = 1.0;
741 auto Asimov = std::make_unique<TLine>(Prior, hpost_copy[i]->GetMinimum(), Prior, hpost_copy[i]->GetMaximum());
744 auto legend = std::make_unique<TLegend>(0.20, 0.7, 0.4, 0.92);
746 hpost_copy[i]->Draw(
"HIST");
748 for (
int j = 0; j < nCredible; ++j)
749 hpost_cl[i][j]->Draw(
"HIST SAME");
750 for (
int j = nCredible-1; j >= 0; --j)
753 legend->AddEntry(hpost_cl[i][j].get(), Form(
"%.0f#sigma Credible Interval", CredibleIntervals[j]),
"f");
755 legend->AddEntry(hpost_cl[i][j].get(), Form(
"%.0f%% Credible Interval", CredibleIntervals[j]*100),
"f");
757 legend->AddEntry(Asimov.get(), Form(
"#splitline{Prior}{x = %.2f , #sigma = %.2f}", Prior, PriorError),
"l");
758 legend->Draw(
"SAME");
759 Asimov->Draw(
"SAME");
770 CredibleDir->Close();
791 for (
int i = 1; i <
nDraw; ++i)
796 maxi_y = std::max(maxi_y, max_val);
797 mini_y = std::min(mini_y, min_val);
800 const int vBins = (maxi_y-mini_y)*25;
801 hviolin = std::make_unique<TH2D>(
"hviolin",
"hviolin",
nDraw, 0,
nDraw, vBins, mini_y, maxi_y);
802 hviolin->SetDirectory(
nullptr);
804 constexpr int PriorFactor = 4;
805 hviolin_prior = std::make_unique<TH2D>(
"hviolin_prior",
"hviolin_prior",
nDraw, 0,
nDraw, PriorFactor*vBins, PriorFactor*mini_y, PriorFactor*maxi_y);
808 auto rand = std::make_unique<TRandom3>(0);
809 std::vector<double> PriorVec(
nDraw);
810 std::vector<double> PriorErrorVec(
nDraw);
811 std::vector<bool> PriorFlatVec(
nDraw);
813 for (
int x = 0; x <
nDraw; ++x)
816 double Prior, PriorError;
820 hviolin->GetXaxis()->SetBinLabel(x+1, Title);
823 PriorErrorVec[x] = PriorError;
827 PriorFlatVec[x] =
ParamFlat[ParType][ParamTemp];
835 #pragma omp parallel for
837 for (
int x = 0; x <
nDraw; ++x)
859 const double Entry = rand->Gaus(PriorVec[x], PriorErrorVec[x]);
869 constexpr int IntervalsSize = 10;
870 const int NIntervals =
nDraw/IntervalsSize;
872 hviolin->GetYaxis()->SetTitle(
"Parameter Value");
873 hviolin->GetXaxis()->SetTitle();
874 hviolin->GetXaxis()->LabelsOption(
"v");
891 hviolin->SetMarkerColor(kBlue);
892 hviolin->SetFillColorAlpha(kBlue, 0.35);
896 const double BottomMargin =
Posterior->GetBottomMargin();
900 hviolin->Write(
"param_violin");
903 hviolin->GetYaxis()->SetRangeUser(-1, +2);
905 for (
int i = 0; i < NIntervals+1; ++i)
907 hviolin->GetXaxis()->SetRangeUser(i*IntervalsSize, i*IntervalsSize+IntervalsSize);
908 hviolin_prior->GetXaxis()->SetRangeUser(i*IntervalsSize, i*IntervalsSize+IntervalsSize);
909 if(i == NIntervals+1)
911 hviolin->GetXaxis()->SetRangeUser(i*IntervalsSize,
nDraw);
916 hviolin->Draw(
"violinX(03100300) SAME");
920 Posterior->SetBottomMargin(BottomMargin);
929 bool HaveMadeDiagonal =
false;
933 for (
int i = 0; i <
nDraw; ++i) {
935 HaveMadeDiagonal =
false;
936 MACH3LOG_INFO(
"Have not run diagonal elements in covariance, will do so now by calling MakePostfit()");
939 HaveMadeDiagonal =
true;
943 if (HaveMadeDiagonal ==
false) {
946 gStyle->SetPalette(55);
948 for (
int i = 0; i <
nDraw; ++i)
950 if (i % (
nDraw/5) == 0)
953 TString Title_i =
"";
954 double Prior_i, PriorError;
962 for (
int j = 0; j <= i; ++j) {
964 if (j == i)
continue;
968 (*Covariance)(i,j) = 0.0;
970 (*Correlation)(i,j) = 0.0;
975 TString Title_j =
"";
976 double Prior_j, PriorError_j;
988 std::unique_ptr<TH2D> hpost_2D = std::make_unique<TH2D>(DrawMe, DrawMe,
nBins, min_i, max_i,
nBins, min_j, max_j);
989 hpost_2D->SetMinimum(0);
990 hpost_2D->GetXaxis()->SetTitle(Title_i);
991 hpost_2D->GetYaxis()->SetTitle(Title_j);
992 hpost_2D->GetZaxis()->SetTitle(
"Steps");
999 (*Covariance)(i,j) = hpost_2D->GetCovariance();
1002 (*Correlation)(i,j) = hpost_2D->GetCorrelationFactor();
1013 hpost_2D->Draw(
"colz");
1014 Posterior->SetName(hpost_2D->GetName());
1015 Posterior->SetTitle(hpost_2D->GetTitle());
1041 MACH3LOG_ERROR(
"Even though it is used for MakeCovariance_MP and for DiagMCMC ");
1042 MACH3LOG_ERROR(
"it has different structure in both for cache hits, sorry ");
1055 for (
int i = 0; i <
nDraw; ++i)
1068 Chain->SetBranchStatus(
"*",
false);
1070 double* ParValBranch =
new double[
nEntries]();
1072 for (
int i = 0; i <
nDraw; ++i)
1077 Chain->SetBranchStatus(
"step",
true);
1078 Chain->SetBranchAddress(
"step", &stepBranch);
1079 const Long64_t countwidth =
nEntries/10;
1083 for (Long64_t j = 0; j <
nEntries; ++j)
1085 if (j % countwidth == 0) {
1093 for (
int i = 0; i <
nDraw; ++i)
1095 ParStep[i][j] = ParValBranch[i];
1098 delete[] ParValBranch;
1101 Chain->SetBranchStatus(
"*",
true);
1104 double tempVal = 0.0;
1105 std::vector<double> Min_Chain(
nDraw);
1106 std::vector<double> Max_Chain(
nDraw);
1107 for (
int i = 0; i <
nDraw; ++i)
1115 for (
int i = 0; i <
nDraw; ++i)
1117 TString Title_i =
"";
1118 double Prior_i, PriorError_i;
1121 for (
int j = 0; j <= i; ++j)
1124 hpost2D[i][j] =
new TH2D(Form(
"hpost2D_%i_%i",i,j), Form(
"hpost2D_%i_%i",i,j),
nBins, Min_Chain[i], Max_Chain[i],
nBins, Min_Chain[j], Max_Chain[j]);
1125 TString Title_j =
"";
1126 double Prior_j, PriorError_j;
1130 hpost2D[i][j]->GetXaxis()->SetTitle(Title_i);
1131 hpost2D[i][j]->GetYaxis()->SetTitle(Title_j);
1132 hpost2D[i][j]->GetZaxis()->SetTitle(
"Steps");
1147 bool HaveMadeDiagonal =
false;
1150 for (
int i = 0; i <
nDraw; ++i) {
1152 HaveMadeDiagonal =
false;
1153 MACH3LOG_WARN(
"Have not run diagonal elements in covariance, will do so now by calling MakePostfit()");
1156 HaveMadeDiagonal =
true;
1163 if(!Mute) clock.Start();
1165 gStyle->SetPalette(55);
1168 #pragma omp parallel for
1170 for (
int i = 0; i <
nDraw; ++i)
1172 for (
int j = 0; j <= i; ++j)
1175 if (j == i)
continue;
1179 (*Covariance)(i,j) = 0.0;
1181 (*Correlation)(i,j) = 0.0;
1203 (*Correlation)(i,j) =
hpost2D[i][j]->GetCorrelationFactor();
1216 for (
int i = 0; i <
nDraw; ++i)
1218 for (
int j = 0; j <= i; ++j)
1221 if (j == i)
continue;
1251 const int DefaultUpperCut =
UpperCut;
1261 const int IntervalsSize =
nSteps/NIntervals;
1267 std::unique_ptr<TH1D> SubOptimality = std::make_unique<TH1D>(
"Suboptimality",
"Suboptimality", NIntervals, MinStep, MaxStep);
1268 SubOptimality->GetXaxis()->SetTitle(
"Step");
1269 SubOptimality->GetYaxis()->SetTitle(
"Suboptimality");
1270 SubOptimality->SetLineWidth(2);
1271 SubOptimality->SetLineColor(kBlue);
1273 for(
int i = 0; i < NIntervals; ++i)
1285 TVectorD eigen_values;
1286 eigen_values.ResizeTo(eigen.GetEigenValues());
1287 eigen_values = eigen.GetEigenValues();
1290 std::vector<double> EigenValues(eigen_values.GetNrows());
1291 for(
unsigned int j = 0; j < EigenValues.size(); j++)
1293 EigenValues[j] = eigen_values(j);
1296 SubOptimality->SetBinContent(i+1, SubOptimalityValue);
1299 MACH3LOG_INFO(
"Making Suboptimality took {:.2f}s to finish for {} steps", clock.RealTime(),
nEntries);
1305 SubOptimality->Draw(
"l");
1306 Posterior->SetName(SubOptimality->GetName());
1307 Posterior->SetTitle(SubOptimality->GetTitle());
1319 const double RightMargin =
Posterior->GetRightMargin();
1323 std::unique_ptr<TH2D> hCov = std::make_unique<TH2D>(
"hCov",
"hCov",
nDraw, 0,
nDraw,
nDraw, 0,
nDraw);
1324 hCov->GetZaxis()->SetTitle(
"Covariance");
1326 std::unique_ptr<TH2D> hCovSq = std::make_unique<TH2D>(
"hCovSq",
"hCovSq",
nDraw, 0,
nDraw,
nDraw, 0,
nDraw);
1327 hCovSq->GetZaxis()->SetTitle(
"Covariance");
1329 std::unique_ptr<TH2D> hCorr = std::make_unique<TH2D>(
"hCorr",
"hCorr",
nDraw, 0,
nDraw,
nDraw, 0,
nDraw);
1330 hCorr->GetZaxis()->SetTitle(
"Correlation");
1331 hCorr->SetMinimum(-1);
1332 hCorr->SetMaximum(1);
1333 hCov->GetXaxis()->SetLabelSize(0.015);
1334 hCov->GetYaxis()->SetLabelSize(0.015);
1335 hCovSq->GetXaxis()->SetLabelSize(0.015);
1336 hCovSq->GetYaxis()->SetLabelSize(0.015);
1337 hCorr->GetXaxis()->SetLabelSize(0.015);
1338 hCorr->GetYaxis()->SetLabelSize(0.015);
1341 for (
int i = 0; i <
nDraw; ++i)
1343 TString titlex =
"";
1347 hCov->GetXaxis()->SetBinLabel(i+1, titlex);
1348 hCovSq->GetXaxis()->SetBinLabel(i+1, titlex);
1349 hCorr->GetXaxis()->SetBinLabel(i+1, titlex);
1351 for (
int j = 0; j <
nDraw; ++j)
1354 const double cov = (*Covariance)(i,j);
1355 const double corr = (*Correlation)(i,j);
1357 hCov->SetBinContent(i+1, j+1, cov);
1358 hCovSq->SetBinContent(i+1, j+1, ((cov > 0) - (cov < 0))*std::sqrt(std::fabs(cov)));
1359 hCorr->SetBinContent(i+1, j+1, corr);
1361 TString titley =
"";
1362 double nom_j, err_j;
1365 hCov->GetYaxis()->SetBinLabel(j+1, titley);
1366 hCovSq->GetYaxis()->SetBinLabel(j+1, titley);
1367 hCorr->GetYaxis()->SetBinLabel(j+1, titley);
1372 gStyle->SetOptStat(0);
1375 const int NRGBs = 5;
1376 TColor::InitializeColors();
1377 Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
1378 Double_t red[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50 };
1379 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00 };
1380 Double_t blue[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00 };
1381 TColor::CreateGradientColorTable(5, stops, red, green, blue, 255);
1382 gStyle->SetNumberContours(255);
1390 else hCov->Draw(
"colz");
1396 else hCorr->Draw(
"colz");
1399 hCov->Write(
"Covariance_plot");
1400 hCovSq->Write(
"Covariance_sq_plot");
1401 hCorr->Write(
"Correlation_plot");
1414 const int OptTitle = gStyle->GetOptTitle();
1418 gStyle->SetOptTitle(1);
1420 constexpr int Nhists = 3;
1422 constexpr double Thresholds[Nhists+1] = {0, 0.25, 0.5, 1.0001};
1423 constexpr Color_t CorrColours[Nhists] = {kRed-10, kRed-6, kRed};
1426 std::vector<std::vector<double>> CorrOfInterest;
1427 CorrOfInterest.resize(
nDraw);
1428 std::vector<std::vector<std::string>> NameCorrOfInterest;
1429 NameCorrOfInterest.resize(
nDraw);
1431 std::vector<std::vector<std::unique_ptr<TH1D>>> Corr1DHist(
nDraw);
1433 for(
int i = 0; i <
nDraw; ++i)
1436 double Prior = 1.0, PriorError = 1.0;
1439 Corr1DHist[i].resize(Nhists);
1440 for(
int j = 0; j < Nhists; ++j)
1442 Corr1DHist[i][j] = std::make_unique<TH1D>(Form(
"Corr1DHist_%i_%i", i, j), Form(
"Corr1DHist_%i_%i", i, j),
nDraw, 0,
nDraw);
1443 Corr1DHist[i][j]->SetTitle(Form(
"%s",Title.Data()));
1444 Corr1DHist[i][j]->GetYaxis()->SetTitle(
"Correlation");
1445 Corr1DHist[i][j]->SetFillColor(CorrColours[j]);
1446 Corr1DHist[i][j]->SetLineColor(kBlack);
1448 for (
int k = 0; k <
nDraw; ++k)
1450 TString Title_y =
"";
1451 double Prior_y = 1.0;
1452 double PriorError_y = 1.0;
1454 Corr1DHist[i][j]->GetXaxis()->SetBinLabel(k+1, Title_y.Data());
1460 #pragma omp parallel for
1462 for(
int i = 0; i <
nDraw; ++i)
1464 for(
int j = 0; j <
nDraw; ++j)
1466 for(
int k = 0; k < Nhists; ++k)
1468 const double TempEntry = std::fabs((*
Correlation)(i,j));
1469 if(Thresholds[k+1] > TempEntry && TempEntry >= Thresholds[k])
1471 Corr1DHist[i][k]->SetBinContent(j+1, (*
Correlation)(i,j));
1477 NameCorrOfInterest[i].push_back(Corr1DHist[i][0]->GetXaxis()->GetBinLabel(j+1));
1482 TDirectory *CorrDir =
OutputFile->mkdir(
"Corr1D");
1485 for(
int i = 0; i <
nDraw; i++)
1489 Corr1DHist[i][0]->SetMaximum(+1.);
1490 Corr1DHist[i][0]->SetMinimum(-1.);
1491 Corr1DHist[i][0]->Draw();
1492 for(
int k = 1; k < Nhists; k++) {
1493 Corr1DHist[i][k]->Draw(
"SAME");
1496 auto leg = std::make_unique<TLegend>(0.3, 0.75, 0.6, 0.90);
1498 for(
int k = 0; k < Nhists; k++) {
1499 leg->AddEntry(Corr1DHist[i][k].get(), Form(
"%.2f > |Corr| >= %.2f", Thresholds[k+1], Thresholds[k]),
"f");
1503 Posterior->Write(Corr1DHist[i][0]->GetTitle());
1508 for(
int i = 0; i <
nDraw; i++)
1510 const int size = int(CorrOfInterest[i].
size());
1512 if(
size == 0)
continue;
1513 auto Corr1DHist_Reduced = std::make_unique<TH1D>(
"Corr1DHist_Reduced",
"Corr1DHist_Reduced",
size, 0,
size);
1514 Corr1DHist_Reduced->SetTitle(Corr1DHist[i][0]->GetTitle());
1515 Corr1DHist_Reduced->GetYaxis()->SetTitle(
"Correlation");
1516 Corr1DHist_Reduced->SetFillColor(kBlue);
1517 Corr1DHist_Reduced->SetLineColor(kBlue);
1519 for (
int j = 0; j <
size; ++j)
1521 Corr1DHist_Reduced->GetXaxis()->SetBinLabel(j+1, NameCorrOfInterest[i][j].c_str());
1522 Corr1DHist_Reduced->SetBinContent(j+1, CorrOfInterest[i][j]);
1524 Corr1DHist_Reduced->GetXaxis()->LabelsOption(
"v");
1526 Corr1DHist_Reduced->SetMaximum(+1.);
1527 Corr1DHist_Reduced->SetMinimum(-1.);
1528 Corr1DHist_Reduced->Draw();
1530 Posterior->Write(Form(
"%s_Red", Corr1DHist_Reduced->GetTitle()));
1539 gStyle->SetOptTitle(OptTitle);
1545 const std::vector<Style_t>& CredibleRegionStyle,
1546 const std::vector<Color_t>& CredibleRegionColor,
1547 const bool CredibleInSigmas,
1548 const bool Draw2DPosterior,
1549 const bool DrawBestFit) {
1555 const int nCredible = int(CredibleRegions.size());
1557 std::vector<std::vector<std::unique_ptr<TH2D>>> hpost_2D_copy(
nDraw);
1558 std::vector<std::vector<std::vector<std::unique_ptr<TH2D>>>> hpost_2D_cl(
nDraw);
1560 for (
int i = 0; i <
nDraw; ++i)
1562 hpost_2D_copy[i].resize(
nDraw);
1563 hpost_2D_cl[i].resize(
nDraw);
1564 for (
int j = 0; j <= i; ++j)
1566 hpost_2D_copy[i][j] = M3::Clone<TH2D>(
hpost2D[i][j], Form(
"hpost_copy_%i_%i", i, j));
1567 hpost_2D_cl[i][j].resize(nCredible);
1568 for (
int k = 0; k < nCredible; ++k)
1570 hpost_2D_cl[i][j][k] = M3::Clone<TH2D>(
hpost2D[i][j], Form(
"hpost_copy_%i_%i_CL_%f", i, j, CredibleRegions[k]));
1576 #pragma omp parallel for
1579 for (
int i = 0; i <
nDraw; ++i)
1581 for (
int j = 0; j <= i; ++j)
1583 for (
int k = 0; k < nCredible; ++k)
1586 hpost_2D_cl[i][j][k]->SetLineColor(CredibleRegionColor[k]);
1587 hpost_2D_cl[i][j][k]->SetLineWidth(2);
1588 hpost_2D_cl[i][j][k]->SetLineStyle(CredibleRegionStyle[k]);
1593 gStyle->SetPalette(51);
1594 for (
int i = 0; i <
nDraw; ++i)
1596 for (
int j = 0; j <= i; ++j)
1599 if (j == i)
continue;
1602 auto legend = std::make_unique<TLegend>(0.20, 0.7, 0.4, 0.92);
1603 legend->SetTextColor(kRed);
1607 auto bestfitM = std::make_unique<TGraph>(1);
1608 const int MaxBin = hpost_2D_copy[i][j]->GetMaximumBin();
1610 hpost_2D_copy[i][j]->GetBinXYZ(MaxBin, Mbx, Mby, Mbz);
1611 const double Mx = hpost_2D_copy[i][j]->GetXaxis()->GetBinCenter(Mbx);
1612 const double My = hpost_2D_copy[i][j]->GetYaxis()->GetBinCenter(Mby);
1614 bestfitM->SetPoint(0, Mx, My);
1615 bestfitM->SetMarkerStyle(22);
1616 bestfitM->SetMarkerSize(1);
1617 bestfitM->SetMarkerColor(kMagenta);
1621 if(Draw2DPosterior){
1622 hpost_2D_copy[i][j]->Draw(
"COLZ");
1625 hpost_2D_copy[i][j]->Draw(
"AXIS");
1629 for (
int k = 0; k < nCredible; ++k)
1630 hpost_2D_cl[i][j][k]->Draw(
"CONT3 SAME");
1631 for (
int k = nCredible-1; k >= 0; --k)
1633 if(CredibleInSigmas)
1634 legend->AddEntry(hpost_2D_cl[i][j][k].get(), Form(
"%.0f#sigma Credible Interval", CredibleRegions[k]),
"l");
1636 legend->AddEntry(hpost_2D_cl[i][j][k].get(), Form(
"%.0f%% Credible Region", CredibleRegions[k]*100),
"l");
1638 legend->Draw(
"SAME");
1641 legend->AddEntry(bestfitM.get(),
"Best Fit",
"p");
1642 bestfitM->Draw(
"SAME.P");
1664 const std::vector<double>& CredibleIntervals,
1665 const std::vector<Color_t>& CredibleIntervalsColours,
1667 const std::vector<double>& CredibleRegions,
1668 const std::vector<Style_t>& CredibleRegionStyle,
1669 const std::vector<Color_t>& CredibleRegionColor,
1671 const bool CredibleInSigmas) {
1676 const int nParamPlot = int(ParNames.size());
1677 std::vector<int> ParamNumber;
1678 for(
int j = 0; j < nParamPlot; ++j)
1683 MACH3LOG_WARN(
"Couldn't find param {}. Will not plot Triangle plot", ParNames[j]);
1686 ParamNumber.push_back(ParamNo);
1697 auto FormatHistogram = [](
auto& hist) {
1698 hist->GetXaxis()->SetTitle(
"");
1699 hist->GetYaxis()->SetTitle(
"");
1702 hist->GetXaxis()->SetLabelSize(0.1);
1703 hist->GetYaxis()->SetLabelSize(0.1);
1705 hist->GetXaxis()->SetNdivisions(4);
1706 hist->GetYaxis()->SetNdivisions(4);
1714 std::sort(ParamNumber.begin(), ParamNumber.end(), std::greater<int>());
1718 for(
int j = 1; j < nParamPlot+1; j++) Npad += j;
1724 const int nCredibleIntervals = int(CredibleIntervals.size());
1725 const int nCredibleRegions = int(CredibleRegions.size());
1728 std::vector<TPad*> TrianglePad(Npad);
1730 std::vector<std::unique_ptr<TH1D>> hpost_copy(nParamPlot);
1731 std::vector<std::vector<std::unique_ptr<TH1D>>> hpost_cl(nParamPlot);
1732 std::vector<std::unique_ptr<TText>> TriangleText(nParamPlot * 2);
1733 std::vector<std::unique_ptr<TH2D>> hpost_2D_copy(Npad-nParamPlot);
1734 std::vector<std::vector<std::unique_ptr<TH2D>>> hpost_2D_cl(Npad-nParamPlot);
1735 gStyle->SetPalette(51);
1738 std::vector<double> X_Min(nParamPlot);
1739 std::vector<double> X_Max(nParamPlot);
1741 double xScale = (0.95 - (X_Min[0]+0.05))/nParamPlot;
1743 X_Max[0] = X_Min[0]+xScale+0.05;
1744 for(
int i = 1; i < nParamPlot; i++)
1746 X_Min[i] = X_Max[i-1];
1747 X_Max[i] = X_Min[i]+xScale;
1749 std::vector<double> Y_Min(nParamPlot);
1750 std::vector<double> Y_Max(nParamPlot);
1753 double yScale = std::fabs(0.10 - (Y_Max[0]))/nParamPlot;
1754 Y_Min[0] = Y_Max[0]-yScale;
1755 for(
int i = 1; i < nParamPlot; i++)
1757 Y_Max[i] = Y_Min[i-1];
1758 Y_Min[i] = Y_Max[i]-yScale;
1762 int counterPad = 0, counterText = 0, counterPost = 0, counter2DPost = 0;
1764 for(
int y = 0; y < nParamPlot; y++)
1767 for(
int x = 0; x <= y; x++)
1771 TrianglePad[counterPad] =
new TPad(Form(
"TPad_%i", counterPad), Form(
"TPad_%i", counterPad),
1772 X_Min[x], Y_Min[y], X_Max[x], Y_Max[y]);
1774 TrianglePad[counterPad]->SetTopMargin(0);
1775 TrianglePad[counterPad]->SetRightMargin(0);
1777 TrianglePad[counterPad]->SetGrid();
1778 TrianglePad[counterPad]->SetFrameBorderMode(0);
1779 TrianglePad[counterPad]->SetBorderMode(0);
1780 TrianglePad[counterPad]->SetBorderSize(0);
1783 TrianglePad[counterPad]->SetBottomMargin(y == (nParamPlot - 1) ? 0.1 : 0);
1785 TrianglePad[counterPad]->SetLeftMargin(x == 0 ? 0.15 : 0);
1787 TrianglePad[counterPad]->Draw();
1788 TrianglePad[counterPad]->cd();
1793 hpost_copy[counterPost] = M3::Clone<TH1D>(
hpost[ParamNumber[x]], Form(
"hpost_copy_%i", ParamNumber[x]));
1794 hpost_cl[counterPost].resize(nCredibleIntervals);
1796 hpost_copy[counterPost]->Scale(1. / hpost_copy[counterPost]->Integral());
1797 for (
int j = 0; j < nCredibleIntervals; ++j)
1799 hpost_cl[counterPost][j] = M3::Clone<TH1D>(
hpost[ParamNumber[x]], Form(
"hpost_copy_%i_CL_%f", ParamNumber[x], CredibleIntervals[j]));
1801 hpost_cl[counterPost][j]->Reset(
"");
1802 hpost_cl[counterPost][j]->Fill(0.0, 0.0);
1805 hpost_cl[counterPost][j]->Scale(1. / hpost_cl[counterPost][j]->Integral());
1806 GetCredibleIntervalSig(hpost_copy[counterPost], hpost_cl[counterPost][j], CredibleInSigmas, CredibleIntervals[j]);
1808 hpost_cl[counterPost][j]->SetFillColor(CredibleIntervalsColours[j]);
1809 hpost_cl[counterPost][j]->SetLineWidth(1);
1812 hpost_copy[counterPost]->SetMaximum(hpost_copy[counterPost]->GetMaximum()*1.2);
1813 hpost_copy[counterPost]->SetLineWidth(2);
1814 hpost_copy[counterPost]->SetLineColor(kBlack);
1817 FormatHistogram(hpost_copy[counterPost]);
1819 hpost_copy[counterPost]->Draw(
"HIST");
1820 for (
int j = 0; j < nCredibleIntervals; ++j){
1821 hpost_cl[counterPost][j]->Draw(
"HIST SAME");
1828 hpost_2D_copy[counter2DPost] = M3::Clone<TH2D>(
hpost2D[ParamNumber[x]][ParamNumber[y]],
1829 Form(
"hpost_copy_%i_%i", ParamNumber[x], ParamNumber[y]));
1830 hpost_2D_cl[counter2DPost].resize(nCredibleRegions);
1832 for (
int k = 0; k < nCredibleRegions; ++k)
1834 hpost_2D_cl[counter2DPost][k] = M3::Clone<TH2D>(
hpost2D[ParamNumber[x]][ParamNumber[y]],
1835 Form(
"hpost_copy_%i_%i_CL_%f", ParamNumber[x], ParamNumber[y], CredibleRegions[k]));
1838 hpost_2D_cl[counter2DPost][k]->SetLineColor(CredibleRegionColor[k]);
1839 hpost_2D_cl[counter2DPost][k]->SetLineWidth(2);
1840 hpost_2D_cl[counter2DPost][k]->SetLineStyle(CredibleRegionStyle[k]);
1843 FormatHistogram(hpost_2D_copy[counter2DPost]);
1845 hpost_2D_copy[counter2DPost]->Draw(
"COL");
1847 for (
int k = 0; k < nCredibleRegions; ++k){
1848 hpost_2D_cl[counter2DPost][k]->Draw(
"CONT3 SAME");
1853 if(y == (nParamPlot-1))
1856 TriangleText[counterText] = std::make_unique<TText>(X_Min[x]+ (X_Max[x]-X_Min[x])/4, 0.04,
hpost[ParamNumber[x]]->GetTitle());
1858 TriangleText[counterText]->SetTextSize(0.015);
1859 TriangleText[counterText]->SetNDC(
true);
1860 TriangleText[counterText]->Draw();
1867 TriangleText[counterText] = std::make_unique<TText>(0.04, Y_Min[y] + (Y_Max[y]-Y_Min[y])/4,
hpost[ParamNumber[y]]->GetTitle());
1869 TriangleText[counterText]->SetTextAngle(90);
1871 TriangleText[counterText]->SetTextSize(0.015);
1872 TriangleText[counterText]->SetNDC(
true);
1873 TriangleText[counterText]->Draw();
1882 auto legend = std::make_unique<TLegend>(0.60, 0.7, 0.9, 0.9);
1885 for (
int j = nCredibleIntervals-1; j >= 0; --j)
1887 if(CredibleInSigmas)
1888 legend->AddEntry(hpost_cl[0][j].get(), Form(
"%.0f#sigma Credible Interval", CredibleIntervals[j]),
"f");
1890 legend->AddEntry(hpost_cl[0][j].get(), Form(
"%.0f%% Credible Interval", CredibleRegions[j]*100),
"f");
1892 for (
int k = nCredibleRegions-1; k >= 0; --k)
1894 if(CredibleInSigmas)
1895 legend->AddEntry(hpost_2D_cl[0][k].get(), Form(
"%.0f#sigma Credible Region", CredibleRegions[k]),
"l");
1897 legend->AddEntry(hpost_2D_cl[0][k].get(), Form(
"%.0f%% Credible Region", CredibleRegions[k]*100),
"l");
1899 legend->Draw(
"SAME");
1912 for(
int i = 0; i < Npad; i++)
delete TrianglePad[i];
1928 Chain =
new TChain(
"posteriors",
"posteriors");
1937 TObjArray* brlis =
Chain->GetListOfBranches();
1949 Chain->SetBranchStatus(
"*",
false);
1956 TBranch* br =
static_cast<TBranch*
>(brlis->At(i));
1961 TString bname = br->GetName();
1964 bool rejected =
false;
1973 if(rejected)
continue;
1976 Chain->SetBranchStatus(bname.Data(),
true);
1978 if (bname.BeginsWith(
"ndd_"))
1984 else if (bname.BeginsWith(
"skd_joint_"))
1992 if (bname.BeginsWith(
"LogL_sample_")) {
1996 else if (bname.BeginsWith(
"LogL_systematic_")) {
2040 Gauss = std::make_unique<TF1>(
"Gauss",
"[0]/sqrt(2.0*3.14159)/[2]*TMath::Exp(-0.5*pow(x-[1],2)/[2]/[2])", -5, 5);
2041 Gauss->SetLineWidth(2);
2042 Gauss->SetLineColor(kOrange-5);
2059 #pragma omp parallel for
2061 for (
int i = 0; i <
nDraw; ++i)
2063 (*Central_Value)(i) =
_UNDEF_;
2070 (*Errors_HPD_Positive)(i) =
_UNDEF_;
2071 (*Errors_HPD_Negative)(i) =
_UNDEF_;
2072 for (
int j = 0; j <
nDraw; ++j) {
2073 (*Covariance)(i, j) =
_UNDEF_;
2074 (*Correlation)(i, j) =
_UNDEF_;
2086 for(
unsigned int j = 0; j <
ParamType.size(); j++)
2104 auto PreFitPlot = std::make_unique<TH1D>(
"Prefit",
"Prefit",
nDraw, 0,
nDraw);
2105 PreFitPlot->SetDirectory(
nullptr);
2106 for (
int i = 0; i < PreFitPlot->GetNbinsX() + 1; ++i) {
2107 PreFitPlot->SetBinContent(i+1, 0);
2108 PreFitPlot->SetBinError(i+1, 0);
2113 double CentralValueTemp, Central, Error;
2116 for (
int i = 0; i <
nDraw; ++i)
2125 if ( CentralValueTemp != 0) {
2126 Central =
ParamCentral[ParamEnum][ParamNo] / CentralValueTemp;
2127 Error =
ParamErrors[ParamEnum][ParamNo]/CentralValueTemp;
2129 Central = CentralValueTemp + 1.0;
2135 Central = CentralValueTemp;
2142 PreFitPlot->SetBinContent(i+1, Central);
2143 PreFitPlot->SetBinError(i+1, Error);
2144 PreFitPlot->GetXaxis()->SetBinLabel(i+1,
ParamNames[ParamEnum][ParamNo]);
2146 PreFitPlot->SetDirectory(
nullptr);
2148 PreFitPlot->SetFillStyle(1001);
2149 PreFitPlot->SetFillColor(kRed-3);
2150 PreFitPlot->SetMarkerStyle(21);
2151 PreFitPlot->SetMarkerSize(2.4);
2152 PreFitPlot->SetMarkerColor(kWhite);
2153 PreFitPlot->SetLineColor(PreFitPlot->GetFillColor());
2154 PreFitPlot->GetXaxis()->LabelsOption(
"v");
2183 TFile *TempFile =
new TFile(
MCMCFile.c_str(),
"open");
2184 TDirectory* CovarianceFolder = TempFile->Get<TDirectory>(
"CovarianceFolder");
2187 TMacro *Config = TempFile->Get<TMacro>(
"MaCh3_Config");
2189 if (Config ==
nullptr) {
2195 if (std::getenv(
"MACH3") !=
nullptr) {
2196 MACH3LOG_INFO(
"Found MACH3 environment variable: {}", std::getenv(
"MACH3"));
2203 bool InputNotFound =
false;
2205 CovPos[
kXSecPar] = GetFromManager<std::vector<std::string>>(Settings[
"General"][
"Systematics"][
"XsecCovFile"], {
"none"});
2209 InputNotFound =
true;
2213 if (XsecConfig ==
nullptr) {
2220 if (
const char * mach3_env = std::getenv(
"MACH3"))
2231 CovarianceFolder->Close();
2232 delete CovarianceFolder;
2242 TFile *TempFile =
new TFile(
MCMCFile.c_str(),
"open");
2245 TMacro *Config = TempFile->Get<TMacro>(
"MaCh3_Config");
2247 if (Config ==
nullptr) {
2255 CovPos[
kNDPar].push_back(GetFromManager<std::string>(Settings[
"General"][
"Systematics"][
"NDCovFile"],
"none"));
2257 MACH3LOG_WARN(
"Couldn't find NDCov (legacy) branch in output");
2261 CovPos[
kFDDetPar].push_back(GetFromManager<std::string>(Settings[
"General"][
"Systematics"][
"FDCovFile"],
"none"));
2263 MACH3LOG_WARN(
"Couldn't find FDCov (legacy) branch in output");
2266 if (
const char * mach3_env = std::getenv(
"MACH3"))
2269 CovPos[
kNDPar][i].insert(0, std::string(mach3_env)+
"/");
2284 auto systematics = XSecFile[
"Systematics"];
2286 for (
auto it = systematics.begin(); it != systematics.end(); ++it, ++paramIndex )
2288 auto const ¶m = *it;
2290 std::string TempString = (param[
"Systematic"][
"Names"][
"FancyName"].as<std::string>());
2292 bool rejected =
false;
2301 if(rejected)
continue;
2304 ParamCentral[
kXSecPar].push_back(param[
"Systematic"][
"ParameterValues"][
"PreFitValue"].as<double>());
2305 ParamNom[
kXSecPar].push_back(param[
"Systematic"][
"ParameterValues"][
"Generated"].as<double>());
2307 ParamFlat[
kXSecPar].push_back(GetFromManager<bool>(param[
"Systematic"][
"FlatPrior"],
false));
2309 ParameterGroup.push_back(param[
"Systematic"][
"ParameterGroup"].as<std::string>());
2317 BranchNames.push_back(
"xsec_" + std::to_string(paramIndex));
2333 TFile *NDdetFile =
new TFile(
CovPos[
kNDPar].back().c_str(),
"open");
2334 if (NDdetFile->IsZombie()) {
2340 TMatrixDSym *NDdetMatrix = NDdetFile->Get<TMatrixDSym>(
"nddet_cov");
2341 TVectorD *NDdetNominal = NDdetFile->Get<TVectorD>(
"det_weights");
2342 TDirectory *BinningDirectory = NDdetFile->Get<TDirectory>(
"Binning");
2344 for (
int i = 0; i < NDdetNominal->GetNrows(); ++i)
2355 TIter next(BinningDirectory->GetListOfKeys());
2356 TKey *key =
nullptr;
2358 while ((key =
static_cast<TKey*
>(next())))
2360 std::string name = std::string(key->GetName());
2361 TH2Poly* RefPoly = BinningDirectory->Get<TH2Poly>((name).c_str());
2362 int size = RefPoly->GetNumberOfBins();
2376 TFile *FDdetFile =
new TFile(
CovPos[
kFDDetPar].back().c_str(),
"open");
2377 if (FDdetFile->IsZombie()) {
2383 TMatrixDSym *FDdetMatrix = FDdetFile->Get<TMatrixDSym>(
"SKJointError_Erec_Total");
2385 for (
int i = 0; i < FDdetMatrix->GetNrows(); ++i)
2417 std::stringstream TempStream;
2418 TempStream <<
"step > " << Cuts;
2441 for (
int i = 0; i <
nDraw; ++i)
2444 double Prior = 1.0, PriorError = 1.0;
2461 #pragma omp parallel for
2463 for (
int i = 0; i <
nDraw; ++i)
2465 for (
int j = 0; j <= i; ++j)
2469 hpost2D[i][j]->Fill(0.0, 0.0, 0.0);
2489 TDirectory *PolarDir =
OutputFile->mkdir(
"PolarDir");
2492 for(
unsigned int k = 0; k < ParNames.size(); ++k)
2498 MACH3LOG_WARN(
"Couldn't find param {}. Will not calculate Polar Plot", ParNames[k]);
2503 double Prior = 1.0, PriorError = 1.0;
2506 std::vector<double> x_val(
nBins);
2507 std::vector<double> y_val(
nBins);
2510 double xmax = 2*TMath::Pi();
2512 double Integral =
hpost[ParamNo]->Integral();
2513 for (Int_t ipt = 0; ipt <
nBins; ipt++)
2515 x_val[ipt] = ipt*(xmax-xmin)/
nBins+xmin;
2516 y_val[ipt] =
hpost[ParamNo]->GetBinContent(ipt+1)/Integral;
2519 auto PolarGraph = std::make_unique<TGraphPolar>(
nBins, x_val.data(), y_val.data());
2520 PolarGraph->SetLineWidth(2);
2521 PolarGraph->SetFillStyle(3001);
2522 PolarGraph->SetLineColor(kRed);
2523 PolarGraph->SetFillColor(kRed);
2524 PolarGraph->Draw(
"AFL");
2526 auto Text = std::make_unique<TText>(0.6, 0.1, Title);
2527 Text->SetTextSize(0.04);
2546 const std::vector<std::vector<double>>& Model1Bounds,
2547 const std::vector<std::vector<double>>& Model2Bounds,
2548 const std::vector<std::vector<std::string>>& ModelNames){
2553 if((ParNames.size() != Model1Bounds.size()) || (Model2Bounds.size() != Model1Bounds.size()) || (Model2Bounds.size() != ModelNames.size()))
2558 for(
unsigned int k = 0; k < ParNames.size(); ++k)
2564 MACH3LOG_WARN(
"Couldn't find param {}. Will not calculate Bayes Factor", ParNames[k]);
2568 const double M1_min = Model1Bounds[k][0];
2569 const double M2_min = Model2Bounds[k][0];
2570 const double M1_max = Model1Bounds[k][1];
2571 const double M2_max = Model2Bounds[k][1];
2573 long double IntegralMode1 =
hpost[ParamNo]->Integral(
hpost[ParamNo]->FindFixBin(M1_min),
hpost[ParamNo]->FindFixBin(M1_max));
2574 long double IntegralMode2 =
hpost[ParamNo]->Integral(
hpost[ParamNo]->FindFixBin(M2_min),
hpost[ParamNo]->FindFixBin(M2_max));
2576 double BayesFactor = 0.;
2577 std::string Name =
"";
2580 if(IntegralMode1 >= IntegralMode2)
2582 BayesFactor = IntegralMode1/IntegralMode2;
2583 Name =
"\\mathfrak{B}(" + ModelNames[k][0]+
"/" + ModelNames[k][1] +
") = " + std::to_string(BayesFactor);
2587 BayesFactor = IntegralMode2/IntegralMode1;
2588 Name =
"\\mathfrak{B}(" + ModelNames[k][1]+
"/" + ModelNames[k][0] +
") = " + std::to_string(BayesFactor);
2594 MACH3LOG_INFO(
"Following Jeffreys Scale = {}", JeffreysScale);
2595 MACH3LOG_INFO(
"Following Dunne-Kaboth Scale = {}", DunneKabothScale);
2603 const std::vector<double>& EvaluationPoint,
2604 const std::vector<std::vector<double>>& Bounds){
2606 if((ParNames.size() != EvaluationPoint.size()) || (Bounds.size() != EvaluationPoint.size()))
2615 TDirectory *SavageDickeyDir =
OutputFile->mkdir(
"SavageDickey");
2616 SavageDickeyDir->cd();
2618 for(
unsigned int k = 0; k < ParNames.size(); ++k)
2624 MACH3LOG_WARN(
"Couldn't find param {}. Will not calculate SavageDickey", ParNames[k]);
2629 double Prior = 1.0, PriorError = 1.0;
2630 bool FlatPrior =
false;
2635 FlatPrior =
ParamFlat[ParType][ParamTemp];
2637 TH1D* PosteriorHist =
static_cast<TH1D *
>(
hpost[ParamNo]->Clone(Title));
2640 TH1D* PriorHist =
nullptr;
2644 int NBins = PosteriorHist->GetNbinsX();
2645 if(Bounds[k][0] > Bounds[k][1])
2650 PriorHist =
new TH1D(
"PriorHist", Title, NBins, Bounds[k][0], Bounds[k][1]);
2652 double FlatProb = ( Bounds[k][1] - Bounds[k][0]) / NBins;
2653 for (
int g = 0; g < NBins + 1; ++g)
2655 PriorHist->SetBinContent(g+1, FlatProb);
2660 PriorHist =
static_cast<TH1D*
>(PosteriorHist->Clone(
"Prior"));
2661 PriorHist->Reset(
"");
2662 PriorHist->Fill(0.0, 0.0);
2664 auto rand = std::make_unique<TRandom3>(0);
2666 for(
int g = 0; g < 1000000; ++g)
2668 PriorHist->Fill(rand->Gaus(Prior, PriorError));
2672 PriorHist->Scale(1./PriorHist->Integral(),
"width");
2673 PosteriorHist->Scale(1./PosteriorHist->Integral(),
"width");
2675 PriorHist->SetLineColor(kRed);
2676 PriorHist->SetMarkerColor(kRed);
2677 PriorHist->SetFillColorAlpha(kRed, 0.35);
2678 PriorHist->SetFillStyle(1001);
2679 PriorHist->GetXaxis()->SetTitle(Title);
2680 PriorHist->GetYaxis()->SetTitle(
"Posterior Probability");
2681 PriorHist->SetMaximum(PosteriorHist->GetMaximum()*1.5);
2682 PriorHist->GetYaxis()->SetLabelOffset(999);
2683 PriorHist->GetYaxis()->SetLabelSize(0);
2684 PriorHist->SetLineWidth(2);
2685 PriorHist->SetLineStyle(kSolid);
2687 PosteriorHist->SetLineColor(kBlue);
2688 PosteriorHist->SetMarkerColor(kBlue);
2689 PosteriorHist->SetFillColorAlpha(kBlue, 0.35);
2690 PosteriorHist->SetFillStyle(1001);
2692 PriorHist->Draw(
"hist");
2693 PosteriorHist->Draw(
"hist same");
2695 double ProbPrior = PriorHist->GetBinContent(PriorHist->FindBin(EvaluationPoint[k]));
2697 if(ProbPrior < 0) ProbPrior = 0.00001;
2698 double ProbPosterior = PosteriorHist->GetBinContent(PosteriorHist->FindBin(EvaluationPoint[k]));
2699 double SavageDickey = ProbPosterior/ProbPrior;
2703 std::unique_ptr<TGraph> PostPoint(
new TGraph(1));
2704 PostPoint->SetPoint(0, EvaluationPoint[k], ProbPosterior);
2705 PostPoint->SetMarkerStyle(20);
2706 PostPoint->SetMarkerSize(1);
2707 PostPoint->Draw(
"P same");
2709 std::unique_ptr<TGraph> PriorPoint(
new TGraph(1));
2710 PriorPoint->SetPoint(0, EvaluationPoint[k], ProbPrior);
2711 PriorPoint->SetMarkerStyle(20);
2712 PriorPoint->SetMarkerSize(1);
2713 PriorPoint->Draw(
"P same");
2715 auto legend = std::make_unique<TLegend>(0.12, 0.6, 0.6, 0.97);
2717 legend->AddEntry(PriorHist,
"Prior",
"l");
2718 legend->AddEntry(PosteriorHist,
"Posterior",
"l");
2719 legend->AddEntry(PostPoint.get(), Form(
"SavageDickey = %.2f, (%s)", SavageDickey, DunneKabothScale.c_str()),
"");
2720 legend->Draw(
"same");
2725 delete PosteriorHist;
2729 SavageDickeyDir->Close();
2730 delete SavageDickeyDir;
2738 const std::vector<double>& NewCentral,
2739 const std::vector<double>& NewError) {
2743 if( (Names.size() != NewCentral.size()) || (NewCentral.size() != NewError.size()))
2745 MACH3LOG_ERROR(
"Size of passed vectors doesn't match in ReweightPrior");
2748 std::vector<int> Param;
2749 std::vector<double> OldCentral;
2750 std::vector<double> OldError;
2751 std::vector<bool> FlatPrior;
2754 for(
unsigned int k = 0; k < Names.size(); ++k)
2760 MACH3LOG_WARN(
"Couldn't find param {}. Can't reweight Prior", Names[k]);
2765 double Prior = 1.0, PriorError = 1.0;
2768 Param.push_back(ParamNo);
2769 OldCentral.push_back(Prior);
2770 OldError.push_back(PriorError);
2775 FlatPrior.push_back(
ParamFlat[ParType][ParamTemp]);
2777 std::vector<double> ParameterPos(Names.size());
2779 std::string InputFile =
MCMCFile+
".root";
2780 std::string OutputFilename =
MCMCFile +
"_reweighted.root";
2783 int ret = system((
"cp " + InputFile +
" " + OutputFilename).c_str());
2785 MACH3LOG_WARN(
"Error: system call to copy file failed with code {}", ret);
2787 TFile *OutputChain =
new TFile(OutputFilename.c_str(),
"UPDATE");
2789 TTree *post = OutputChain->Get<TTree>(
"posteriors");
2793 post->SetBranchStatus(
"*",
false);
2795 for (
unsigned int j = 0; j < Names.size(); ++j) {
2796 post->SetBranchStatus(
BranchNames[Param[j]].Data(),
true);
2797 post->SetBranchAddress(
BranchNames[Param[j]].Data(), &ParameterPos[j]);
2799 TBranch *bpt = post->Branch(
"Weight", &Weight,
"Weight/D");
2800 post->SetBranchStatus(
"Weight",
true);
2808 for (
unsigned int j = 0; j < Names.size(); ++j)
2810 double new_chi = (ParameterPos[j] - NewCentral[j])/NewError[j];
2811 double new_prior = std::exp(-0.5 * new_chi * new_chi);
2813 double old_chi = -1;
2814 double old_prior = -1;
2818 old_chi = (ParameterPos[j] - OldCentral[j])/OldError[j];
2819 old_prior = std::exp(-0.5 * old_chi * old_chi);
2821 Weight *= new_prior/old_prior;
2825 post->SetBranchStatus(
"*",
true);
2827 post->Write(
"posteriors", TObject::kOverwrite);
2828 OutputChain->Close();
2837 const std::vector<int>& NIntervals) {
2842 for(
unsigned int k = 0; k < Names.size(); ++k)
2848 MACH3LOG_WARN(
"Couldn't find param {}. Can't reweight Prior", Names[k]);
2852 const int IntervalsSize =
nSteps/NIntervals[k];
2854 int ret = system(fmt::format(
"rm {}.gif",Names[k]).c_str());
2856 MACH3LOG_WARN(
"Error: system call to delete {} failed with code {}", Names[k], ret);
2864 for(
int i = NIntervals[k]-1; i >= 0; --i)
2868 EvePlot->SetMinimum(0);
2869 EvePlot->GetYaxis()->SetTitle(
"PDF");
2870 EvePlot->GetYaxis()->SetNoExponent(
false);
2873 std::string CutPosterior1D =
"step > " + std::to_string(i*IntervalsSize+IntervalsSize);
2875 std::string TextTitle =
"Steps = 0 - "+std::to_string(Counter*IntervalsSize+IntervalsSize);
2879 EvePlot->SetLineWidth(2);
2880 EvePlot->SetLineColor(kBlue-1);
2881 EvePlot->SetTitle(Names[k].c_str());
2882 EvePlot->GetXaxis()->SetTitle(EvePlot->GetTitle());
2883 EvePlot->GetYaxis()->SetLabelOffset(1000);
2886 EvePlot->Scale(1. / EvePlot->Integral());
2887 EvePlot->Draw(
"HIST");
2889 TText text(0.3, 0.8, TextTitle.c_str());
2890 text.SetTextFont (43);
2891 text.SetTextSize (40);
2895 if(i == 0)
Posterior->Print((Names[k] +
".gif++20").c_str());
2896 else Posterior->Print((Names[k] +
".gif+20").c_str());
2942 MACH3LOG_ERROR(
"Even though it is used for MakeCovariance_MP and for DiagMCMC");
2943 MACH3LOG_ERROR(
"it has different structure in both for cache hits, sorry ");
2948 MACH3LOG_ERROR(
"please use SetnBatches to set other value fore example 20");
2954 for (
int j = 0; j <
nDraw; ++j) {
2956 for (
int i = 0; i <
nEntries; ++i) {
2965 for (
int i = 0; i <
nEntries; ++i) {
2969 for (
int j = 0; j <
nSamples; ++j) {
2972 for (
int j = 0; j <
nSysts; ++j) {
2981 for (
int i = 0; i <
nDraw; ++i) {
2989 Chain->SetBranchStatus(
"*",
false);
2992 const int countwidth =
nEntries/10;
2999 for (
int i = 0; i <
nBatches; ++i) {
3002 for (
int j = 0; j <
nDraw; ++j) {
3006 std::vector<double> ParStepBranch(
nDraw);
3007 std::vector<double> SampleValuesBranch(
nSamples);
3008 std::vector<double> SystValuesBranch(
nSysts);
3009 int StepNumberBranch = 0;
3010 double AccProbValuesBranch = 0;
3012 for (
int j = 0; j <
nDraw; ++j) {
3017 for (
int j = 0; j <
nSamples; ++j) {
3022 for (
int j = 0; j <
nSysts; ++j) {
3027 Chain->SetBranchStatus(
"step",
true);
3028 Chain->SetBranchAddress(
"step", &StepNumberBranch);
3030 Chain->SetBranchStatus(
"accProb",
true);
3031 Chain->SetBranchAddress(
"accProb", &AccProbValuesBranch);
3035 for (
int i = 0; i <
nEntries; ++i) {
3039 if (i % countwidth == 0)
3043 for (
int j = 0; j <
nDraw; ++j) {
3044 ParStep[j][i] = ParStepBranch[j];
3047 for (
int j = 0; j <
nSamples; ++j) {
3051 for (
int j = 0; j <
nSysts; ++j) {
3060 int BatchNumber = -1;
3062 for (
int j = 0; j <
nBatches; ++j) {
3063 if (i < (j+1)*BatchLength) {
3069 for (
int j = 0; j <
nDraw; ++j) {
3078 MACH3LOG_INFO(
"Took {:.2f}s to finish caching statistic for Diag MCMC with {} steps", clock.RealTime(),
nEntries);
3082 #pragma omp parallel for
3084 for (
int i = 0; i <
nDraw; ++i) {
3086 for (
int j = 0; j <
nBatches; ++j) {
3104 std::vector<TH1D*> TraceParamPlots(
nDraw);
3105 std::vector<TH1D*> TraceSamplePlots(
nSamples);
3106 std::vector<TH1D*> TraceSystsPlots(
nSysts);
3109 for (
int j = 0; j <
nDraw; ++j) {
3111 double Prior = 1.0, PriorError = 1.0;
3114 std::string HistName = Form(
"%s_%s_Trace", Title.Data(),
BranchNames[j].Data());
3115 TraceParamPlots[j] =
new TH1D(HistName.c_str(), HistName.c_str(),
nEntries, 0,
nEntries);
3116 TraceParamPlots[j]->GetXaxis()->SetTitle(
"Step");
3117 TraceParamPlots[j]->GetYaxis()->SetTitle(
"Parameter Variation");
3120 for (
int j = 0; j <
nSamples; ++j) {
3122 TraceSamplePlots[j] =
new TH1D(HistName.c_str(), HistName.c_str(),
nEntries, 0,
nEntries);
3123 TraceSamplePlots[j]->GetXaxis()->SetTitle(
"Step");
3124 TraceSamplePlots[j]->GetYaxis()->SetTitle(
"Sample -logL");
3127 for (
int j = 0; j <
nSysts; ++j) {
3129 TraceSystsPlots[j] =
new TH1D(HistName.c_str(), HistName.c_str(),
nEntries, 0,
nEntries);
3130 TraceSystsPlots[j]->GetXaxis()->SetTitle(
"Step");
3131 TraceSystsPlots[j]->GetYaxis()->SetTitle(
"Systematic -logL");
3139 #pragma omp parallel for
3141 for (
int i = 0; i <
nEntries; ++i) {
3143 for (
int j = 0; j <
nDraw; ++j) {
3144 TraceParamPlots[j]->SetBinContent(i,
ParStep[j][i]);
3146 for (
int j = 0; j <
nSamples; ++j) {
3147 TraceSamplePlots[j]->SetBinContent(i,
SampleValues[i][j]);
3149 for (
int j = 0; j <
nSysts; ++j) {
3150 TraceSystsPlots[j]->SetBinContent(i,
SystValues[i][j]);
3155 TDirectory *TraceDir =
OutputFile->mkdir(
"Trace");
3157 for (
int j = 0; j <
nDraw; ++j) {
3160 Fitter->SetLineColor(kRed);
3161 TraceParamPlots[j]->Fit(
"Fitter",
"Rq");
3162 TraceParamPlots[j]->Write();
3164 delete TraceParamPlots[j];
3167 TDirectory *LLDir =
OutputFile->mkdir(
"LogL");
3169 for (
int j = 0; j <
nSamples; ++j) {
3170 TraceSamplePlots[j]->Write();
3171 delete TraceSamplePlots[j];
3176 for (
int j = 0; j <
nSysts; ++j) {
3177 TraceSystsPlots[j]->Write();
3178 delete TraceSystsPlots[j];
3199 MACH3LOG_INFO(
"Making auto-correlations for nLags = {}", nLags);
3203 TDirectory* AutoCorrDir =
OutputFile->mkdir(
"Auto_corr");
3204 std::vector<TH1D*> LagKPlots(
nDraw);
3205 std::vector<std::vector<double>> LagL(
nDraw);
3208 std::vector<double> ACFFT(
nEntries, 0.0);
3209 std::vector<double> ParVals(
nEntries, 0.0);
3210 std::vector<double> ParValsFFTR(
nEntries, 0.0);
3211 std::vector<double> ParValsFFTI(
nEntries, 0.0);
3212 std::vector<double> ParValsFFTSquare(
nEntries, 0.0);
3213 std::vector<double> ParValsComplex(
nEntries, 0.0);
3217 TVirtualFFT* fftf = TVirtualFFT::FFT(1, &
nEntries,
"C2CFORWARD");
3218 TVirtualFFT* fftb = TVirtualFFT::FFT(1, &
nEntries,
"C2CBACKWARD");
3221 for (
int j = 0; j <
nDraw; ++j) {
3223 LagL[j].resize(nLags);
3224 for (
int i = 0; i <
nEntries; ++i) {
3226 ParValsComplex[i] = 0.;
3230 fftf->SetPointsComplex(ParVals.data(), ParValsComplex.data());
3232 fftf->GetPointsComplex(ParValsFFTR.data(), ParValsFFTI.data());
3235 for (
int i = 0; i <
nEntries; ++i) {
3236 ParValsFFTSquare[i] = ParValsFFTR[i]*ParValsFFTR[i] + ParValsFFTI[i]*ParValsFFTI[i];
3240 fftb->SetPointsComplex(ParValsFFTSquare.data(), ParValsComplex.data());
3242 fftb->GetPointsComplex(ACFFT.data(), ParValsComplex.data());
3245 double normAC = ACFFT[0];
3246 for (
int i = 0; i <
nEntries; ++i) {
3252 double Prior = 1.0, PriorError = 1.0;
3254 std::string HistName = Form(
"%s_%s_Lag", Title.Data(),
BranchNames[j].Data());
3257 LagKPlots[j] =
new TH1D(HistName.c_str(), HistName.c_str(), nLags, 0.0, nLags);
3258 LagKPlots[j]->GetXaxis()->SetTitle(
"Lag");
3259 LagKPlots[j]->GetYaxis()->SetTitle(
"Auto-correlation function");
3262 for (
int k = 0; k < nLags; ++k) {
3263 LagL[j][k] = ACFFT[k];
3264 LagKPlots[j]->SetBinContent(k, ACFFT[k]);
3269 LagKPlots[j]->Write();
3270 delete LagKPlots[j];
3276 AutoCorrDir->Close();
3282 MACH3LOG_INFO(
"Making auto-correlations took {:.2f}s", clock.RealTime());
3294 MACH3LOG_INFO(
"Making auto-correlations for nLags = {}", nLags);
3297 std::vector<std::vector<double>> DenomSum(
nDraw);
3298 std::vector<std::vector<double>> NumeratorSum(
nDraw);
3299 std::vector<std::vector<double>> LagL(
nDraw);
3300 for (
int j = 0; j <
nDraw; ++j) {
3301 DenomSum[j].resize(nLags);
3302 NumeratorSum[j].resize(nLags);
3303 LagL[j].resize(nLags);
3305 std::vector<TH1D*> LagKPlots(
nDraw);
3307 for (
int j = 0; j <
nDraw; ++j)
3310 for (
int k = 0; k < nLags; ++k) {
3311 NumeratorSum[j][k] = 0.0;
3312 DenomSum[j][k] = 0.0;
3318 double Prior = 1.0, PriorError = 1.0;
3321 std::string HistName = Form(
"%s_%s_Lag", Title.Data(),
BranchNames[j].Data());
3322 LagKPlots[j] =
new TH1D(HistName.c_str(), HistName.c_str(), nLags, 0.0, nLags);
3323 LagKPlots[j]->GetXaxis()->SetTitle(
"Lag");
3324 LagKPlots[j]->GetYaxis()->SetTitle(
"Auto-correlation function");
3332 #pragma omp parallel for collapse(2)
3334 for (
int j = 0; j <
nDraw; ++j) {
3335 for (
int k = 0; k < nLags; ++k) {
3337 for (
int i = 0; i <
nEntries; ++i) {
3343 const double Product = Diff*LagTerm;
3344 NumeratorSum[j][k] += Product;
3347 const double Denom = Diff*Diff;
3348 DenomSum[j][k] += Denom;
3355 PrepareGPU_AutoCorr(nLags);
3367 #pragma omp parallel for collapse(2)
3370 for (
int j = 0; j <
nDraw; ++j)
3372 for (
int k = 0; k < nLags; ++k)
3374 const int temp_index = j*nLags+k;
3375 NumeratorSum[j][k] = NumeratorSum_cpu[temp_index];
3376 DenomSum[j][k] = DenomSum_cpu[temp_index];
3380 delete[] NumeratorSum_cpu;
3381 delete[] DenomSum_cpu;
3382 delete[] ParStep_cpu;
3383 delete[] ParamSums_cpu;
3396 TDirectory *AutoCorrDir =
OutputFile->mkdir(
"Auto_corr");
3398 for (
int j = 0; j <
nDraw; ++j) {
3399 for (
int k = 0; k < nLags; ++k) {
3400 LagL[j][k] = NumeratorSum[j][k]/DenomSum[j][k];
3401 LagKPlots[j]->SetBinContent(k, NumeratorSum[j][k]/DenomSum[j][k]);
3404 LagKPlots[j]->Write();
3405 delete LagKPlots[j];
3413 AutoCorrDir->Close();
3419 MACH3LOG_INFO(
"Making auto-correlations took {:.2f}s", clock.RealTime());
3425void MCMCProcessor::PrepareGPU_AutoCorr(
const int nLags) {
3429 NumeratorSum_cpu =
new float[
nDraw*nLags];
3430 DenomSum_cpu =
new float[
nDraw*nLags];
3431 ParamSums_cpu =
new float[
nDraw];
3435 #pragma omp parallel
3440 #pragma omp for nowait
3442 for (
int i = 0; i <
nDraw; ++i)
3449 #pragma omp for collapse(2) nowait
3451 for (
int j = 0; j <
nDraw; ++j)
3453 for (
int k = 0; k < nLags; ++k)
3455 const int temp = j*nLags+k;
3456 NumeratorSum_cpu[temp] = 0.0;
3457 DenomSum_cpu[temp] = 0.0;
3462 #pragma omp for collapse(2)
3464 for (
int j = 0; j <
nDraw; ++j)
3469 ParStep_cpu[temp] =
ParStep[j][i];
3508 if(LagL.size() == 0)
3515 TVectorD* SamplingEfficiency =
new TVectorD(
nDraw);
3516 std::vector<double> TempDenominator(
nDraw);
3518 constexpr int Nhists = 5;
3519 constexpr double Thresholds[Nhists + 1] = {1, 0.02, 0.005, 0.001, 0.0001, 0.0};
3520 constexpr Color_t ESSColours[Nhists] = {kGreen, kGreen + 2, kYellow, kOrange, kRed};
3523 std::vector<std::unique_ptr<TH1D>> EffectiveSampleSizeHist(Nhists);
3524 for(
int i = 0; i < Nhists; ++i)
3526 EffectiveSampleSizeHist[i] =
3527 std::make_unique<TH1D>(Form(
"EffectiveSampleSizeHist_%i", i), Form(
"EffectiveSampleSizeHist_%i", i),
nDraw, 0,
nDraw);
3528 EffectiveSampleSizeHist[i]->GetYaxis()->SetTitle(
"N_{eff}/N");
3529 EffectiveSampleSizeHist[i]->SetFillColor(ESSColours[i]);
3530 EffectiveSampleSizeHist[i]->SetLineColor(ESSColours[i]);
3531 EffectiveSampleSizeHist[i]->Sumw2();
3532 for (
int j = 0; j <
nDraw; ++j)
3535 double Prior = 1.0, PriorError = 1.0;
3537 EffectiveSampleSizeHist[i]->GetXaxis()->SetBinLabel(j+1, Title.Data());
3542 #pragma omp parallel for
3545 for (
int j = 0; j <
nDraw; ++j)
3547 (*EffectiveSampleSize)(j) =
_UNDEF_;
3548 (*SamplingEfficiency)(j) =
_UNDEF_;
3549 TempDenominator[j] = 0.;
3551 for (
int k = 0; k < nLags; ++k)
3553 TempDenominator[j] += LagL[j][k];
3555 TempDenominator[j] = 1+2*TempDenominator[j];
3556 (*EffectiveSampleSize)(j) =
double(
nEntries)/TempDenominator[j];
3558 (*SamplingEfficiency)(j) = 100 * 1/TempDenominator[j];
3560 for(
int i = 0; i < Nhists; ++i)
3562 EffectiveSampleSizeHist[i]->SetBinContent(j+1, 0);
3563 EffectiveSampleSizeHist[i]->SetBinError(j+1, 0);
3566 if(Thresholds[i] >= TempEntry && TempEntry > Thresholds[i+1])
3569 EffectiveSampleSizeHist[i]->SetBinContent(j+1, TempEntry);
3578 SamplingEfficiency->Write(
"SamplingEfficiency");
3580 EffectiveSampleSizeHist[0]->SetTitle(
"Effective Sample Size");
3581 EffectiveSampleSizeHist[0]->Draw();
3582 for(
int i = 1; i < Nhists; ++i)
3584 EffectiveSampleSizeHist[i]->Draw(
"SAME");
3587 auto leg = std::make_unique<TLegend>(0.2, 0.7, 0.6, 0.95);
3589 for(
int i = 0; i < Nhists; ++i)
3591 leg->AddEntry(EffectiveSampleSizeHist[i].get(), Form(
"%.4f >= N_{eff}/N > %.4f", Thresholds[i], Thresholds[i+1]),
"f");
3592 } leg->Draw(
"SAME");
3594 Posterior->Write(
"EffectiveSampleSizeCanvas");
3598 delete SamplingEfficiency;
3608 std::vector<TH1D*> BatchedParamPlots(
nDraw);
3609 for (
int j = 0; j <
nDraw; ++j) {
3611 double Prior = 1.0, PriorError = 1.0;
3615 std::string HistName = Form(
"%s_%s_batch", Title.Data(),
BranchNames[j].Data());
3616 BatchedParamPlots[j] =
new TH1D(HistName.c_str(), HistName.c_str(),
nBatches, 0,
nBatches);
3620 #pragma omp parallel for
3622 for (
int j = 0; j <
nDraw; ++j) {
3623 for (
int i = 0; i <
nBatches; ++i) {
3627 std::stringstream ss;
3628 ss << BatchRangeLow <<
" - " << BatchRangeHigh;
3629 BatchedParamPlots[j]->GetXaxis()->SetBinLabel(i+1, ss.str().c_str());
3633 TDirectory *BatchDir =
OutputFile->mkdir(
"Batched_means");
3635 for (
int j = 0; j <
nDraw; ++j) {
3636 TF1 *Fitter =
new TF1(
"Fitter",
"[0]", 0,
nBatches);
3637 Fitter->SetLineColor(kRed);
3638 BatchedParamPlots[j]->Fit(
"Fitter",
"Rq");
3639 BatchedParamPlots[j]->Write();
3641 delete BatchedParamPlots[j];
3648 for (
int i = 0; i <
nBatches; ++i) {
3665 MACH3LOG_ERROR(
"BatchedAverages haven't been initialises or have been deleted something is wrong");
3671 TVectorD* BatchedVariance =
new TVectorD(
nDraw);
3673 TVectorD* C_Test_Statistics =
new TVectorD(
nDraw);
3675 std::vector<double> OverallBatchMean(
nDraw);
3676 std::vector<double> C_Rho_Nominator(
nDraw);
3677 std::vector<double> C_Rho_Denominator(
nDraw);
3678 std::vector<double> C_Nominator(
nDraw);
3679 std::vector<double> C_Denominator(
nDraw);
3690 for (
int j = 0; j <
nDraw; ++j)
3692 OverallBatchMean[j] = 0.0;
3693 C_Rho_Nominator[j] = 0.0;
3694 C_Rho_Denominator[j] = 0.0;
3695 C_Nominator[j] = 0.0;
3696 C_Denominator[j] = 0.0;
3698 (*BatchedVariance)(j) = 0.0;
3699 (*C_Test_Statistics)(j) = 0.0;
3708 #pragma omp for nowait
3711 for (
int j = 0; j <
nDraw; ++j)
3717 (*BatchedVariance)(j) = (BatchLength/(
nBatches-1))* (*BatchedVariance)(j);
3722 #pragma omp for nowait
3724 for (
int j = 0; j <
nDraw; ++j)
3732 C_Denominator[j] = 2*C_Denominator[j];
3739 for (
int j = 0; j <
nDraw; ++j)
3741 for (
int i = 0; i <
nBatches-1; ++i)
3756 for (
int j = 0; j <
nDraw; ++j)
3758 (*C_Test_Statistics)(j) = std::sqrt((
nBatches*
nBatches - 1)/(
nBatches-2)) * ( C_Rho_Nominator[j]/C_Rho_Denominator[j] + C_Nominator[j]/ C_Denominator[j]);
3766 BatchedVariance->Write(
"BatchedMeansVariance");
3767 C_Test_Statistics->Write(
"C_Test_Statistics");
3770 delete BatchedVariance;
3771 delete C_Test_Statistics;
3782 const double TopMargin =
Posterior->GetTopMargin();
3783 const int OptTitle = gStyle->GetOptTitle();
3786 gStyle->SetOptTitle(1);
3791 const int N_Coeffs = std::min(10000,
nEntries);
3792 const int start = -(N_Coeffs/2-1);
3793 const int end = N_Coeffs/2-1;
3794 const int v_size = end - start;
3800 std::vector<std::vector<float>> k_j(nPrams, std::vector<float>(v_size, 0.0));
3801 std::vector<std::vector<float>> P_j(nPrams, std::vector<float>(v_size, 0.0));
3804 if (_N % 2 != 0) _N -= 1;
3807 const double two_pi_over_N = 2 * TMath::Pi() /
static_cast<double>(_N);
3811 #pragma omp parallel for collapse(2)
3814 for (
int j = 0; j < nPrams; ++j)
3816 for (
int jj = start; jj < end; ++jj)
3818 std::complex<double> a_j = 0.0;
3819 for (
int n = 0; n < _N; ++n)
3822 std::complex<double> exp_temp(0, two_pi_over_N * jj * n);
3823 a_j +=
ParStep[j][n] * std::exp(exp_temp);
3825 a_j /= std::sqrt(
float(_N));
3826 const int _c = jj - start;
3828 k_j[j][_c] = two_pi_over_N * jj;
3830 P_j[j][_c] = std::norm(a_j);
3834 TDirectory *PowerDir =
OutputFile->mkdir(
"PowerSpectrum");
3837 TVectorD* PowerSpectrumStepSize =
new TVectorD(nPrams);
3838 for (
int j = 0; j < nPrams; ++j)
3840 auto plot = std::make_unique<TGraph>(v_size, k_j[j].data(), P_j[j].data());
3843 double Prior = 1.0, PriorError = 1.0;
3846 std::string name = Form(
"Power Spectrum of %s;k;P(k)", Title.Data());
3848 plot->SetTitle(name.c_str());
3849 name = Form(
"%s_power_spectrum", Title.Data());
3850 plot->SetName(name.c_str());
3851 plot->SetMarkerStyle(7);
3854 TF1 *func =
new TF1(
"power_template",
"[0]*( ([1] / x)^[2] / (([1] / x)^[2] +1) )", 0.0, 1.0);
3856 func->SetParameter(0, 10.0);
3858 func->SetParameter(1, 0.1);
3860 func->SetParameter(2, 2.0);
3863 func->SetParLimits(0, 0.0, 100.0);
3864 func->SetParLimits(1, 0.001, 1.0);
3865 func->SetParLimits(2, 0.0, 5.0);
3867 plot->Fit(
"power_template",
"Rq");
3872 plot->Write(plot->GetName());
3878 (*PowerSpectrumStepSize)(j) = std::sqrt(func->GetParameter(0)/float(v_size*0.5));
3882 PowerSpectrumStepSize->Write(
"PowerSpectrumStepSize");
3883 delete PowerSpectrumStepSize;
3888 MACH3LOG_INFO(
"Making Power Spectrum took {:.2f}s", clock.RealTime());
3891 gStyle->SetOptTitle(OptTitle);
3902 std::vector<double> MeanUp(
nDraw, 0.0);
3903 std::vector<double> SpectralVarianceUp(
nDraw, 0.0);
3904 std::vector<int> DenomCounterUp(
nDraw, 0);
3905 const double Threshold = 0.5 *
nSteps;
3908 constexpr double LowerThreshold = 0;
3909 constexpr double UpperThreshold = 1.0;
3911 constexpr int NChecks = 100;
3912 constexpr double Division = (UpperThreshold - LowerThreshold)/NChecks;
3914 std::vector<std::unique_ptr<TH1D>> GewekePlots(
nDraw);
3915 for (
int j = 0; j <
nDraw; ++j)
3918 double Prior = 1.0, PriorError = 1.0;
3920 std::string HistName = Form(
"%s_%s_Geweke", Title.Data(),
BranchNames[j].Data());
3921 GewekePlots[j] = std::make_unique<TH1D>(HistName.c_str(), HistName.c_str(), NChecks, 0.0, 100 * UpperThreshold);
3922 GewekePlots[j]->GetXaxis()->SetTitle(
"Burn-In (%)");
3923 GewekePlots[j]->GetYaxis()->SetTitle(
"Geweke T score");
3935 for (
int j = 0; j <
nDraw; ++j)
3942 DenomCounterUp[j]++;
3945 MeanUp[j] = MeanUp[j]/DenomCounterUp[j];
3950 #pragma omp for collapse(2)
3952 for (
int j = 0; j <
nDraw; ++j)
3958 SpectralVarianceUp[j] += (
ParStep[j][i] - MeanUp[j])*(
ParStep[j][i] - MeanUp[j]);
3967 for (
int k = 1; k < NChecks+1; ++k)
3970 std::vector<double> MeanDown(
nDraw, 0.0);
3971 std::vector<double> SpectralVarianceDown(
nDraw, 0.0);
3972 std::vector<int> DenomCounterDown(
nDraw, 0);
3974 const int ThresholsCheck = Division*k*
nSteps;
3976 for (
int j = 0; j <
nDraw; ++j)
3983 DenomCounterDown[j]++;
3986 MeanDown[j] = MeanDown[j]/DenomCounterDown[j];
3989 for (
int j = 0; j <
nDraw; ++j)
3995 SpectralVarianceDown[j] += (
ParStep[j][i] - MeanDown[j])*(
ParStep[j][i] - MeanDown[j]);
4000 for (
int j = 0; j <
nDraw; ++j)
4002 double T_score = std::fabs((MeanDown[j] - MeanUp[j])/std::sqrt(SpectralVarianceDown[j]/DenomCounterDown[j] + SpectralVarianceUp[j]/DenomCounterUp[j]));
4003 GewekePlots[j]->SetBinContent(k, T_score);
4012 TDirectory *GewekeDir =
OutputFile->mkdir(
"Geweke");
4013 for (
int j = 0; j <
nDraw; ++j)
4016 GewekePlots[j]->Write();
4018 for (
int i = 0; i <
nDraw; ++i) {
4037 auto AcceptanceProbPlot = std::make_unique<TH1D>(
"AcceptanceProbability",
"Acceptance Probability",
nEntries, 0,
nEntries);
4038 AcceptanceProbPlot->GetXaxis()->SetTitle(
"Step");
4039 AcceptanceProbPlot->GetYaxis()->SetTitle(
"Acceptance Probability");
4041 auto BatchedAcceptanceProblot = std::make_unique<TH1D>(
"AcceptanceProbability_Batch",
"AcceptanceProbability_Batch",
nBatches, 0,
nBatches);
4042 BatchedAcceptanceProblot->GetYaxis()->SetTitle(
"Acceptance Probability");
4044 for (
int i = 0; i <
nBatches; ++i) {
4048 std::stringstream ss;
4049 ss << BatchRangeLow <<
" - " << BatchRangeHigh;
4050 BatchedAcceptanceProblot->GetXaxis()->SetBinLabel(i+1, ss.str().c_str());
4054 #pragma omp parallel for
4056 for (
int i = 0; i <
nEntries; ++i) {
4061 TDirectory *probDir =
OutputFile->mkdir(
"AccProb");
4064 AcceptanceProbPlot->Write();
4065 BatchedAcceptanceProblot->Write();
4078 if (CredibleIntervals.size() != CredibleIntervalsColours.size()) {
4079 MACH3LOG_ERROR(
"size of CredibleIntervals is not equal to size of CredibleIntervalsColours");
4082 if (CredibleIntervals.size() > 1) {
4083 for (
unsigned int i = 1; i < CredibleIntervals.size(); i++) {
4084 if (CredibleIntervals[i] > CredibleIntervals[i - 1]) {
4086 MACH3LOG_ERROR(
"{:.2f} {:.2f}", CredibleIntervals[i], CredibleIntervals[i - 1]);
4096 const std::vector<Style_t>& CredibleRegionStyle,
4097 const std::vector<Color_t>& CredibleRegionColor) {
4099 if ((CredibleRegions.size() != CredibleRegionStyle.size()) || (CredibleRegionStyle.size() != CredibleRegionColor.size())) {
4100 MACH3LOG_ERROR(
"size of CredibleRegions is not equal to size of CredibleRegionStyle or CredibleRegionColor");
4103 for (
unsigned int i = 1; i < CredibleRegions.size(); i++) {
4104 if (CredibleRegions[i] > CredibleRegions[i - 1]) {
4106 MACH3LOG_ERROR(
"{:.2f} {:.2f}", CredibleRegions[i], CredibleRegions[i - 1]);
4117 auto caseInsensitiveCompare = [](
const std::string& a,
const std::string& b) {
4118 return std::equal(a.begin(), a.end(), b.begin(), b.end(),
4119 [](
char c1,
char c2) { return std::tolower(c1) == std::tolower(c2); });
4123 if (caseInsensitiveCompare(groupName, name)) {
4134 std::unordered_map<std::string, int> paramCounts;
4135 std::vector<std::string> orderedKeys;
4138 if (paramCounts[param] == 0) {
4139 orderedKeys.push_back(param);
4141 paramCounts[param]++;
4144 MACH3LOG_INFO(
"************************************************");
4149 for (
const std::string& key : orderedKeys) {
4154 MACH3LOG_INFO(
"************************************************");
4160 return std::vector<double>{Canv->GetTopMargin(), Canv->GetBottomMargin(),
4161 Canv->GetLeftMargin(), Canv->GetRightMargin()};
4171 if (margins.size() != 4) {
4175 Canv->SetTopMargin(margins[0]);
4176 Canv->SetBottomMargin(margins[1]);
4177 Canv->SetLeftMargin(margins[2]);
4178 Canv->SetRightMargin(margins[3]);
4184 Line->SetLineColor(Colour);
4185 Line->SetLineWidth(Width);
4186 Line->SetLineStyle(Style);
4192 Legend->SetTextSize(
size);
4193 Legend->SetLineColor(0);
4194 Legend->SetLineStyle(0);
4195 Legend->SetFillColor(0);
4196 Legend->SetFillStyle(0);
4197 Legend->SetBorderSize(0);
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
int CrossSectionParameters
int FDParametersStartingPos
int NDParametersStartingPos
void RemoveFitter(TH1D *hist, const std::string &name)
KS: Remove fitted TF1 from hist to make comparison easier.
ParameterEnum
KS: Enum for different covariance classes.
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
double * EffectiveSampleSize
double GetSubOptimality(const std::vector< double > &EigenValues, const int TotalTarameters)
Based on .
void GetGaussian(TH1D *&hist, TF1 *gauss, double &Mean, double &Error)
CW: Fit Gaussian to posterior.
void GetCredibleIntervalSig(const std::unique_ptr< TH1D > &hist, std::unique_ptr< TH1D > &hpost_copy, const bool CredibleInSigmas, const double coverage)
KS: Get 1D histogram within credible interval, hpost_copy has to have the same binning,...
std::string GetJeffreysScale(const double BayesFactor)
KS: Following H. Jeffreys .
void GetHPD(TH1D *const hist, double &Mean, double &Error, double &Error_p, double &Error_m, const double coverage)
Get Highest Posterior Density (HPD)
void GetCredibleRegionSig(std::unique_ptr< TH2D > &hist2D, const bool CredibleInSigmas, const double coverage)
KS: Set 2D contour within some coverage.
void GetArithmetic(TH1D *const hist, double &Mean, double &Error)
CW: Get Arithmetic mean from posterior.
std::string GetDunneKaboth(const double BayesFactor)
KS: Based on Table 1 in https://www.t2k.org/docs/technotes/435.
YAML::Node TMacroToYAML(const TMacro ¯o)
KS: Convert a ROOT TMacro object to a YAML node.
void ScanParameterOrder()
Scan order of params from a different groups.
int nBatches
Number of batches for Batched Mean.
void GewekeDiagnostic()
Geweke Diagnostic based on the methods described by Fang (2014) and Karlsbakk (2011)....
TMatrixDSym * Correlation
Posterior Correlation Matrix.
void MakeViolin()
Make and Draw Violin.
void GetNthParameter(const int param, double &Prior, double &PriorError, TString &Title) const
Get properties of parameter by passing it number.
int * StepNumber
Step number for step, important if chains were merged.
double ** ParStep
Array holding values for all parameters.
void PrintInfo() const
Print info like how many params have been loaded etc.
void MakeCredibleIntervals(const std::vector< double > &CredibleIntervals={0.99, 0.90, 0.68 }, const std::vector< Color_t > &CredibleIntervalsColours={kCyan+4, kCyan-2, kCyan-10}, const bool CredibleInSigmas=false)
Make and Draw Credible intervals.
void ReadModelFile()
Read the xsec file and get the input central values and errors.
std::vector< double > GetMargins(const std::unique_ptr< TCanvas > &Canv) const
Get TCanvas margins, to be able to reset them if particular function need different margins.
void CalculateESS(const int nLags, const std::vector< std::vector< double > > &LagL)
KS: calc Effective Sample Size.
void GetBayesFactor(const std::vector< std::string > &ParName, const std::vector< std::vector< double > > &Model1Bounds, const std::vector< std::vector< double > > &Model2Bounds, const std::vector< std::vector< std::string > > &ModelNames)
Calculate Bayes factor for vector of params, and model boundaries.
std::unique_ptr< TF1 > Gauss
Gaussian fitter.
void Initialise()
Scan chain, what parameters we have and load information from covariance matrices.
int BurnInCut
Value of burn in cut.
MCMCProcessor(const std::string &InputFile)
Constructs an MCMCProcessor object with the specified input file and options.
double Post2DPlotThreshold
KS: Set Threshold when to plot 2D posterior as by default we get a LOT of plots.
void AcceptanceProbabilities()
Acceptance Probability.
double ** SampleValues
Holds the sample values.
void BatchedAnalysis()
Get the batched means variance estimation and variable indicating if number of batches is sensible .
void AutoCorrelation()
KS: Calculate autocorrelations supports both OpenMP and CUDA :)
TVectorD * Means_HPD
Vector with mean values using Highest Posterior Density.
void ResetHistograms()
Reset 2D posteriors, in case we would like to calculate in again with different BurnInCut.
std::vector< TString > SampleName_v
Vector of each systematic.
std::vector< std::vector< double > > ParamCentral
Parameters central values which we are going to analyse.
std::vector< std::vector< double > > ParamErrors
Uncertainty on a single parameter.
void MakeTrianglePlot(const std::vector< std::string > &ParNames, const std::vector< double > &CredibleIntervals={0.99, 0.90, 0.68 }, const std::vector< Color_t > &CredibleIntervalsColours={kCyan+4, kCyan-2, kCyan-10}, const std::vector< double > &CredibleRegions={0.99, 0.90, 0.68}, const std::vector< Style_t > &CredibleRegionStyle={kDashed, kSolid, kDotted}, const std::vector< Color_t > &CredibleRegionColor={kGreen-3, kGreen-10, kGreen}, const bool CredibleInSigmas=false)
Make fancy triangle plot for selected parameters.
std::string OutputName
Name of output files.
std::unique_ptr< TH2D > hviolin_prior
Holds prior violin plot for all dials,.
int nSamples
Number of sample PDF objects.
std::vector< int > nParam
Number of parameters per type.
int GetGroup(const std::string &name) const
Number of params from a given group, for example flux.
double DrawRange
Drawrange for SetMaximum.
std::vector< std::vector< bool > > ParamFlat
Whether Param has flat prior or not.
std::vector< YAML::Node > CovConfig
Covariance matrix config.
std::vector< std::vector< double > > ParamNom
double ** SystValues
Holds the systs values.
virtual ~MCMCProcessor()
Destroys the MCMCProcessor object.
TVectorD * Errors
Vector with errors values using RMS.
double * AccProbBatchedAverages
Holds all accProb in batches.
bool useFFTAutoCorrelation
MJR: Use FFT-based autocorrelation algorithm (save time & resources)?
void MakeCredibleRegions(const std::vector< double > &CredibleRegions={0.99, 0.90, 0.68}, const std::vector< Style_t > &CredibleRegionStyle={kDashed, kSolid, kDotted}, const std::vector< Color_t > &CredibleRegionColor={kGreen-3, kGreen-10, kGreen}, const bool CredibleInSigmas=false, const bool Draw2DPosterior=true, const bool DrawBestFit=true)
Make and Draw Credible Regions.
std::string StepCut
BurnIn Cuts.
void GetPostfit_Ind(TVectorD *&Central, TVectorD *&Errors, TVectorD *&Peaks, ParameterEnum kParam)
Or the individual post-fits.
int GetParamIndexFromName(const std::string &Name)
Get parameter number based on name.
void DrawCorrelations1D()
Draw 1D correlations which might be more helpful than looking at huge 2D Corr matrix.
void GetPostfit(TVectorD *&Central, TVectorD *&Errors, TVectorD *&Central_Gauss, TVectorD *&Errors_Gauss, TVectorD *&Peaks)
Get the post-fit results (arithmetic and Gaussian)
TVectorD * Means_Gauss
Vector with mean values using Gaussian fit.
int AutoCorrLag
LagL used in AutoCorrelation.
std::unique_ptr< TCanvas > Posterior
Fancy canvas used for our beautiful plots.
TFile * OutputFile
The output file.
void ReadNDFile()
Read the ND cov file and get the input central values and errors.
bool ApplySmoothing
Apply smoothing for 2D histos using root algorithm.
TChain * Chain
Main chain storing all steps etc.
std::string MCMCFile
Name of MCMC file.
void SetLegendStyle(TLegend *Legend, const double size) const
Configures the style of a TLegend object.
std::vector< std::string > ExcludedNames
std::unique_ptr< TH1D > MakePrefit()
Prepare prefit histogram for parameter overlay plot.
std::vector< TH1D * > hpost
Holds 1D Posterior Distributions.
TVectorD * Errors_HPD_Negative
Vector with negative error (left hand side) values using Highest Posterior Density.
std::vector< std::vector< std::string > > CovPos
Covariance matrix name position.
double * ParamSums
Total parameter sum for each param.
void DiagMCMC()
KS: Perform MCMC diagnostic including Autocorrelation, Trace etc.
int UpperCut
KS: Used only for SubOptimality.
std::string Posterior1DCut
Cut used when making 1D Posterior distribution.
void MakePostfit()
Make 1D projection for each parameter and prepare structure.
double * AccProbValues
Holds all accProb.
void FindInputFilesLegacy()
void DrawCovariance()
Draw the post-fit covariances.
void SetMargins(std::unique_ptr< TCanvas > &Canv, const std::vector< double > &margins)
Set TCanvas margins to specified values.
void ParamTraces()
CW: Draw trace plots of the parameters i.e. parameter vs step.
void PrepareDiagMCMC()
CW: Prepare branches etc. for DiagMCMC.
std::vector< bool > IamVaried
Is the ith parameter varied.
std::unique_ptr< TH2D > hviolin
Holds violin plot for all dials.
int nDraw
Number of all parameters used in the analysis.
std::string OutputSuffix
Output file suffix useful when running over same file with different settings.
void SetupOutput()
Prepare all objects used for output.
void MakeOutputFile()
prepare output root file and canvas to which we will save EVERYTHING
bool plotBinValue
If true it will print value on each bin of covariance matrix.
TVectorD * Errors_Gauss
Vector with error values using Gaussian fit.
std::vector< ParameterEnum > ParamType
Make an enum for which class this parameter belongs to so we don't have to keep string comparing.
std::vector< std::string > NDSamplesNames
virtual void LoadAdditionalInfo()
allow loading additional info for example used for oscillation parameters
TVectorD * Central_Value
Vector with central value for each parameter.
std::vector< std::string > ExcludedTypes
int nSteps
KS: For merged chains number of entries will be different from nSteps.
void CheckCredibleRegionsOrder(const std::vector< double > &CredibleRegions, const std::vector< Style_t > &CredibleRegionStyle, const std::vector< Color_t > &CredibleRegionColor)
Checks the order and size consistency of the CredibleRegions, CredibleRegionStyle,...
std::vector< int > NDSamplesBins
void MakeCovariance_MP(const bool Mute=false)
Calculate covariance by making 2D projection of each combination of parameters using multithreading.
double ** BatchedAverages
Values of batched average for every param and batch.
void DrawPostfit()
Draw the post-fit comparisons.
TString CanvasName
Name of canvas which help to save to the sample pdf.
std::vector< std::string > ParameterGroup
TVectorD * Errors_HPD
Vector with error values using Highest Posterior Density.
void AutoCorrelation_FFT()
MJR: Autocorrelation function using FFT algorithm for extra speed.
void SetTLineStyle(TLine *Line, const Color_t Colour, const Width_t Width, const ELineStyle Style) const
Configures a TLine object with the specified style parameters.
void ReadInputCovLegacy()
void GetPolarPlot(const std::vector< std::string > &ParNames)
Make funny polar plot.
std::vector< std::vector< TH2D * > > hpost2D
Holds 2D Posterior Distributions.
void ParameterEvolution(const std::vector< std::string > &Names, const std::vector< int > &NIntervals)
Make .gif of parameter evolution.
void GetCovariance(TMatrixDSym *&Cov, TMatrixDSym *&Corr)
Get the post-fit covariances and correlations.
TVectorD * Means
Vector with mean values using Arithmetic Mean.
std::vector< TString > SystName_v
Vector of each sample PDF object.
void CacheSteps()
KS:By caching each step we use multithreading.
std::vector< TString > BranchNames
void GetSavageDickey(const std::vector< std::string > &ParName, const std::vector< double > &EvaluationPoint, const std::vector< std::vector< double > > &Bounds)
Calculate Bayes factor for point like hypothesis using SavageDickey.
bool PlotFlatPrior
Whether we plot flat prior or not, we usually provide error even for flat prior params.
bool FancyPlotNames
Whether we want fancy plot names or not.
void ReweightPrior(const std::vector< std::string > &Names, const std::vector< double > &NewCentral, const std::vector< double > &NewError)
Reweight Prior by giving new central value and new error.
void SetStepCut(const std::string &Cuts)
Set the step cutting by string.
bool printToPDF
Will plot all plot to PDF not only to root file.
void CheckCredibleIntervalsOrder(const std::vector< double > &CredibleIntervals, const std::vector< Color_t > &CredibleIntervalsColours)
Checks the order and size consistency of the CredibleIntervals and CredibleIntervalsColours vectors.
std::vector< std::vector< TString > > ParamNames
Name of parameters which we are going to analyse.
bool doDiagMCMC
Doing MCMC Diagnostic.
int nSysts
Number of covariance objects.
void ReadFDFile()
Read the FD cov file and get the input central values and errors.
void FindInputFiles()
Read the output MCMC file and find what inputs were used.
bool CacheMCMC
MCMC Chain has been cached.
std::vector< int > ParamTypeStartPos
bool MadePostfit
Sanity check if Postfit is already done to not make several times.
void PowerSpectrumAnalysis()
RC: Perform spectral analysis of MCMC .
void ScanInput()
Scan Input etc.
void BatchedMeans()
CW: Batched means, literally read from an array and chuck into TH1D.
int nEntries
KS: For merged chains number of entries will be different from nSteps.
int nBranches
Number of branches in a TTree.
TVectorD * Errors_HPD_Positive
Vector with positive error (right hand side) values using Highest Posterior Density.
TMatrixDSym * Covariance
Posterior Covariance Matrix.
void MakeSubOptimality(const int NIntervals=10)
Make and Draw SubOptimality .
bool plotRelativeToPrior
Whether we plot relative to prior or nominal, in most cases is prior.
void MakeCovariance()
Calculate covariance by making 2D projection of each combination of parameters.
void ReadInputCov()
CW: Read the input Covariance matrix entries. Get stuff like parameter input errors,...
Custom exception class for MaCh3 errors.
__host__ void InitGPU_AutoCorr(float **ParStep_gpu, float **NumeratorSum_gpu, float **ParamSums_gpu, float **DenomSum_gpu, int n_Entries, int n_Pars, const int n_Lags)
KS: Initialiser, here we allocate memory for variables and copy constants.
__host__ void CopyToGPU_AutoCorr(float *ParStep_cpu, float *NumeratorSum_cpu, float *ParamSums_cpu, float *DenomSum_cpu, float *ParStep_gpu, float *NumeratorSum_gpu, float *ParamSums_gpu, float *DenomSum_gpu)
KS: Copy necessary variables from CPU to GPU.
__host__ void RunGPU_AutoCorr(float *ParStep_gpu, float *ParamSums_gpu, float *NumeratorSum_gpu, float *DenomSum_gpu, float *NumeratorSum_cpu, float *DenomSum_cpu)
KS: This call the main kernel responsible for calculating LagL and later copy results back to CPU.
__host__ void CleanupGPU_AutoCorr(float *ParStep_gpu, float *NumeratorSum_gpu, float *ParamSums_gpu, float *DenomSum_gpu)
KS: free memory on gpu.
TMacro * GetConfigMacroFromChain(TDirectory *CovarianceFolder)
KS: We store configuration macros inside the chain. In the past, multiple configs were stored,...
void PrintProgressBar(const Long64_t Done, const Long64_t All)
KS: Simply print progress bar.
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
void EstimateDataTransferRate(TChain *chain, const Long64_t entry)
KS: Check what CPU you are using.