776 #pragma GCC diagnostic push
777 #pragma GCC diagnostic ignored "-Wfloat-conversion"
779 std::string NameTemp =
"";
783 for (
int i = 0; i <
Nchains; i++)
787 while (temp.find(
".root") != std::string::npos) {
788 temp = temp.substr(0, temp.find(
".root"));
791 const auto slash = temp.find_last_of(
"/\\");
792 if (slash != std::string::npos) {
793 temp = temp.substr(slash + 1);
796 NameTemp = NameTemp + temp +
"_";
800 NameTemp = std::to_string(
Nchains) +
"Chains" +
"_";
802 NameTemp +=
"diag.root";
804 TFile *DiagFile =
M3::Open(NameTemp,
"recreate", __FILE__, __LINE__);
807 TH1D *StandardDeviationGlobalPlot =
new TH1D(
"StandardDeviationGlobalPlot",
"StandardDeviationGlobalPlot",
nDraw, 0,
nDraw);
808 TH1D *BetweenChainVariancePlot =
new TH1D(
"BetweenChainVariancePlot",
"BetweenChainVariancePlot",
nDraw, 0,
nDraw);
809 TH1D *MarginalPosteriorVariancePlot =
new TH1D(
"MarginalPosteriorVariancePlot",
"MarginalPosteriorVariancePlot",
nDraw, 0,
nDraw);
810 TH1D *RhatPlot =
new TH1D(
"RhatPlot",
"RhatPlot", 200, 0, 2);
811 TH1D *EffectiveSampleSizePlot =
new TH1D(
"EffectiveSampleSizePlot",
"EffectiveSampleSizePlot", 400, 0, 10000);
813 TH1D *RhatLogPlot =
new TH1D(
"RhatLogPlot",
"RhatLogPlot", 200, 0, 2);
815 TH1D *StandardDeviationGlobalFoldedPlot =
nullptr;
816 TH1D *BetweenChainVarianceFoldedPlot =
nullptr;
817 TH1D *MarginalPosteriorVarianceFoldedPlot =
nullptr;
818 TH1D *RhatFoldedPlot =
nullptr;
819 TH1D *EffectiveSampleSizeFoldedPlot =
nullptr;
820 TH1D *RhatFoldedLogPlot =
nullptr;
824 StandardDeviationGlobalFoldedPlot =
new TH1D(
"StandardDeviationGlobalFoldedPlot",
"StandardDeviationGlobalFoldedPlot",
nDraw, 0,
nDraw);
825 BetweenChainVarianceFoldedPlot =
new TH1D(
"BetweenChainVarianceFoldedPlot",
"BetweenChainVarianceFoldedPlot",
nDraw, 0,
nDraw);
826 MarginalPosteriorVarianceFoldedPlot =
new TH1D(
"MarginalPosteriorVarianceFoldedPlot",
"MarginalPosteriorVarianceFoldedPlot",
nDraw, 0,
nDraw);
827 RhatFoldedPlot =
new TH1D(
"RhatFoldedPlot",
"RhatFoldedPlot", 200, 0, 2);
828 EffectiveSampleSizeFoldedPlot =
new TH1D(
"EffectiveSampleSizeFoldedPlot",
"EffectiveSampleSizeFoldedPlot", 400, 0, 10000);
829 RhatFoldedLogPlot =
new TH1D(
"RhatFoldedLogPlot",
"RhatFoldedLogPlot", 200, 0, 2);
833 int CiteriumFolded = 0;
834 for(
int j = 0; j <
nDraw; j++)
842 RhatPlot->Fill(
RHat[j]);
844 if(
RHat[j] > 1.1) Criterium++;
856 RhatLogPlot->Fill(
RHat[j]);
864 MACH3LOG_WARN(
"Number of parameters which has R hat greater than 1.1 is {}({:.2f}%) while for R hat folded {}({:.2f}%)",
865 Criterium, 100*
double(Criterium)/
double(
nDraw), CiteriumFolded, 100*
double(CiteriumFolded)/
double(
nDraw));
866 for(
int j = 0; j <
nDraw; j++)
877 MACH3LOG_WARN(
"Number of parameters which has R hat greater than 1.1 is {}({:.2f}%)", Criterium, 100*
double(Criterium)/
double(
nDraw));
878 for(
int j = 0; j <
nDraw; j++)
887 StandardDeviationGlobalPlot->Write();
888 BetweenChainVariancePlot->Write();
889 MarginalPosteriorVariancePlot->Write();
891 EffectiveSampleSizePlot->Write();
893 RhatLogPlot->Write();
897 StandardDeviationGlobalFoldedPlot->Write();
898 BetweenChainVarianceFoldedPlot->Write();
899 MarginalPosteriorVarianceFoldedPlot->Write();
900 RhatFoldedPlot->Write();
901 EffectiveSampleSizeFoldedPlot->Write();
903 RhatFoldedLogPlot->Write();
907 auto TempCanvas = std::make_unique<TCanvas>(
"Canvas",
"Canvas", 1024, 1024);
908 gStyle->SetOptStat(0);
909 TempCanvas->SetGridx();
910 TempCanvas->SetGridy();
913 auto TempLine = std::make_unique<TLine>(0, 0, 0, 0);
914 TempLine->SetLineColor(kBlack);
916 RhatPlot->GetXaxis()->SetTitle(
"R hat");
917 RhatPlot->SetLineColor(kRed);
918 RhatPlot->SetFillColor(kRed);
921 RhatFoldedPlot->SetLineColor(kBlue);
922 RhatFoldedPlot->SetFillColor(kBlue);
925 TLegend Legend(0.55, 0.6, 0.9, 0.9);
926 Legend.SetTextSize(0.04);
927 Legend.SetFillColor(0);
928 Legend.SetFillStyle(0);
929 Legend.SetLineWidth(0);
930 Legend.SetLineColor(0);
932 Legend.AddEntry(TempLine.get(), Form(
"Number of throws=%.0i, Number of chains=%.1i",
TotToys,
Nchains),
"");
933 Legend.AddEntry(RhatPlot,
"Rhat Gelman 2013",
"l");
934 if(
HighMemoryMode) Legend.AddEntry(RhatFoldedPlot,
"Rhat-Folded Gelman 2021",
"l");
939 TempCanvas->Write(
"Rhat");
942 RhatLogPlot->GetXaxis()->SetTitle(
"R hat for LogL");
943 RhatLogPlot->SetLineColor(kRed);
944 RhatLogPlot->SetFillColor(kRed);
948 TLegend LegendFolded(0.55, 0.6, 0.9, 0.9);
950 LegendFolded.SetTextSize(0.04);
951 LegendFolded.SetFillColor(0);
952 LegendFolded.SetFillStyle(0);
953 LegendFolded.SetLineWidth(0);
954 LegendFolded.SetLineColor(0);
956 LegendFolded.AddEntry(TempLine.get(), Form(
"Number of throws=%.0i, Number of chains=%.1i",
TotToys,
Nchains),
"");
957 LegendFolded.AddEntry(RhatLogPlot,
"Rhat Gelman 2013",
"l");
958 if(
HighMemoryMode) LegendFolded.AddEntry(RhatFoldedLogPlot,
"Rhat-Folded Gelman 2021",
"l");
961 LegendFolded.Draw(
"same");
962 TempCanvas->Write(
"RhatLog");
965 EffectiveSampleSizePlot->GetXaxis()->SetTitle(
"S_{eff, BDA2}");
966 EffectiveSampleSizePlot->SetLineColor(kRed);
967 if(
HighMemoryMode) EffectiveSampleSizeFoldedPlot->SetLineColor(kBlue);
969 TLegend LegendESS(0.45, 0.6, 0.9, 0.9);
970 LegendESS.SetTextSize(0.03);
971 LegendESS.SetFillColor(0);
972 LegendESS.SetFillStyle(0);
973 LegendESS.SetLineWidth(0);
974 LegendESS.SetLineColor(0);
976 const double Mean1 = EffectiveSampleSizePlot->GetMean();
977 const double RMS1 = EffectiveSampleSizePlot->GetRMS();
979 LegendESS.AddEntry(TempLine.get(), Form(
"Number of throws=%.0i, Number of chains=%.1i",
TotToys,
Nchains),
"");
980 LegendESS.AddEntry(EffectiveSampleSizePlot, Form(
"S_{eff, BDA2} #mu = %.2f, #sigma = %.2f",Mean1 ,RMS1),
"l");
983 const double Mean2 = EffectiveSampleSizeFoldedPlot->GetMean();
984 const double RMS2 = EffectiveSampleSizeFoldedPlot->GetRMS();
985 LegendESS.AddEntry(EffectiveSampleSizeFoldedPlot, Form(
"S_{eff, BDA2} Folded, #mu = %.2f, #sigma = %.2f", Mean2, RMS2),
"l");
987 EffectiveSampleSizePlot->Draw();
988 LegendESS.Draw(
"same");
990 TempCanvas->Write(
"EffectiveSampleSize");
994 delete StandardDeviationGlobalPlot;
995 delete BetweenChainVariancePlot;
996 delete MarginalPosteriorVariancePlot;
998 delete EffectiveSampleSizePlot;
1004 delete StandardDeviationGlobalFoldedPlot;
1005 delete BetweenChainVarianceFoldedPlot;
1006 delete MarginalPosteriorVarianceFoldedPlot;
1007 delete RhatFoldedPlot;
1008 delete EffectiveSampleSizeFoldedPlot;
1010 delete RhatFoldedLogPlot;
1016 MACH3LOG_INFO(
"Finished and wrote results to {}", NameTemp);
1017 #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.