778 #pragma GCC diagnostic push
779 #pragma GCC diagnostic ignored "-Wfloat-conversion"
781 std::string NameTemp =
"";
785 for (
int i = 0; i <
Nchains; i++)
789 while (temp.find(
".root") != std::string::npos) {
790 temp = temp.substr(0, temp.find(
".root"));
793 const auto slash = temp.find_last_of(
"/\\");
794 if (slash != std::string::npos) {
795 temp = temp.substr(slash + 1);
798 NameTemp = NameTemp + temp +
"_";
802 NameTemp = std::to_string(
Nchains) +
"Chains" +
"_";
804 NameTemp +=
"diag.root";
806 TFile *DiagFile =
M3::Open(NameTemp,
"recreate", __FILE__, __LINE__);
809 TH1D *StandardDeviationGlobalPlot =
new TH1D(
"StandardDeviationGlobalPlot",
"StandardDeviationGlobalPlot",
nDraw, 0,
nDraw);
810 TH1D *BetweenChainVariancePlot =
new TH1D(
"BetweenChainVariancePlot",
"BetweenChainVariancePlot",
nDraw, 0,
nDraw);
811 TH1D *MarginalPosteriorVariancePlot =
new TH1D(
"MarginalPosteriorVariancePlot",
"MarginalPosteriorVariancePlot",
nDraw, 0,
nDraw);
812 TH1D *RhatPlot =
new TH1D(
"RhatPlot",
"RhatPlot", 200, 0, 2);
813 TH1D *EffectiveSampleSizePlot =
new TH1D(
"EffectiveSampleSizePlot",
"EffectiveSampleSizePlot", 400, 0, 10000);
815 TH1D *RhatLogPlot =
new TH1D(
"RhatLogPlot",
"RhatLogPlot", 200, 0, 2);
817 TH1D *StandardDeviationGlobalFoldedPlot =
nullptr;
818 TH1D *BetweenChainVarianceFoldedPlot =
nullptr;
819 TH1D *MarginalPosteriorVarianceFoldedPlot =
nullptr;
820 TH1D *RhatFoldedPlot =
nullptr;
821 TH1D *EffectiveSampleSizeFoldedPlot =
nullptr;
822 TH1D *RhatFoldedLogPlot =
nullptr;
826 StandardDeviationGlobalFoldedPlot =
new TH1D(
"StandardDeviationGlobalFoldedPlot",
"StandardDeviationGlobalFoldedPlot",
nDraw, 0,
nDraw);
827 BetweenChainVarianceFoldedPlot =
new TH1D(
"BetweenChainVarianceFoldedPlot",
"BetweenChainVarianceFoldedPlot",
nDraw, 0,
nDraw);
828 MarginalPosteriorVarianceFoldedPlot =
new TH1D(
"MarginalPosteriorVarianceFoldedPlot",
"MarginalPosteriorVarianceFoldedPlot",
nDraw, 0,
nDraw);
829 RhatFoldedPlot =
new TH1D(
"RhatFoldedPlot",
"RhatFoldedPlot", 200, 0, 2);
830 EffectiveSampleSizeFoldedPlot =
new TH1D(
"EffectiveSampleSizeFoldedPlot",
"EffectiveSampleSizeFoldedPlot", 400, 0, 10000);
831 RhatFoldedLogPlot =
new TH1D(
"RhatFoldedLogPlot",
"RhatFoldedLogPlot", 200, 0, 2);
835 int CiteriumFolded = 0;
836 for(
int j = 0; j <
nDraw; j++)
844 RhatPlot->Fill(
RHat[j]);
846 if(
RHat[j] > 1.1) Criterium++;
858 RhatLogPlot->Fill(
RHat[j]);
866 MACH3LOG_WARN(
"Number of parameters which has R hat greater than 1.1 is {}({:.2f}%) while for R hat folded {}({:.2f}%)",
867 Criterium, 100*
double(Criterium)/
double(
nDraw), CiteriumFolded, 100*
double(CiteriumFolded)/
double(
nDraw));
868 for(
int j = 0; j <
nDraw; j++)
879 MACH3LOG_WARN(
"Number of parameters which has R hat greater than 1.1 is {}({:.2f}%)", Criterium, 100*
double(Criterium)/
double(
nDraw));
880 for(
int j = 0; j <
nDraw; j++)
889 StandardDeviationGlobalPlot->Write();
890 BetweenChainVariancePlot->Write();
891 MarginalPosteriorVariancePlot->Write();
893 EffectiveSampleSizePlot->Write();
895 RhatLogPlot->Write();
899 StandardDeviationGlobalFoldedPlot->Write();
900 BetweenChainVarianceFoldedPlot->Write();
901 MarginalPosteriorVarianceFoldedPlot->Write();
902 RhatFoldedPlot->Write();
903 EffectiveSampleSizeFoldedPlot->Write();
905 RhatFoldedLogPlot->Write();
909 auto TempCanvas = std::make_unique<TCanvas>(
"Canvas",
"Canvas", 1024, 1024);
910 gStyle->SetOptStat(0);
911 TempCanvas->SetGridx();
912 TempCanvas->SetGridy();
915 auto TempLine = std::make_unique<TLine>(0, 0, 0, 0);
916 TempLine->SetLineColor(kBlack);
918 RhatPlot->GetXaxis()->SetTitle(
"R hat");
919 RhatPlot->SetLineColor(kRed);
920 RhatPlot->SetFillColor(kRed);
923 RhatFoldedPlot->SetLineColor(kBlue);
924 RhatFoldedPlot->SetFillColor(kBlue);
927 TLegend Legend(0.55, 0.6, 0.9, 0.9);
928 Legend.SetTextSize(0.04);
929 Legend.SetFillColor(0);
930 Legend.SetFillStyle(0);
931 Legend.SetLineWidth(0);
932 Legend.SetLineColor(0);
934 Legend.AddEntry(TempLine.get(), Form(
"Number of throws=%.0i, Number of chains=%.1i",
TotToys,
Nchains),
"");
935 Legend.AddEntry(RhatPlot,
"Rhat Gelman 2013",
"l");
936 if(
HighMemoryMode) Legend.AddEntry(RhatFoldedPlot,
"Rhat-Folded Gelman 2021",
"l");
941 TempCanvas->Write(
"Rhat");
944 RhatLogPlot->GetXaxis()->SetTitle(
"R hat for LogL");
945 RhatLogPlot->SetLineColor(kRed);
946 RhatLogPlot->SetFillColor(kRed);
950 TLegend LegendFolded(0.55, 0.6, 0.9, 0.9);
952 LegendFolded.SetTextSize(0.04);
953 LegendFolded.SetFillColor(0);
954 LegendFolded.SetFillStyle(0);
955 LegendFolded.SetLineWidth(0);
956 LegendFolded.SetLineColor(0);
958 LegendFolded.AddEntry(TempLine.get(), Form(
"Number of throws=%.0i, Number of chains=%.1i",
TotToys,
Nchains),
"");
959 LegendFolded.AddEntry(RhatLogPlot,
"Rhat Gelman 2013",
"l");
960 if(
HighMemoryMode) LegendFolded.AddEntry(RhatFoldedLogPlot,
"Rhat-Folded Gelman 2021",
"l");
963 LegendFolded.Draw(
"same");
964 TempCanvas->Write(
"RhatLog");
967 EffectiveSampleSizePlot->GetXaxis()->SetTitle(
"S_{eff, BDA2}");
968 EffectiveSampleSizePlot->SetLineColor(kRed);
969 if(
HighMemoryMode) EffectiveSampleSizeFoldedPlot->SetLineColor(kBlue);
971 TLegend LegendESS(0.45, 0.6, 0.9, 0.9);
972 LegendESS.SetTextSize(0.03);
973 LegendESS.SetFillColor(0);
974 LegendESS.SetFillStyle(0);
975 LegendESS.SetLineWidth(0);
976 LegendESS.SetLineColor(0);
978 const double Mean1 = EffectiveSampleSizePlot->GetMean();
979 const double RMS1 = EffectiveSampleSizePlot->GetRMS();
981 LegendESS.AddEntry(TempLine.get(), Form(
"Number of throws=%.0i, Number of chains=%.1i",
TotToys,
Nchains),
"");
982 LegendESS.AddEntry(EffectiveSampleSizePlot, Form(
"S_{eff, BDA2} #mu = %.2f, #sigma = %.2f",Mean1 ,RMS1),
"l");
985 const double Mean2 = EffectiveSampleSizeFoldedPlot->GetMean();
986 const double RMS2 = EffectiveSampleSizeFoldedPlot->GetRMS();
987 LegendESS.AddEntry(EffectiveSampleSizeFoldedPlot, Form(
"S_{eff, BDA2} Folded, #mu = %.2f, #sigma = %.2f", Mean2, RMS2),
"l");
989 EffectiveSampleSizePlot->Draw();
990 LegendESS.Draw(
"same");
992 TempCanvas->Write(
"EffectiveSampleSize");
996 delete StandardDeviationGlobalPlot;
997 delete BetweenChainVariancePlot;
998 delete MarginalPosteriorVariancePlot;
1000 delete EffectiveSampleSizePlot;
1006 delete StandardDeviationGlobalFoldedPlot;
1007 delete BetweenChainVarianceFoldedPlot;
1008 delete MarginalPosteriorVarianceFoldedPlot;
1009 delete RhatFoldedPlot;
1010 delete EffectiveSampleSizeFoldedPlot;
1012 delete RhatFoldedLogPlot;
1018 MACH3LOG_INFO(
"Finished and wrote results to {}", NameTemp);
1019 #pragma GCC diagnostic pop
#define MACH3LOG_CRITICAL
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.