Skip to content

Commit

Permalink
For some reason ROOT changed treatment of Violin plots in R6. Default…
Browse files Browse the repository at this point in the history
… way of plotting Violin in R6 was UGLYgit status./ProcessMCMC Diag_Config.yaml Chain_1.root After spedning far too much time reading docuemtnaiton and source I can finally reproduce old style of violin. In addition ROOT introduces more options so now not only I can reprodcue old plots but make them FANCIER./ProcessMCMC Diag_Config.yaml Chain_1.root So win-win
  • Loading branch information
KSkwarczynski committed Aug 21, 2024
1 parent 6500310 commit 560a92b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 81 deletions.
32 changes: 18 additions & 14 deletions Diagnostics/GetPostfitParamPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "TTree.h"
#include "TFile.h"
#include "TVectorD.h"
#include "TCandle.h"
#include "TGraphAsymmErrors.h"

#include "manager/manager.h"
Expand Down Expand Up @@ -580,15 +581,15 @@ void GetPostfitParamPlots()

canv = new TCanvas("canv", "canv", 1024, 1024);
//gStyle->SetPalette(51);
gStyle->SetOptStat(0); //Set 0 to disable statystic box
gStyle->SetOptStat(0); //Set 0 to disable statistic box
canv->SetLeftMargin(0.12);
canv->SetBottomMargin(0.12);
canv->SetTopMargin(0.08);
canv->SetRightMargin(0.04);

canv->Print((SaveName+"[").c_str());

// these for non named params where we dont need as much space
// these for non named params where we don't need as much space
p1 = new TPad("p1", "p1", 0.0, 0.3, 1.0, 1.0);
p2 = new TPad("p2", "p2", 0.0, 0.0, 1.0, 0.3);
p1->SetLeftMargin(canv->GetLeftMargin());
Expand Down Expand Up @@ -720,7 +721,10 @@ void GetViolinPlots(std::string FileName1 = "", std::string FileName2 = "")
//KS: Should be in some config... either way it control whether you plot symetric or assymetric error bars
bool PlotAssym = true;

std::cout<<" Making Violin Plot"<<std::endl;
//KS: No idea why but ROOT changed treatment of viilin in R6. If you have non uniform binning this will results in very hard to see violin plots.
TCandle::SetScaledViolin(false);

MACH3LOG_INFO("Making Violin Plot");
if (!FileName1.empty()) std::cout << "File 1 " << FileName1<< std::endl;
if (!FileName2.empty()) std::cout << "File 2 " << FileName2<< std::endl;

Expand Down Expand Up @@ -851,14 +855,14 @@ void GetViolinPlots(std::string FileName1 = "", std::string FileName2 = "")
Violin->GetYaxis()->SetRangeUser(-2., 3.);
if(File2 != NULL) Violin2->GetYaxis()->SetRangeUser(-2., 3.);
}
//KS: ROOT6 has some additional options, consider updaiting it. more https://root.cern/doc/master/classTHistPainter.html#HP140b
ViolinPre->Draw("VIOLIN");
Violin->Draw("VIOLIN SAME");
//KS: ROOT6 has some additional options, consider updating it. more https://root.cern/doc/master/classTHistPainter.html#HP140b
ViolinPre->Draw("violinX(03100300)");
Violin->Draw("violinX(03100300) SAME");
if(File2 != NULL)
{
Violin2->GetXaxis()->SetRangeUser(XsecOffset[i-1], XsecOffset[i]);
Violin2->GetXaxis()->SetRangeUser(XsecOffset[i-1], XsecOffset[i]);
Violin2->Draw("VIOLIN SAME");
Violin2->Draw("violinX(03100300) SAME");
}
if (Postfit != NULL) {
Postfit->GetXaxis()->SetRangeUser(XsecOffset[i-1], XsecOffset[i]);
Expand Down Expand Up @@ -891,13 +895,13 @@ void GetViolinPlots(std::string FileName1 = "", std::string FileName2 = "")
PostGraph->GetYaxis()->SetRangeUser(0.7, 1.3);

//KS: ROOT6 has some additional options, consider updaiting it. more https://root.cern/doc/master/classTHistPainter.html#HP140b
ViolinPre->Draw("VIOLIN");
Violin->Draw("VIOLIN SAME");
ViolinPre->Draw("violinX(03100300)");
Violin->Draw("violinX(03100300) SAME");
if(File2 != NULL)
{
Violin2->GetYaxis()->SetRangeUser(0.7, 1.3);
Violin2->GetXaxis()->SetRangeUser(nFlux, nFlux+FluxInterval);
Violin2->Draw("VIOLIN SAME");
Violin2->Draw("violinX(03100300) SAME");
}
if(PlotAssym) PostGraph->Draw("P SAME");
else Postfit->Draw("SAME");
Expand All @@ -915,14 +919,14 @@ void GetViolinPlots(std::string FileName1 = "", std::string FileName2 = "")
Postfit->GetYaxis()->SetRangeUser(-3.4, 3.4);
PostGraph->GetYaxis()->SetRangeUser(-3.4, 3.4);

//KS: ROOT6 has some additional options, consider updaiting it. more https://root.cern/doc/master/classTHistPainter.html#HP140b
ViolinPre->Draw("VIOLIN");
Violin->Draw("VIOLIN SAME");
//KS: ROOT6 has some additional options, consider updating it. more https://root.cern/doc/master/classTHistPainter.html#HP140b
ViolinPre->Draw("violinX(03100300)");
Violin->Draw("violinX(03100300) SAME");
if(File2 != NULL)
{
Violin2->GetXaxis()->SetRangeUser(CrossSectionParameters, nBins);
Violin2->GetYaxis()->SetRangeUser(-3.4, 3.4);
Violin2->Draw("VIOLIN SAME");
Violin2->Draw("violinX(03100300) SAME");
}
if(PlotAssym) PostGraph->Draw("P SAME");
else Postfit->Draw("SAME");
Expand Down
23 changes: 8 additions & 15 deletions Diagnostics/ProcessMCMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ int main(int argc, char *argv[])

void ProcessMCMC(std::string inputFile)
{
std::cout << "File for study: " << inputFile << " with config "<<config<<std::endl;

// Make the processor
MACH3LOG_INFO("File for study: {} with config {}", inputFile, config);
// Make the processor)
MCMCProcessor* Processor = new MCMCProcessor(inputFile, false);

YAML::Node card_yaml = YAML::LoadFile(config.c_str());
Expand Down Expand Up @@ -307,7 +306,7 @@ void MultipleProcessMCMC()
if(GetFromManager<bool>(Settings["PerformKStest"], true)) KolmogorovSmirnovTest(Processor, Posterior, canvasname);

// Close the pdf file
std::cout << "Closing pdf " << canvasname << std::endl;
MACH3LOG_INFO("Closing pdf {}", canvasname);
canvasname+="]";
Posterior->Print(canvasname);

Expand Down Expand Up @@ -358,7 +357,6 @@ void CalcSavageDickey(MCMCProcessor* Processor)
return;
}


void CalcBipolarPlot(MCMCProcessor* Processor)
{
YAML::Node card_yaml = YAML::LoadFile(config.c_str());
Expand All @@ -374,10 +372,7 @@ void CalcBipolarPlot(MCMCProcessor* Processor)
return;
}


void GetTrianglePlot(MCMCProcessor* Processor){
std::cout<<std::endl;

void GetTrianglePlot(MCMCProcessor* Processor) {
YAML::Node card_yaml = YAML::LoadFile(config.c_str());
YAML::Node Settings = card_yaml["ProcessMCMC"];

Expand Down Expand Up @@ -413,7 +408,7 @@ void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, std::string inputFile)
Canvas->SetRightMargin(0.15);
Canvas->SetLeftMargin(0.10);

//KS: Fancy colots
//KS: Fancy colours
const int NRGBs = 10;
TColor::InitializeColors();
Double_t stops[NRGBs] = { 0.00, 0.10, 0.25, 0.35, 0.50, 0.60, 0.65, 0.75, 0.90, 1.00 };
Expand All @@ -436,7 +431,7 @@ void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, std::string inputFile)
const int IntervalsSize = entries/NIntervals;
//We start with burn from 0 (no burn in at all)
int BurnIn = 0;
std::cout<<"Diagnosing matrices with entries="<< entries<<", NIntervals="<<NIntervals<<" and IntervalsSize="<<IntervalsSize<<std::endl;
MACH3LOG_INFO("Diagnosing matrices with entries={}, NIntervals={} and IntervalsSize={}", entries, NIntervals, IntervalsSize);

TMatrixDSym *Covariance = nullptr;
TMatrixDSym *Correlation = nullptr;
Expand All @@ -459,7 +454,7 @@ void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, std::string inputFile)
delete Correlation;
Correlation = nullptr;

//KS: Loop over alls dsired cuts
//KS: Loop over all desired cuts
for(int k = 1; k < NIntervals; ++k)
{
BurnIn = k*IntervalsSize;
Expand Down Expand Up @@ -575,7 +570,6 @@ void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, std::string inputFile)

void ReweightPrior(MCMCProcessor* Processor)
{
std::cout<<std::endl;

YAML::Node card_yaml = YAML::LoadFile(config.c_str());
YAML::Node Settings = card_yaml["ProcessMCMC"];
Expand All @@ -597,11 +591,10 @@ TH2D* TMatrixIntoTH2D(TMatrixDSym* Matrix, std::string title)
{
for(int j = 0; j < Matrix->GetNcols(); j++)
{
//KS: +1 becasue there is offset in histogram realtive to TMatrix
//KS: +1 because there is offset in histogram relative to TMatrix
hMatrix->SetBinContent(i+1,j+1, (*Matrix)(i,j));
}
}

return hMatrix;
}

Expand Down
Loading

0 comments on commit 560a92b

Please sign in to comment.