12 inline void ProcessMCMC(
const std::string& inputFile);
22 inline TH2D*
TMatrixIntoTH2D(TMatrixDSym* Matrix,
const std::string& title);
25 const std::unique_ptr<TCanvas>& Posterior,
26 const TString& canvasname);
32 int main(
int argc,
char *argv[])
36 if (argc != 3 && argc !=6 && argc != 8)
39 MACH3LOG_ERROR(
" single chain: {} <Config> <MCMM_ND_Output.root>", argv[0]);
40 MACH3LOG_ERROR(
" two chain: {} <Config> <MCMM_ND_Output_1.root> <Title 1> <MCMC_ND_Output_2.root> <Title 2>", argv[0]);
41 MACH3LOG_ERROR(
" three chain: {} <Config> <MCMM_ND_Output_1.root> <Title 1> <MCMC_ND_Output_2.root> <Title 2> <MCMC_ND_Output_3.root> <Title 3>", argv[0]);
48 MACH3LOG_ERROR(
"The 'ProcessMCMC' node is not defined in the YAML configuration.");
55 std::string filename = argv[2];
59 else if (argc == 6 || argc == 8)
93 std::map<std::string, std::pair<double, double>>
GetCustomBinning(
const YAML::Node& Settings)
95 std::map<std::string, std::pair<double, double>> CustomBinning;
96 if (Settings[
"CustomBinEdges"]) {
97 const YAML::Node& edges = Settings[
"CustomBinEdges"];
99 for (
const auto& node : edges) {
100 std::string key = node.first.as<std::string>();
101 auto values = node.second.as<std::vector<double>>();
103 if (values.size() == 2) {
104 CustomBinning[key] = std::make_pair(values[0], values[1]);
105 MACH3LOG_DEBUG(
"Adding custom binning {} with {:.4f}, {:.4f}", key, values[0], values[1]);
112 return CustomBinning;
119 auto Processor = std::make_unique<OscProcessor>(inputFile);
122 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
124 const bool PlotCorr = GetFromManager<bool>(Settings[
"PlotCorr"],
false);
126 Processor->SetExcludedTypes(
GetFromManager<std::vector<std::string>>(Settings[
"ExcludedTypes"], {}));
127 Processor->SetExcludedNames(
GetFromManager<std::vector<std::string>>(Settings[
"ExcludedNames"], {}));
128 Processor->SetExcludedGroups(
GetFromManager<std::vector<std::string>>(Settings[
"ExcludedGroups"], {}));
131 Processor->SetPosterior1DCut(GetFromManager<std::string>(Settings[
"Posterior1DCut"],
""));
133 if(PlotCorr) Processor->SetOutputSuffix(
"_drawCorr");
135 Processor->SetPlotRelativeToPrior(GetFromManager<bool>(Settings[
"PlotRelativeToPrior"],
false));
136 Processor->SetPrintToPDF(GetFromManager<bool>(Settings[
"PrintToPDF"],
true));
139 Processor->SetPlotErrorForFlatPrior(GetFromManager<bool>(Settings[
"PlotErrorForFlatPrior"],
true));
140 Processor->SetFancyNames(GetFromManager<bool>(Settings[
"FancyNames"],
true));
141 Processor->SetPlotBinValue(GetFromManager<bool>(Settings[
"PlotBinValue"],
false));
143 Processor->SetPost2DPlotThreshold(GetFromManager<double>(Settings[
"Post2DPlotThreshold"], 0.2));
145 Processor->Initialise();
147 if(Settings[
"BurnInSteps"]) {
148 Processor->SetStepCut(Settings[
"BurnInSteps"].as<int>());
151 Processor->SetStepCut(
static_cast<int>(Processor->GetnSteps()/5));
153 if(Settings[
"MaxEntries"]) {
154 Processor->SetEntries(Get<int>(Settings[
"MaxEntries"], __FILE__, __LINE__));
156 if(Settings[
"NBins"]) {
157 Processor->SetNBins(Get<int>(Settings[
"NBins"], __FILE__, __LINE__));
159 if(Settings[
"Thinning"])
161 if(Settings[
"Thinning"][0].as<bool>()){
162 Processor->ThinMCMC(Settings[
"Thinning"][1].as<int>());
167 Processor->DrawPostfit();
169 if(GetFromManager<bool>(Settings[
"MakeCredibleIntervals"],
true)) {
170 Processor->MakeCredibleIntervals(
GetFromManager<std::vector<double>>(Settings[
"CredibleIntervals"], {0.99, 0.90, 0.68}),
171 GetFromManager<std::vector<short int>>(Settings[
"CredibleIntervalsColours"], {436, 430, 422}),
172 GetFromManager<bool>(Settings[
"CredibleInSigmas"],
false));
174 if(GetFromManager<bool>(Settings[
"CalcBayesFactor"],
true))
CalcBayesFactor(Processor.get());
175 if(GetFromManager<bool>(Settings[
"CalcSavageDickey"],
true))
CalcSavageDickey(Processor.get());
176 if(GetFromManager<bool>(Settings[
"CalcBipolarPlot"],
false))
CalcBipolarPlot(Processor.get());
177 if(GetFromManager<bool>(Settings[
"CalcParameterEvolution"],
false))
CalcParameterEvolution(Processor.get());
181 Processor->SetSmoothing(GetFromManager<bool>(Settings[
"Smoothing"],
true));
184 Processor->CacheSteps();
186 if(GetFromManager<bool>(Settings[
"MakeViolin"],
true)) Processor->MakeViolin();
187 Processor->MakeCovariance_MP();
189 Processor->DrawCovariance();
190 if(GetFromManager<bool>(Settings[
"MakeCovarianceYAML"],
true)) Processor->MakeCovarianceYAML(GetFromManager<std::string>(Settings[
"CovarianceYAMLOutName"],
"UpdatedCorrelationMatrix.yaml"), GetFromManager<std::string>(Settings[
"CovarianceYAMLMeansMethod"],
"HPD"));
192 auto const &MakeSubOptimality = Settings[
"MakeSubOptimality"];
193 if(MakeSubOptimality[0].as<bool>()) Processor->MakeSubOptimality(MakeSubOptimality[1].as<int>());
195 if(GetFromManager<bool>(Settings[
"MakeCredibleRegions"],
false)) {
196 Processor->MakeCredibleRegions(
GetFromManager<std::vector<double>>(Settings[
"CredibleRegions"], {0.99, 0.90, 0.68}),
197 GetFromManager<std::vector<short int>>(Settings[
"CredibleRegionStyle"], {2, 1, 3}),
198 GetFromManager<std::vector<short int>>(Settings[
"CredibleRegionColor"], {413, 406, 416}),
199 GetFromManager<bool>(Settings[
"CredibleInSigmas"],
false),
200 GetFromManager<bool>(Settings[
"Draw2DPosterior"],
true),
201 GetFromManager<bool>(Settings[
"DrawBestFit"],
true));
203 if(GetFromManager<bool>(Settings[
"GetTrianglePlot"],
true))
GetTrianglePlot(Processor.get());
206 if(GetFromManager<bool>(Settings[
"DiagnoseCovarianceMatrix"],
false))
DiagnoseCovarianceMatrix(Processor.get(), inputFile);
208 Processor->ProduceChi2(GetFromManager<std::string>(Settings[
"Chi2Group"],
"Osc"));
209 if(GetFromManager<bool>(Settings[
"JarlskogAnalysis"],
true)) Processor->PerformJarlskogAnalysis();
210 if(GetFromManager<bool>(Settings[
"ProducePMNSElements"],
true)) Processor->ProducePMNSElements();
211 if(GetFromManager<bool>(Settings[
"ProduceUnitarityTriangles"],
true)) Processor->ProduceUnitarityTriangles();
212 if(GetFromManager<bool>(Settings[
"MakePiePlot"],
true)) Processor->MakePiePlot();
218 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
220 constexpr Color_t PosteriorColor[] = {kBlue-1, kRed, kGreen+2};
223 std::vector<std::unique_ptr<MCMCProcessor>> Processor(
nFiles);
225 if(!Settings[
"BurnInSteps"]) {
229 for (
int ik = 0; ik <
nFiles; ik++)
233 Processor[ik] = std::make_unique<MCMCProcessor>(
FileNames[ik]);
234 Processor[ik]->SetOutputSuffix((
"_" + std::to_string(ik)).c_str());
236 Processor[ik]->SetExcludedTypes(
GetFromManager<std::vector<std::string>>(Settings[
"ExcludedTypes"], {}));
237 Processor[ik]->SetExcludedNames(
GetFromManager<std::vector<std::string>>(Settings[
"ExcludedNames"], {}));
238 Processor[ik]->SetExcludedGroups(
GetFromManager<std::vector<std::string>>(Settings[
"ExcludedGroups"], {}));
241 Processor[ik]->SetPosterior1DCut(GetFromManager<std::string>(Settings[
"Posterior1DCut"],
""));
243 Processor[ik]->SetPlotRelativeToPrior(GetFromManager<bool>(Settings[
"PlotRelativeToPrior"],
false));
244 Processor[ik]->SetFancyNames(GetFromManager<bool>(Settings[
"FancyNames"],
true));
245 Processor[ik]->Initialise();
247 if(Settings[
"BurnInSteps"]) {
248 Processor[ik]->SetStepCut(Settings[
"BurnInSteps"].as<int>());
250 Processor[ik]->SetStepCut(
static_cast<int>(Processor[ik]->GetnSteps()/5));
253 if(Settings[
"MaxEntries"]) {
254 Processor[ik]->SetEntries(Get<int>(Settings[
"MaxEntries"], __FILE__, __LINE__));
256 if(Settings[
"NBins"]) {
257 Processor[ik]->SetNBins(Get<int>(Settings[
"NBins"], __FILE__, __LINE__));
262 Processor[0]->DrawPostfit();
264 std::map<std::string, std::pair<double, double>> ParamEdges;
265 for(
int i = 0; i < Processor[0]->GetNParams(); ++i) {
267 TH1D* hist = Processor[0]->GetHpost(i);
274 std::string paramName = hist->GetTitle();
277 TAxis* axis = hist->GetXaxis();
278 double xmin = axis->GetXmin();
279 double xmax = axis->GetXmax();
281 MACH3LOG_DEBUG(
"Adding bin edges for {} equal to {:.4f}, {:.4f}",paramName, xmin, xmax);
283 ParamEdges[paramName] = std::make_pair(xmin, xmax);
287 for (
int ik = 1; ik <
nFiles; ik++)
290 Processor[ik]->MakePostfit(ParamEdges);
291 Processor[ik]->DrawPostfit();
295 auto Posterior = std::make_unique<TCanvas>(
"PosteriorMulti",
"PosteriorMulti", 0, 0, 1024, 1024);
296 gStyle->SetOptStat(0);
297 gStyle->SetOptTitle(0);
298 Posterior->SetGrid();
299 Posterior->SetBottomMargin(0.1f);
300 Posterior->SetTopMargin(0.05f);
301 Posterior->SetRightMargin(0.03f);
302 Posterior->SetLeftMargin(0.15f);
306 size_t pos =
FileNames[0].rfind(
".root");
307 std::string base = (pos == std::string::npos) ?
FileNames[0] :
FileNames[0].substr(0, pos);
308 TString canvasname = base;
312 for (
int ik = 1; ik <
nFiles; ik++) {
315 pos = base.rfind(
".root");
316 if (pos != std::string::npos) base = base.substr(0, pos);
317 canvasname +=
"_" + TString(base);
320 canvasname = canvasname +
".pdf[";
322 Posterior->Print(canvasname);
324 canvasname.ReplaceAll(
"[",
"");
326 for(
int i = 0; i < Processor[0]->GetNParams(); ++i)
329 std::vector<std::unique_ptr<TH1D>> hpost(
nFiles);
330 std::vector<std::unique_ptr<TLine>> hpd(
nFiles);
331 hpost[0] =
M3::Clone(Processor[0]->GetHpost(i));
332 hpost[0]->GetYaxis()->SetTitle(
"Posterior Density");
334 for (
int ik = 1 ; ik <
nFiles; ik++)
337 const int Index = Processor[ik]->GetParamIndexFromName(hpost[0]->GetTitle());
343 hpost[ik] =
M3::Clone(Processor[ik]->GetHpost(Index));
347 if(hpost[0]->GetMaximum() == hpost[0]->Integral()*1.5 || Skip) {
350 for (
int ik = 0; ik <
nFiles; ik++)
355 hpost[ik]->SetLineColor(PosteriorColor[ik]);
357 hpost[ik]->SetLineWidth(2);
360 hpost[ik]->Scale(1./hpost[ik]->Integral());
364 double PriorError = 1.0;
366 Processor[0]->GetNthParameter(i, Prior, PriorError, Title);
369 auto Asimov = std::make_unique<TLine>(Prior, hpost[0]->GetMinimum(), Prior, hpost[0]->GetMaximum());
370 Asimov->SetLineColor(kRed-3);
371 Asimov->SetLineWidth(2);
372 Asimov->SetLineStyle(kDashed);
375 auto leg = std::make_unique<TLegend>(0.20, 0.7, 0.6, 0.97);
376 leg->SetTextSize(0.03f);
377 leg->SetFillColor(0);
378 leg->SetFillStyle(0);
379 leg->SetLineColor(0);
380 leg->SetLineStyle(0);
381 TString asimovLeg = Form(
"#splitline{Prior}{x = %.2f , #sigma = %.2f}", Prior, PriorError);
382 leg->AddEntry(Asimov.get(), asimovLeg,
"l");
384 for (
int ik = 0; ik <
nFiles; ik++)
386 TString rebinLeg = Form(
"#splitline{%s}{#mu = %.2f, #sigma = %.2f}",
TitleNames[ik].c_str(), hpost[ik]->GetMean(), hpost[ik]->GetRMS());
387 leg->AddEntry(hpost[ik].get(), rebinLeg,
"l");
389 hpd[ik] = std::make_unique<TLine>(hpost[ik]->GetBinCenter(hpost[ik]->GetMaximumBin()), hpost[ik]->GetMinimum(),
390 hpost[ik]->GetBinCenter(hpost[ik]->GetMaximumBin()), hpost[ik]->GetMaximum());
391 hpd[ik]->SetLineColor(hpost[ik]->GetLineColor());
392 hpd[ik]->SetLineWidth(2);
393 hpd[ik]->SetLineStyle(kSolid);
398 for (
int ik = 0; ik <
nFiles; ik++) maximum = std::max(maximum, hpost[ik]->GetMaximum());
399 for (
int ik = 0; ik <
nFiles; ik++) hpost[ik]->SetMaximum(1.3*maximum);
401 hpost[0]->Draw(
"hist");
402 for (
int ik = 1; ik <
nFiles; ik++) hpost[ik]->Draw(
"hist same");
403 Asimov->Draw(
"same");
404 for (
int ik = 0; ik <
nFiles; ik++) hpd[ik]->Draw(
"same");
407 Posterior->Print(canvasname);
415 if(GetFromManager<bool>(Settings[
"PerformKStest"],
true))
KolmogorovSmirnovTest(Processor, Posterior, canvasname);
420 Posterior->Print(canvasname);
427 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
429 std::vector<std::string> ParNames;
430 std::vector<std::vector<double>> Model1Bounds;
431 std::vector<std::vector<double>> Model2Bounds;
432 std::vector<std::vector<std::string>> ModelNames;
433 for (
const auto& dg : Settings[
"BayesFactor"])
435 ParNames.push_back(dg[0].as<std::string>());
436 ModelNames.push_back(dg[1].as<std::vector<std::string>>());
437 Model1Bounds.push_back(dg[2].as<std::vector<double>>());
438 Model2Bounds.push_back(dg[3].as<std::vector<double>>());
441 Processor->
GetBayesFactor(ParNames, Model1Bounds, Model2Bounds, ModelNames);
447 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
449 std::vector<std::string> ParNames;
450 std::vector<double> EvaluationPoint;
451 std::vector<std::vector<double>> Bounds;
453 for (
const auto& d : Settings[
"SavageDickey"])
455 ParNames.push_back(d[0].as<std::string>());
456 EvaluationPoint.push_back(d[1].as<double>());
457 Bounds.push_back(d[2].as<std::vector<double>>());
465 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
467 std::vector<std::string> ParNames;
468 std::vector<int> Intervals;
469 for (
const auto& d : Settings[
"ParameterEvolution"])
471 ParNames.push_back(d[0].as<std::string>());
472 Intervals.push_back(d[1].as<int>());
480 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
482 std::vector<std::string> ParNames;
483 for (
const auto& d : Settings[
"BipolarPlot"])
485 ParNames.push_back(d[0].as<std::string>());
492 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
494 for (
const auto& dg : Settings[
"TrianglePlot"])
496 std::string ParName = dg[0].as<std::string>();
498 std::vector<std::string> NameVec = dg[1].as<std::vector<std::string>>();
500 GetFromManager<std::vector<double>>(Settings[
"CredibleIntervals"], {0.99, 0.90, 0.68}),
501 GetFromManager<std::vector<short int>>(Settings[
"CredibleIntervalsColours"], {436, 430, 422}),
502 GetFromManager<std::vector<double>>(Settings[
"CredibleRegions"], {0.99, 0.90, 0.68}),
503 GetFromManager<std::vector<short int>>(Settings[
"CredibleRegionStyle"], {2, 1, 3}),
504 GetFromManager<std::vector<short int>>(Settings[
"CredibleRegionColor"], {413, 406, 416}),
505 GetFromManager<bool>(Settings[
"CredibleInSigmas"],
false));
515 auto Canvas = std::make_unique<TCanvas>(
"Canvas",
"Canvas", 0, 0, 1024, 1024);
517 gStyle->SetOptStat(0);
518 gStyle->SetOptTitle(0);
521 Canvas->SetBottomMargin(0.1f);
522 Canvas->SetTopMargin(0.05f);
523 Canvas->SetRightMargin(0.15f);
524 Canvas->SetLeftMargin(0.10f);
527 const int NRGBs = 10;
528 TColor::InitializeColors();
529 Double_t stops[NRGBs] = { 0.00, 0.10, 0.25, 0.35, 0.50, 0.60, 0.65, 0.75, 0.90, 1.00 };
530 Double_t red[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00, 0.10, 0.50, 1.00, 0.75, 0.55 };
531 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00, 0.60, 0.90, 1.00, 0.75, 0.75 };
532 Double_t blue[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50, 0.60, 0.90, 1.00, 0.05, 0.05 };
533 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, 255);
534 gStyle->SetNumberContours(255);
536 std::string OutName = inputFile;
537 OutName = OutName.substr(0, OutName.find(
".root"));
538 Canvas->Print(Form(
"Correlation_%s.pdf[", OutName.c_str()),
"pdf");
539 Canvas->Print(Form(
"Covariance_%s.pdf[", OutName.c_str()),
"pdf");
542 YAML::Node Settings = card_yaml[
"ProcessMCMC"];
544 const int entries = int(Processor->
GetnSteps());
545 const int NIntervals = GetFromManager<int>(Settings[
"NIntervals"], 5);
546 const int IntervalsSize = entries/NIntervals;
549 MACH3LOG_INFO(
"Diagnosing matrices with entries={}, NIntervals={} and IntervalsSize={}", entries, NIntervals, IntervalsSize);
551 TMatrixDSym *Covariance =
nullptr;
552 TMatrixDSym *Correlation =
nullptr;
554 TH2D *CovariancePreviousHist =
nullptr;
555 TH2D *CorrelationPreviousHist =
nullptr;
557 TH2D *CovarianceHist =
nullptr;
558 TH2D *CorrelationHist =
nullptr;
568 Covariance =
nullptr;
570 Correlation =
nullptr;
573 for(
int k = 1; k < NIntervals; ++k)
575 BurnIn = k*IntervalsSize;
583 TH2D *CovarianceDiff =
static_cast<TH2D*
>(CovarianceHist->Clone(
"Covariance_Ratio"));
584 TH2D *CorrelationDiff =
static_cast<TH2D*
>(CorrelationHist->Clone(
"Correlation_Ratio"));
588 #pragma omp parallel for
590 for (
int j = 1; j < CovarianceDiff->GetXaxis()->GetNbins()+1; ++j)
592 for (
int i = 1; i < CovarianceDiff->GetYaxis()->GetNbins()+1; ++i)
594 if( std::fabs (CovarianceDiff->GetBinContent(j, i)) < 1.e-5 && std::fabs (CovariancePreviousHist->GetBinContent(j, i)) < 1.e-5)
599 if( std::fabs (CorrelationDiff->GetBinContent(j, i)) < 1.e-5 && std::fabs (CorrelationPreviousHist->GetBinContent(j, i)) < 1.e-5)
607 CovarianceDiff->Divide(CovariancePreviousHist);
608 CorrelationDiff->Divide(CorrelationPreviousHist);
611 for (
int j = 0; j < CovarianceDiff->GetXaxis()->GetNbins(); ++j)
615 double PriorError = 1.0;
619 CovarianceDiff->GetXaxis()->SetBinLabel(j+1, Title);
620 CovarianceDiff->GetYaxis()->SetBinLabel(j+1, Title);
621 CorrelationDiff->GetXaxis()->SetBinLabel(j+1, Title);
622 CorrelationDiff->GetYaxis()->SetBinLabel(j+1, Title);
624 CovarianceDiff->GetXaxis()->SetLabelSize(0.015f);
625 CovarianceDiff->GetYaxis()->SetLabelSize(0.015f);
626 CorrelationDiff->GetXaxis()->SetLabelSize(0.015f);
627 CorrelationDiff->GetYaxis()->SetLabelSize(0.015f);
629 std::stringstream ss;
634 ss << (k-1)*IntervalsSize;
635 std::string str = ss.str();
637 TString Title =
"Cov " + str;
638 CovarianceDiff->GetZaxis()->SetTitle( Title );
639 Title =
"Corr " + str;
640 CorrelationDiff->GetZaxis()->SetTitle(Title);
642 CovarianceDiff->SetMinimum(-2);
643 CovarianceDiff->SetMaximum(2);
644 CorrelationDiff->SetMinimum(-2);
645 CorrelationDiff->SetMaximum(2);
648 CovarianceDiff->Draw(
"colz");
649 Canvas->Print(Form(
"Covariance_%s.pdf", OutName.c_str()),
"pdf");
651 CorrelationDiff->Draw(
"colz");
652 Canvas->Print(Form(
"Correlation_%s.pdf", OutName.c_str()),
"pdf");
655 delete CovariancePreviousHist;
656 CovariancePreviousHist =
static_cast<TH2D*
>(CovarianceHist->Clone());
657 delete CorrelationPreviousHist;
658 CorrelationPreviousHist =
static_cast<TH2D*
>(CorrelationHist->Clone());
660 delete CovarianceHist;
661 CovarianceHist =
nullptr;
662 delete CorrelationHist;
663 CorrelationHist =
nullptr;
665 delete CovarianceDiff;
666 delete CorrelationDiff;
668 Covariance =
nullptr;
670 Correlation =
nullptr;
673 Canvas->Print(Form(
"Covariance_%s.pdf]", OutName.c_str()),
"pdf");
674 Canvas->Print(Form(
"Correlation_%s.pdf]", OutName.c_str()),
"pdf");
677 if(Covariance !=
nullptr)
delete Covariance;
678 if(Correlation !=
nullptr)
delete Correlation;
679 if(CovariancePreviousHist !=
nullptr)
delete CovariancePreviousHist;
680 if(CorrelationPreviousHist !=
nullptr)
delete CorrelationPreviousHist;
681 if(CovarianceHist !=
nullptr)
delete CovarianceHist;
682 if(CorrelationHist !=
nullptr)
delete CorrelationHist;
688 TH2D* hMatrix =
new TH2D(title.c_str(), title.c_str(), Matrix->GetNrows(), 0.0, Matrix->GetNrows(), Matrix->GetNcols(), 0.0, Matrix->GetNcols());
689 for(
int i = 0; i < Matrix->GetNrows(); i++)
691 for(
int j = 0; j < Matrix->GetNcols(); j++)
694 hMatrix->SetBinContent(i+1,j+1, (*Matrix)(i,j));
702 const std::unique_ptr<TCanvas>& Posterior,
703 const TString& canvasname)
705 constexpr Color_t CumulativeColor[] = {kBlue-1, kRed, kGreen+2};
706 constexpr Style_t CumulativeStyle[] = {kSolid, kDashed, kDotted};
708 for(
int i = 0; i < Processor[0]->GetNParams(); ++i)
711 std::vector<std::unique_ptr<TH1D>> hpost(
nFiles);
712 std::vector<std::unique_ptr<TH1D>> CumulativeDistribution(
nFiles);
716 double PriorError = 1.0;
718 Processor[0]->GetNthParameter(i, Prior, PriorError, Title);
720 for (
int ik = 0 ; ik <
nFiles; ik++)
723 if(ik == 0 ) Index = i;
727 Index = Processor[ik]->GetParamIndexFromName(hpost[0]->GetTitle());
734 hpost[ik] =
M3::Clone(Processor[ik]->GetHpost(Index));
735 CumulativeDistribution[ik] =
M3::Clone(Processor[ik]->GetHpost(Index));
736 CumulativeDistribution[ik]->Fill(0., 0.);
737 CumulativeDistribution[ik]->Reset();
738 CumulativeDistribution[ik]->SetMaximum(1.);
739 TString TempTitle = Title+
" Kolmogorov Smirnov";
740 CumulativeDistribution[ik]->SetTitle(TempTitle);
742 TempTitle = Title+
" Value";
743 CumulativeDistribution[ik]->GetXaxis()->SetTitle(TempTitle);
744 CumulativeDistribution[ik]->GetYaxis()->SetTitle(
"Cumulative Probability");
746 CumulativeDistribution[ik]->SetLineWidth(2);
747 CumulativeDistribution[ik]->SetLineColor(CumulativeColor[ik]);
748 CumulativeDistribution[ik]->SetLineStyle(CumulativeStyle[ik]);
752 if(hpost[0]->GetMaximum() == hpost[0]->Integral()*1.5 || Skip) {
756 for (
int ik = 0 ; ik <
nFiles; ik++)
758 const int NumberOfBins = hpost[ik]->GetXaxis()->GetNbins();
759 double Cumulative = 0;
760 const double Integral = hpost[ik]->Integral();
761 for (
int j = 1; j < NumberOfBins+1; ++j)
763 Cumulative += hpost[ik]->GetBinContent(j)/Integral;
764 CumulativeDistribution[ik]->SetBinContent(j, Cumulative);
767 CumulativeDistribution[ik]->SetBinContent(NumberOfBins+1, 1.);
770 std::vector<int> TestStatBin(
nFiles, 0);
771 std::vector<double> TestStatD(
nFiles, -999);
772 std::vector<std::unique_ptr<TLine>> LineD(
nFiles);
774 for (
int ik = 1 ; ik <
nFiles; ik++)
776 const int NumberOfBins = CumulativeDistribution[0]->GetXaxis()->GetNbins();
777 for (
int j = 1; j < NumberOfBins+1; ++j)
779 const double BinValue = CumulativeDistribution[0]->GetBinCenter(j);
780 const int BinNumber = CumulativeDistribution[ik]->FindBin(BinValue);
782 double TempDstat = std::fabs(CumulativeDistribution[0]->GetBinContent(j) - CumulativeDistribution[ik]->GetBinContent(BinNumber));
783 if(TempDstat > TestStatD[ik])
785 TestStatD[ik] = TempDstat;
791 for (
int ik = 0 ; ik <
nFiles; ik++)
793 LineD[ik] = std::make_unique<TLine>(CumulativeDistribution[0]->GetBinCenter(TestStatBin[ik]), 0, CumulativeDistribution[0]->GetBinCenter(TestStatBin[ik]), CumulativeDistribution[0]->GetBinContent(TestStatBin[ik]));
794 LineD[ik]->SetLineColor(CumulativeColor[ik]);
795 LineD[ik]->SetLineWidth(2.0);
797 CumulativeDistribution[0]->Draw();
798 for (
int ik = 0 ; ik <
nFiles; ik++)
799 CumulativeDistribution[ik]->Draw(
"SAME");
801 auto leg = std::make_unique<TLegend>(0.15, 0.7, 0.5, 0.90);
802 leg->SetTextSize(0.04f);
803 for (
int ik = 0; ik <
nFiles; ik++)
804 leg->AddEntry(CumulativeDistribution[ik].get(),
TitleNames[ik].c_str(),
"l");
805 for (
int ik = 1; ik <
nFiles; ik++)
806 leg->AddEntry(LineD[ik].get(), Form(
"#Delta D = %.4f", TestStatD[ik]),
"l");
808 leg->SetLineColor(0);
809 leg->SetLineStyle(0);
810 leg->SetFillColor(0);
811 leg->SetFillStyle(0);
814 for (
int ik = 1; ik <
nFiles; ik++)
815 LineD[ik]->Draw(
"sam");
818 Posterior->Print(canvasname);
void RemoveFitter(TH1D *hist, const std::string &name)
KS: Remove fitted TF1 from hist to make comparison easier.
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
void GetTrianglePlot(MCMCProcessor *Processor)
void DiagnoseCovarianceMatrix(MCMCProcessor *Processor, const std::string &inputFile)
KS: You validate stability of posterior covariance matrix, you set burn calc cov matrix increase burn...
int main(int argc, char *argv[])
TH2D * TMatrixIntoTH2D(TMatrixDSym *Matrix, const std::string &title)
KS: Convert TMatrix to TH2D, mostly useful for making fancy plots.
std::vector< std::string > TitleNames
void CalcBipolarPlot(MCMCProcessor *Processor)
void CalcParameterEvolution(MCMCProcessor *Processor)
void ProcessMCMC(const std::string &inputFile)
Main function processing MCMC and Producing plots.
void MultipleProcessMCMC()
Function producing comparison of posterior and more betwen a few MCMC chains.
std::vector< std::string > FileNames
void KolmogorovSmirnovTest(const std::vector< std::unique_ptr< MCMCProcessor >> &Processor, const std::unique_ptr< TCanvas > &Posterior, const TString &canvasname)
KS: Perform KS test to check if two posteriors for the same parameter came from the same distribution...
void CalcBayesFactor(MCMCProcessor *Processor)
KS: Calculate Bayes factor for a given hypothesis, most informative are those related to osc params....
std::map< std::string, std::pair< double, double > > GetCustomBinning(const YAML::Node &Settings)
Parse custom binning edges from a YAML configuration node.
void CalcSavageDickey(MCMCProcessor *Processor)
Type GetFromManager(const YAML::Node &node, const Type defval, const std::string File="", const int Line=1)
Get content of config file if node is not found take default value specified.
bool CheckNodeExists(const YAML::Node &node, Args... args)
KS: Wrapper function to call the recursive helper.
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Class responsible for processing MCMC chains, performing diagnostics, generating plots,...
void GetNthParameter(const int param, double &Prior, double &PriorError, TString &Title) const
Get properties of parameter by passing it number.
void Reset2DPosteriors()
Reset 2D posteriors, in case we would like to calculate in again with different BurnInCut.
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.
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.
void SetPrintToPDF(const bool PlotOrNot)
Whether to dump all plots into PDF.
Long64_t GetnSteps()
Get Number of Steps that Chain has, for merged chains will not be the same nEntries.
void GetPolarPlot(const std::vector< std::string > &ParNames)
Make funny polar plot.
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.
void SetStepCut(const std::string &Cuts)
Set the step cutting by string.
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.
Custom exception class used throughout MaCh3.
std::unique_ptr< ObjectType > Clone(const ObjectType *obj, const std::string &name="")
KS: Creates a copy of a ROOT-like object and wraps it in a smart pointer.
constexpr static const double _BAD_DOUBLE_
Default value used for double initialisation.
constexpr static const int _BAD_INT_
Default value used for int initialisation.